Skip to content

Commit

Permalink
Merge pull request #3 from umjammer/0.0.4
Browse files Browse the repository at this point in the history
0.0.4
  • Loading branch information
umjammer authored Dec 2, 2024
2 parents 385584e + 381fcfe commit 15845a7
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 130 deletions.
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-sound-dx7</artifactId>
<version>0.0.3</version>
<version>0.0.4</version>

<properties>
<vavi.test.volume>0.02</vavi.test.volume>
Expand All @@ -23,7 +23,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.1.0</version>
<version>1.2.1</version>
<executions>
<execution>
<id>read-properties</id>
Expand All @@ -49,7 +49,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<source>17</source>
<target>17</target>
Expand All @@ -62,13 +62,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<configuration>
<argLine>
--add-opens java.desktop/com.sun.media.sound=ALL-UNNAMED
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
-Dvavi.test.volume=${vavi.test.volume}
-Dvavi.test.volume.midi=${vavi.test.volume.midi}
-Dvavi.test.volume=@{vavi.test.volume}
-Dvavi.test.volume.midi=@{vavi.test.volume.midi}
</argLine>
<trimStackTrace>false</trimStackTrace>
</configuration>
Expand All @@ -88,7 +88,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -99,12 +99,12 @@
<dependency>
<groupId>com.github.umjammer</groupId>
<artifactId>vavi-commons</artifactId>
<version>1.1.10</version>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>com.github.umjammer</groupId>
<artifactId>vavi-sound</artifactId>
<version>1.0.16</version>
<version>1.0.19</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vavi/sound/dx7/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Context {
public FreqLut freqLut;
public PitchEnv pitchEnv;

private static Map<Float, Context> instances = new HashMap<>();
private static final Map<Float, Context> instances = new HashMap<>();

public static Context getInstance(float sampleRate) {
if (instances.containsKey(sampleRate)) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/vavi/sound/dx7/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

class Env {

private int[] rates = new int[4];
private int[] levels = new int[4];
private int outLevel;
private int rateScaling;
private final int[] rates = new int[4];
private final int[] levels = new int[4];
private final int outLevel;
private final int rateScaling;
// Level is stored so that 2^24 is one doubling, ie 16 more bits than
// the DX7 itself (fraction is stored in level rather than separate
// counter)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vavi/sound/dx7/Exp2.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Exp2 {
private static final int EXP2_LG_N_SAMPLES = 10;
private static final int EXP2_N_SAMPLES = 1 << EXP2_LG_N_SAMPLES;

private static int[] exp2Tab = new int[EXP2_N_SAMPLES << 1];
private static final int[] exp2Tab = new int[EXP2_N_SAMPLES << 1];

static {
double inc = Math.pow(2, 1.0 / EXP2_N_SAMPLES);
Expand Down Expand Up @@ -53,7 +53,7 @@ class Tanh {
private static final int TANH_LG_N_SAMPLES = 10;
private static final int TANH_N_SAMPLES = 1 << TANH_LG_N_SAMPLES;

private static int[] tanhTab = new int[TANH_N_SAMPLES << 1];
private static final int[] tanhTab = new int[TANH_N_SAMPLES << 1];

static {
double step = 4.0 / TANH_N_SAMPLES;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/vavi/sound/dx7/FmCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class FmCore {

public static class FmOpParams {
int[] gain = new int[2];
final int[] gain = new int[2];
int freq;
int phase;
}
Expand All @@ -39,7 +39,7 @@ public static class FmOperatorInfo {
private static final int FB_OUT = 1 << 7;

private static class FmAlgorithm {
int[] ops = new int[6];
final int[] ops = new int[6];
public FmAlgorithm(Integer... args) {
int c = 0;
for (int i : args) {
Expand Down Expand Up @@ -83,7 +83,7 @@ public FmAlgorithm(Integer... args) {
new FmAlgorithm(0xc4, 0x04, 0x04, 0x04, 0x04, 0x04), // 32
};

private int n_out(FmAlgorithm alg) {
private static int n_out(FmAlgorithm alg) {
int count = 0;
for (int i = 0; i < 6; i++) {
if ((alg.ops[i] & 7) == OUT_BUS_ADD)
Expand Down Expand Up @@ -137,14 +137,14 @@ public void compute(int[] output, FmOpParams[] params, int algorithm, int[] fbBu
if (inBus == 0 || !hasContents[inBus]) {
// TODO more than one op in a feedback loop
if ((flags & 0xc0) == 0xc0 && feedbackShift < 16) {
// Debug.println(op + " fb " + inBus + outBus + add);
// logger.log(Level.DEBUG, op + " fb " + inBus + outBus + add);
FmOpKernel.computeFb(outPtr, param.phase, param.freq, gain1, gain2, fbBuf, feedbackShift, add);
} else {
// Debug.println(op + " pure " + inBus + outBus + add);
// logger.log(Level.DEBUG, op + " pure " + inBus + outBus + add);
FmOpKernel.computePure(outPtr, param.phase, param.freq, gain1, gain2, add);
}
} else {
// Debug.println(op + " normal " + inBus + outBus + " " + param.freq + add);
// logger.log(Level.DEBUG, op + " normal " + inBus + outBus + " " + param.freq + add);
FmOpKernel.compute(outPtr, outPtr, param.phase, param.freq, gain1, gain2, add); // TODO 2nd outPtr
}
hasContents[outBus] = true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vavi/sound/dx7/FreqLut.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FreqLut {
private static final int SAMPLE_SHIFT = 24 - LG_N_SAMPLES;
private static final int MAX_LOGFREQ_INT = 20;

private int[] lut = new int[N_SAMPLES + 1];
private final int[] lut = new int[N_SAMPLES + 1];

FreqLut(double sampleRate) {
double y = (1L << (24 + MAX_LOGFREQ_INT)) / sampleRate;
Expand Down
47 changes: 25 additions & 22 deletions src/main/java/vavi/sound/dx7/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@

package vavi.sound.dx7;

import java.util.logging.Level;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;

import vavi.util.Debug;
import static java.lang.System.getLogger;


public class Note {

private static final Logger logger = getLogger(Note.class.getName());

public static final int LG_N = 6;
public static final int N = 1 << LG_N;

private FmCore core = new FmCore();
private Env[] env = new Env[6];
private FmCore.FmOpParams[] params_ = new FmCore.FmOpParams[6];
private Context context;
private int[] basepitch_ = new int[6];
private int[] fb_buf_ = new int[2];
private int fbShift;
private int algorithm;
private int pitchModDepth;
private int pitchModSens;

private int midiNoteToLogFreq(int midiNote) {
private final FmCore core = new FmCore();
private final Env[] env = new Env[6];
private final FmCore.FmOpParams[] params_ = new FmCore.FmOpParams[6];
private final Context context;
private final int[] basepitch_ = new int[6];
private final int[] fb_buf_ = new int[2];
private final int fbShift;
private final int algorithm;
private final int pitchModDepth;
private final int pitchModSens;

private static int midiNoteToLogFreq(int midiNote) {
final int base = 50857777; // (1 << 24) * (log(440) / log(2) - 69/12)
final int step = (1 << 24) / 12;
return base + step * midiNote;
Expand All @@ -49,7 +52,7 @@ private int midiNoteToLogFreq(int midiNote) {
76922906, 77910978, 78860292, 79773775, 80654032, 81503396, 82323963, 83117622
};

private int oscFreq(int midiNote, int mode, int coarse, int fine, int detune) {
private static int oscFreq(int midiNote, int mode, int coarse, int fine, int detune) {
// TODO: pitch randomization
int logFreq;
if (mode == 0) {
Expand Down Expand Up @@ -77,14 +80,14 @@ private int oscFreq(int midiNote, int mode, int coarse, int fine, int detune) {
};

// See "velocity" section of notes. Returns velocity delta in microsteps.
private int scaleVelocity(int velocity, int sensitivity) {
private static int scaleVelocity(int velocity, int sensitivity) {
int clampedVel = Math.max(0, Math.min(127, velocity));
int velValue = velocityData[clampedVel >> 1] - 239;
int scaledVel = ((sensitivity * velValue + 7) >> 3) << 4;
return scaledVel;
}

private int scaleRate(int midiNote, int sensitivity) {
private static int scaleRate(int midiNote, int sensitivity) {
int x = Math.min(31, Math.max(0, midiNote / 3 - 7));
int qrateDelta = (sensitivity * x) >> 3;

Expand All @@ -103,7 +106,7 @@ private int scaleRate(int midiNote, int sensitivity) {
222, 238, 250
};

private int scaleCurve(int group, int depth, int curve) {
private static int scaleCurve(int group, int depth, int curve) {
int scale;
if (curve == 0 || curve == 3) {
// linear
Expand All @@ -120,7 +123,7 @@ private int scaleCurve(int group, int depth, int curve) {
return scale;
}

private int scaleLevel(int midiNote, int breakPt, int leftDepth, int rightDepth, int leftCurve, int rightCurve) {
private static int scaleLevel(int midiNote, int breakPt, int leftDepth, int rightDepth, int leftCurve, int rightCurve) {
int offset = midiNote - breakPt - 17;
if (offset >= 0) {
return scaleCurve(offset / 3, rightDepth, rightCurve);
Expand All @@ -147,7 +150,7 @@ public Note(Context context, byte[] patch, int midiNote, int velocity) {
outLevel = Env.scaleOutLevel(outLevel);

for (int j = 8; j < 12; j++) {
Debug.println(Level.FINE, patch[off + j] + " ");
logger.log(Level.DEBUG, patch[off + j] + " ");
}

int scaleLevel = scaleLevel(midiNote,
Expand All @@ -159,7 +162,7 @@ public Note(Context context, byte[] patch, int midiNote, int velocity) {
outLevel += scaleLevel;
outLevel = Math.min(127, outLevel);

Debug.println(Level.FINE, op + ": " + scaleLevel + " " + outLevel);
logger.log(Level.DEBUG, op + ": " + scaleLevel + " " + outLevel);

outLevel = outLevel << 5;
outLevel += scaleVelocity(velocity, patch[off + 15]);
Expand Down Expand Up @@ -193,7 +196,7 @@ public Note(Context context, byte[] patch, int midiNote, int velocity) {
static final int kControllerPitch = 128;

public static class Controllers {
public int[] values = new int[129];
public final int[] values = new int[129];
public Controllers(int value) {
values[kControllerPitch] = value;
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/vavi/sound/dx7/Patch.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@

package vavi.sound.dx7;

import vavi.util.Debug;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;

import static java.lang.System.getLogger;


/**
* @see "https://github.com/asb2m10/dexed/blob/master/Documentation/sysex-format.txt"
*/
class Patch {

private static final Logger logger = getLogger(Patch.class.getName());

public static void unpackPatch(byte[] bulk, byte[] patch) {
for (int op = 0; op < 6; op++) {
// eg rate and level, brk pt, depth, scaling
Expand Down Expand Up @@ -66,7 +71,7 @@ public static void unpackPatch(byte[] bulk, byte[] patch) {
private static byte clamp(byte byte_, int pos, byte max) {
if (byte_ > max || byte_ < 0) {
clamped++;
Debug.printf("file %d clamped %d pos %d was %d is %d\n", fileClamped, clamped, pos, byte_, max);
logger.log(Level.DEBUG, "file %d clamped %d pos %d was %d is %d\n", fileClamped, clamped, pos, byte_, max);
return max;
}
return byte_;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/vavi/sound/dx7/PitchEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

public class PitchEnv {

private int[] rates = new int[4];
private int[] levels = new int[4];
private final int[] rates = new int[4];
private final int[] levels = new int[4];
private int level;
private int targetLevel;
private boolean rising;
Expand All @@ -29,7 +29,7 @@ public class PitchEnv {

private boolean down;

private int unit;
private final int unit;

PitchEnv(double sampleRate) {
unit = (int) (Note.N * (1 << 24) / (21.3 * sampleRate) + 0.5);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/vavi/sound/dx7/ResoFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
*/
public class ResoFilter {

private int[] x = new int[4];
private int[] w = new int[4];
private final int[] x = new int[4];
private final int[] w = new int[4];
private int yy;

private Context context;
private final Context context;

public ResoFilter(Context context) {
for (int i = 0; i < 4; i++) {
Expand Down
Loading

0 comments on commit 15845a7

Please sign in to comment.