diff --git a/pom.xml b/pom.xml
index 9664be1..411c407 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
vavi
vavi-sound-dx7
- 0.0.3
+ 0.0.4
0.02
@@ -23,7 +23,7 @@
org.codehaus.mojo
properties-maven-plugin
- 1.1.0
+ 1.2.1
read-properties
@@ -49,7 +49,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.11.0
+ 3.12.1
17
@@ -62,13 +62,13 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.2.2
+ 3.2.5
--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}
false
@@ -88,7 +88,7 @@
org.junit
junit-bom
- 5.10.2
+ 5.10.3
pom
import
@@ -99,12 +99,12 @@
com.github.umjammer
vavi-commons
- 1.1.10
+ 1.1.14
com.github.umjammer
vavi-sound
- 1.0.16
+ 1.0.19
diff --git a/src/main/java/vavi/sound/dx7/Context.java b/src/main/java/vavi/sound/dx7/Context.java
index f65e4ba..059f24a 100644
--- a/src/main/java/vavi/sound/dx7/Context.java
+++ b/src/main/java/vavi/sound/dx7/Context.java
@@ -18,7 +18,7 @@ public class Context {
public FreqLut freqLut;
public PitchEnv pitchEnv;
- private static Map instances = new HashMap<>();
+ private static final Map instances = new HashMap<>();
public static Context getInstance(float sampleRate) {
if (instances.containsKey(sampleRate)) {
diff --git a/src/main/java/vavi/sound/dx7/Env.java b/src/main/java/vavi/sound/dx7/Env.java
index 2807159..74c4036 100644
--- a/src/main/java/vavi/sound/dx7/Env.java
+++ b/src/main/java/vavi/sound/dx7/Env.java
@@ -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)
diff --git a/src/main/java/vavi/sound/dx7/Exp2.java b/src/main/java/vavi/sound/dx7/Exp2.java
index dae4474..7bbb98c 100644
--- a/src/main/java/vavi/sound/dx7/Exp2.java
+++ b/src/main/java/vavi/sound/dx7/Exp2.java
@@ -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);
@@ -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;
diff --git a/src/main/java/vavi/sound/dx7/FmCore.java b/src/main/java/vavi/sound/dx7/FmCore.java
index bd75e71..d09183b 100644
--- a/src/main/java/vavi/sound/dx7/FmCore.java
+++ b/src/main/java/vavi/sound/dx7/FmCore.java
@@ -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;
}
@@ -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) {
@@ -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)
@@ -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;
diff --git a/src/main/java/vavi/sound/dx7/FreqLut.java b/src/main/java/vavi/sound/dx7/FreqLut.java
index 05bb758..33c1821 100644
--- a/src/main/java/vavi/sound/dx7/FreqLut.java
+++ b/src/main/java/vavi/sound/dx7/FreqLut.java
@@ -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;
diff --git a/src/main/java/vavi/sound/dx7/Note.java b/src/main/java/vavi/sound/dx7/Note.java
index 42f914e..5ed2f8f 100644
--- a/src/main/java/vavi/sound/dx7/Note.java
+++ b/src/main/java/vavi/sound/dx7/Note.java
@@ -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;
@@ -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) {
@@ -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;
@@ -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
@@ -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);
@@ -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,
@@ -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]);
@@ -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;
}
diff --git a/src/main/java/vavi/sound/dx7/Patch.java b/src/main/java/vavi/sound/dx7/Patch.java
index aaa119b..4922de6 100644
--- a/src/main/java/vavi/sound/dx7/Patch.java
+++ b/src/main/java/vavi/sound/dx7/Patch.java
@@ -16,7 +16,10 @@
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;
/**
@@ -24,6 +27,8 @@
*/
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
@@ -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_;
diff --git a/src/main/java/vavi/sound/dx7/PitchEnv.java b/src/main/java/vavi/sound/dx7/PitchEnv.java
index 54583ba..35e64db 100644
--- a/src/main/java/vavi/sound/dx7/PitchEnv.java
+++ b/src/main/java/vavi/sound/dx7/PitchEnv.java
@@ -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;
@@ -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);
diff --git a/src/main/java/vavi/sound/dx7/ResoFilter.java b/src/main/java/vavi/sound/dx7/ResoFilter.java
index 17cc3ab..2b9b7dc 100644
--- a/src/main/java/vavi/sound/dx7/ResoFilter.java
+++ b/src/main/java/vavi/sound/dx7/ResoFilter.java
@@ -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++) {
diff --git a/src/main/java/vavi/sound/dx7/Sawtooth.java b/src/main/java/vavi/sound/dx7/Sawtooth.java
index 2159c4a..e5a1b0f 100644
--- a/src/main/java/vavi/sound/dx7/Sawtooth.java
+++ b/src/main/java/vavi/sound/dx7/Sawtooth.java
@@ -16,15 +16,18 @@
package vavi.sound.dx7;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.Level;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
class Sawtooth {
+ private static final Logger logger = getLogger(Sawtooth.class.getName());
+
@SuppressWarnings("unused")
private static final int R = 1 << 29;
private static final int LG_N_SAMPLES = 10;
@@ -40,11 +43,11 @@ class Sawtooth {
private static final int LOW_FREQ_LIMIT = -SLICE_BASE;
private static final double NEG2OVER_PI = -0.63661977236758138;
- private int[][] sawTooth = new int[N_SLICES][N_SAMPLES];
+ private final int[][] sawTooth = new int[N_SLICES][N_SAMPLES];
private static int sawToothFreqOff;
- private static Map instances = new HashMap<>();
+ private static final Map instances = new HashMap<>();
public static Sawtooth getInstance(double sampleRate) {
if (instances.containsKey(sampleRate)) {
@@ -91,7 +94,7 @@ private void init(double sampleRate) {
}
int ds = (int) Math.floor((1 << dShift) * dsD + 0.5);
int cm2 = (int) Math.floor((1 << dShift) * cm2D + 0.5);
- // Debug.println(cm2D + " " + cm2 + " " + dPhase + " " + ds + " " + dShift);
+ // logger.log(Level.DEBUG, cm2D + " " + cm2 + " " + dPhase + " " + ds + " " + dShift);
int s = 0;
int round = (1 << dShift) >> 1;
for (int i = 0; i < N_SAMPLES / 2; i++) {
@@ -103,7 +106,7 @@ private void init(double sampleRate) {
ds += (int) (((long) cm2 * (long) s + (1 << 28)) >> 29);
s += (ds + round) >> dShift;
}
- Debug.println(Level.FINE, maxErr);
+ logger.log(Level.DEBUG, maxErr);
}
sawTooth[j][0] = 0;
sawTooth[j][N_SAMPLES / 2] = 0;
@@ -124,7 +127,7 @@ public Sawtooth(double sampleRate) {
init(sampleRate);
}
- private int compute(int phase) {
+ private static int compute(int phase) {
return phase * 2 - (1 << 24);
}
diff --git a/src/main/java/vavi/sound/dx7/Sin.java b/src/main/java/vavi/sound/dx7/Sin.java
index 942304d..7043a45 100644
--- a/src/main/java/vavi/sound/dx7/Sin.java
+++ b/src/main/java/vavi/sound/dx7/Sin.java
@@ -22,7 +22,7 @@ class Sin {
private static final int SIN_N_SAMPLES = 1 << SIN_LG_N_SAMPLES;
private static final int R = 1 << 29;
- private static int[] sinTab = new int[SIN_N_SAMPLES << 1];
+ private static final int[] sinTab = new int[SIN_N_SAMPLES << 1];
static {
double dPhase = 2 * Math.PI / SIN_N_SAMPLES;
diff --git a/src/main/java/vavi/sound/dx7/SynthUnit.java b/src/main/java/vavi/sound/dx7/SynthUnit.java
index 4649999..4c5c367 100644
--- a/src/main/java/vavi/sound/dx7/SynthUnit.java
+++ b/src/main/java/vavi/sound/dx7/SynthUnit.java
@@ -16,16 +16,20 @@
package vavi.sound.dx7;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
public class SynthUnit {
+ private static final Logger logger = getLogger(SynthUnit.class.getName());
+
private static final byte[] epiano2 = {
95, 29, 20, 50, 99, 95, 0, 0, 41, 0, 19, 0, 115, 24, 79, 2, 0, 95, 20, 20, 50, 99, 95, 0, 0, 0, 0, 0, 0, 3, 0, 99, 2, 0,
95, 29, 20, 50, 99, 95, 0, 0, 0, 0, 0, 0, 59, 24, 89, 2, 0, 95, 20, 20, 50, 99, 95, 0, 0, 0, 0, 0, 0, 59, 8, 99, 2, 0,
@@ -43,29 +47,29 @@ private static class ActiveNote {
// int channel;
}
- private BlockingDeque deque;
+ private final BlockingDeque deque;
private long timestump;
private static final int MAX_ACTIVE_NOTES = 16;
- private ActiveNote[] activeNote = new ActiveNote[MAX_ACTIVE_NOTES];
+ private final ActiveNote[] activeNote = new ActiveNote[MAX_ACTIVE_NOTES];
private int currentNote;
- private byte[] patchData = new byte[156];
+ private final byte[] patchData = new byte[156];
- private Context context;
+ private final Context context;
// in MIDI units (0x4000 is neutral)
- private Note.Controllers controllers;
+ private final Note.Controllers controllers;
- private ResoFilter filter;
- private int[] filterControl = new int[3];
+ private final ResoFilter filter;
+ private final int[] filterControl = new int[3];
private boolean sustain;
// Extra buffering for when GetSamples wants a buffer not a multiple of N
- private int[] extraBuf = new int[Note.N];
+ private final int[] extraBuf = new int[Note.N];
private int extraBufSize;
- private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
public void close() {
executor.shutdown();
@@ -94,7 +98,7 @@ public SynthUnit(float sampleRate, BlockingDeque deque) {
context = Context.getInstance(sampleRate);
filter = new ResoFilter(context);
- Debug.println("period: " + (int) (1000.0 * Note.N / 44100.0));
+ logger.log(Level.DEBUG, "period: " + (int) (1000.0 * Note.N / 44100.0));
executor.scheduleAtFixedRate(this::process, 1000, (int) (1000.0 * Note.N / 44100.0), TimeUnit.MILLISECONDS);
}
@@ -107,7 +111,7 @@ private int allocateNote() {
}
note = (note + 1) % MAX_ACTIVE_NOTES;
}
-Debug.println("allocateNote: max");
+logger.log(Level.DEBUG, "allocateNote: max");
return -1;
}
@@ -118,11 +122,11 @@ public void programChange(int p, byte[] patch, int ofs) {
byte[] name = new byte[10];
System.arraycopy(patchData, 145, name, 0, 10);
- Debug.println("Loaded patch " + p + ": " + new String(name, 0, 10));
+ logger.log(Level.DEBUG, "Loaded patch " + p + ": " + new String(name, 0, 10));
}
public void noteOff(int noteNumber) {
-//Debug.println("note off: " + noteNumber);
+//logger.log(Level.DEBUG, "note off: " + noteNumber);
for (int note = 0; note < MAX_ACTIVE_NOTES; ++note) {
if (activeNote[note].midiNote == noteNumber && activeNote[note].keyDown) {
if (sustain) {
@@ -140,7 +144,7 @@ public void noteOn(int noteNumber, int velocity) {
noteOff(noteNumber);
return;
}
-//Debug.println("note on: " + noteNumber + ", " + velocity);
+//logger.log(Level.DEBUG, "note on: " + noteNumber + ", " + velocity);
int noteIx = allocateNote();
if (noteIx >= 0) {
context.lfo.keyDown(); // TODO: should only do this if # keys down was 0
@@ -173,12 +177,12 @@ public void controlChange(int controller, int value) {
}
}
controllers.values[controller] = value;
-//Debug.println("control change: " + controller + ", " + value);
+//logger.log(Level.DEBUG, "control change: " + controller + ", " + value);
}
public void pitchBend(int data1, int data2) {
controlChange(Note.kControllerPitch, data1 | (data2 << 7));
-//Debug.println("pitch bend: " + data1 + ", " + data2);
+//logger.log(Level.DEBUG, "pitch bend: " + data1 + ", " + data2);
}
public void sysex(byte[] b) {
@@ -223,7 +227,7 @@ public void getSamples(int nSamples, int[] buffer) {
}
}
extraBufSize = i - nSamples;
-//Debug.println("extra: " + (i - nSamples));
+//logger.log(Level.DEBUG, "extra: " + (i - nSamples));
}
public void process() {
@@ -268,6 +272,6 @@ public void process() {
}
}
extraBufSize = i - nSamples;
-//Debug.println("deque: " + deque.size());
+//logger.log(Level.DEBUG, "deque: " + deque.size());
}
}
diff --git a/src/main/java/vavi/sound/midi/dx7/Dx7.java b/src/main/java/vavi/sound/midi/dx7/Dx7.java
index 5e11682..75fef3f 100644
--- a/src/main/java/vavi/sound/midi/dx7/Dx7.java
+++ b/src/main/java/vavi/sound/midi/dx7/Dx7.java
@@ -6,13 +6,16 @@
package vavi.sound.midi.dx7;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
import vavi.sound.dx7.Context;
import vavi.sound.dx7.Note;
import vavi.sound.dx7.ResoFilter;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -22,6 +25,9 @@
* @version 0.00 2020/11/07 umjammer initial version
*/
class Dx7 {
+
+ private static final Logger logger = getLogger(Dx7.class.getName());
+
static final int BUFFER_SIZE = Note.N;
private static class ActiveNote {
@@ -32,11 +38,11 @@ private static class ActiveNote {
}
// in MIDI units (0x4000 is neutral)
- private Note.Controllers controllers;
+ private final Note.Controllers controllers;
private ResoFilter filter;
- private int[] filterControl = new int[3];
+ private final int[] filterControl = new int[3];
// TODO should be use the value in SoftVoice?
private boolean sustain;
@@ -57,17 +63,17 @@ void setSampleRate(float sampleRate) {
filter = new ResoFilter(context);
}
if (this.context.sampleRate != sampleRate) {
-Debug.println("sampleRate: " + sampleRate);
+logger.log(Level.DEBUG, "sampleRate: " + sampleRate);
this.context.setSampleRate(sampleRate);
}
}
- private static List activeNotes = new ArrayList<>();
+ private static final List activeNotes = new ArrayList<>();
private Dx7.ActiveNote activeNote;
- private int[] audioBuf = new int[BUFFER_SIZE];
- private int[] audioBuf2 = new int[BUFFER_SIZE];
+ private final int[] audioBuf = new int[BUFFER_SIZE];
+ private final int[] audioBuf2 = new int[BUFFER_SIZE];
void write(int offset, int len, int i, float[] buffer, float[] extraBuf) {
int lfoValue = context.lfo.getSample();
@@ -127,7 +133,7 @@ public void programChange(int p, byte[] patch, int ofs) {
System.arraycopy(patch, ofs, b, 0, b.length);
context.lfo.reset(b, 137);
-Debug.println("Loaded patch " + p + ": " + new String(b, 145, 10));
+logger.log(Level.DEBUG, "Loaded patch " + p + ": " + new String(b, 145, 10));
}
public void sysex(byte[] b) {
@@ -138,15 +144,15 @@ public void controlChange(int controller, int value) {
switch (controller) {
case 1:
filterControl[0] = 142365917 + value * 917175;
-Debug.println("control change: " + controller + ", " + value);
+logger.log(Level.DEBUG, "control change: " + controller + ", " + value);
break;
case 2:
filterControl[1] = value * 528416;
-Debug.println("control change: " + controller + ", " + value);
+logger.log(Level.DEBUG, "control change: " + controller + ", " + value);
break;
case 3:
filterControl[2] = value * 528416;
-Debug.println("control change: " + controller + ", " + value);
+logger.log(Level.DEBUG, "control change: " + controller + ", " + value);
break;
case 64:
sustain = value != 0;
@@ -159,7 +165,7 @@ public void controlChange(int controller, int value) {
}
}
}
-Debug.println("control change: " + controller + ", " + value);
+logger.log(Level.DEBUG, "control change: " + controller + ", " + value);
break;
}
controllers.values[controller] = value;
diff --git a/src/main/java/vavi/sound/midi/dx7/Dx7MidiDeviceProvider.java b/src/main/java/vavi/sound/midi/dx7/Dx7MidiDeviceProvider.java
index aabe11d..39e2d6d 100644
--- a/src/main/java/vavi/sound/midi/dx7/Dx7MidiDeviceProvider.java
+++ b/src/main/java/vavi/sound/midi/dx7/Dx7MidiDeviceProvider.java
@@ -6,12 +6,13 @@
package vavi.sound.midi.dx7;
-import java.util.logging.Level;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.spi.MidiDeviceProvider;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -22,7 +23,9 @@
*/
public class Dx7MidiDeviceProvider extends MidiDeviceProvider {
- /** */
+ private static final Logger logger = getLogger(Dx7MidiDeviceProvider.class.getName());
+
+ /** */
public final static int MANUFACTURER_ID = 0x43;
/** */
@@ -38,11 +41,11 @@ public MidiDevice getDevice(MidiDevice.Info info)
throws IllegalArgumentException {
if (info == Dx7Synthesizer.info) {
-Debug.println(Level.FINE, "★1 info: " + info);
+logger.log(Level.DEBUG, "★1 info: " + info);
Dx7Synthesizer synthesizer = new Dx7Synthesizer();
return synthesizer;
} else {
-Debug.println(Level.FINE, "★1 here: " + info);
+logger.log(Level.DEBUG, "★1 here: " + info);
throw new IllegalArgumentException();
}
}
diff --git a/src/main/java/vavi/sound/midi/dx7/Dx7Oscillator.java b/src/main/java/vavi/sound/midi/dx7/Dx7Oscillator.java
index 6f0f553..b7c6c85 100644
--- a/src/main/java/vavi/sound/midi/dx7/Dx7Oscillator.java
+++ b/src/main/java/vavi/sound/midi/dx7/Dx7Oscillator.java
@@ -7,7 +7,8 @@
package vavi.sound.midi.dx7;
import java.io.IOException;
-import java.util.logging.Level;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
@@ -17,10 +18,10 @@
import com.sun.media.sound.ModelAbstractOscillator;
import com.sun.media.sound.SimpleInstrument;
-import vavi.util.Debug;
-
import com.sun.media.sound.ModelPatch;
+import static java.lang.System.getLogger;
+
/**
* Dx7Oscillator.
@@ -31,26 +32,28 @@
@SuppressWarnings("restriction")
public class Dx7Oscillator extends ModelAbstractOscillator {
- private static Dx7Soundbank soundbank;
+ private static final Logger logger = getLogger(Dx7Oscillator.class.getName());
+
+ private static final Dx7Soundbank soundbank;
static {
soundbank = new Dx7Soundbank();
}
/** */
- private Dx7 dx7 = new Dx7();
+ private final Dx7 dx7 = new Dx7();
public Dx7 getDx7() {
return dx7;
}
// Extra buffering for when GetSamples wants a buffer not a multiple of N
- private float[] extraBuf = new float[Dx7.BUFFER_SIZE];
+ private final float[] extraBuf = new float[Dx7.BUFFER_SIZE];
private int extraBufSize;
@Override
public void init() {
-//Debug.println("init");
+//logger.log(Level.DEBUG, "init");
super.init();
}
@@ -77,7 +80,7 @@ public Instrument getInstrument(Patch patch) {
@Override
public void noteOn(MidiChannel channel, VoiceStatus voice, int noteNumber, int velocity) {
if (velocity > 0) {
-//Debug.println("channel: " + voice.channel + ", patch: " + voice.bank + "," + voice.program);
+//logger.log(Level.DEBUG, "channel: " + voice.channel + ", patch: " + voice.bank + "," + voice.program);
try {
// TODO how to define drums
if (voice.channel != 9) {
@@ -87,7 +90,7 @@ public void noteOn(MidiChannel channel, VoiceStatus voice, int noteNumber, int v
dx7.noteOn(drums[noteNumber], noteNumber, velocity);
}
} catch (Throwable t) {
- Debug.println(Level.SEVERE, "ch: " + voice.channel + ", note: " + noteNumber);
+ logger.log(Level.ERROR, "ch: " + voice.channel + ", note: " + noteNumber);
}
super.noteOn(channel, voice, noteNumber, velocity);
} else {
@@ -105,7 +108,7 @@ public void noteOff(int velocity) {
/**
* Dx7.BUFFER_SIZE = 64, len = 300
*
- * @see com.sun.media.sound.SoftVoice#processControlLogic()
+ * @see "com.sun.media.sound.SoftVoice#processControlLogic()"
*/
@Override
public int read(float[][] buffers, int offset, int len) throws IOException {
diff --git a/src/main/java/vavi/sound/midi/dx7/Dx7Soundbank.java b/src/main/java/vavi/sound/midi/dx7/Dx7Soundbank.java
index c92976d..c3ed5f7 100644
--- a/src/main/java/vavi/sound/midi/dx7/Dx7Soundbank.java
+++ b/src/main/java/vavi/sound/midi/dx7/Dx7Soundbank.java
@@ -9,6 +9,8 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -21,7 +23,7 @@
import com.sun.media.sound.ModelPatch;
import com.sun.media.sound.SimpleInstrument;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -33,6 +35,8 @@
@SuppressWarnings("restriction")
public class Dx7Soundbank implements Soundbank {
+ private static final Logger logger = getLogger(Dx7Soundbank.class.getName());
+
/** */
public static class Dx7Instrument extends SimpleInstrument {
Object data;
@@ -63,16 +67,16 @@ public Object getData() {
}
}
- private static byte[][] b;
+ private static final byte[][] b;
/** */
- private static Map instruments = new HashMap<>();
+ private static final Map instruments = new HashMap<>();
static {
try {
DataInputStream dis = new DataInputStream(Dx7Soundbank.class.getResourceAsStream("/unpacked.bin"));
int n = dis.available() / 156;
-Debug.println("patchs: " + n);
+logger.log(Level.DEBUG, "patchs: " + n);
b = new byte[n][156];
for (int i = 0; i < n; i++) {
dis.readFully(b[i]);
@@ -134,11 +138,11 @@ public Instrument[] getInstruments() {
return instruments.values().toArray(new Instrument[0]);
}
- private Map emergencies = new HashMap<>();
+ private final Map emergencies = new HashMap<>();
@Override
public Instrument getInstrument(Patch patch) {
-//Debug.println("patch: " + patch.getBank() + "," + patch.getProgram() + ", " + patch.getClass().getName());
+//logger.log(Level.DEBUG, "patch: " + patch.getBank() + "," + patch.getProgram() + ", " + patch.getClass().getName());
Instrument ins;
boolean isPercussion = patch instanceof ModelPatch && ((ModelPatch) patch).isPercussion();
String k = (isPercussion ? "p." : "") + patch.getBank() + "." + patch.getProgram();
@@ -147,7 +151,7 @@ public Instrument getInstrument(Patch patch) {
} else if (emergencies.containsKey(k)) {
ins = emergencies.get(k);
} else {
-Debug.printf("instrument not found for: %d.%d, %02x, %s", patch.getBank(), patch.getProgram(), (patch.getBank() >> 7), isPercussion);
+logger.log(Level.DEBUG, "instrument not found for: %d.%d, %02x, %s", patch.getBank(), patch.getProgram(), (patch.getBank() >> 7), isPercussion);
Instrument emergency;
if (patch.getBank() >> 7 == 0x7f || patch.getBank() >> 7 == 0x78 || isPercussion) { // TODO check spec.
emergency = instruments.get("p.0.0");
@@ -157,7 +161,7 @@ public Instrument getInstrument(Patch patch) {
emergencies.put(k, emergency);
ins = emergency;
}
-//Debug.println("instrument: " + ins.getPatch().getBank() + ", " + ins.getPatch().getProgram() + ", " + ins.getName());
+//logger.log(Level.DEBUG, "instrument: " + ins.getPatch().getBank() + ", " + ins.getPatch().getProgram() + ", " + ins.getName());
return ins;
}
}
diff --git a/src/main/java/vavi/sound/midi/dx7/Dx7Synthesizer.java b/src/main/java/vavi/sound/midi/dx7/Dx7Synthesizer.java
index e7cfdd9..cab5887 100644
--- a/src/main/java/vavi/sound/midi/dx7/Dx7Synthesizer.java
+++ b/src/main/java/vavi/sound/midi/dx7/Dx7Synthesizer.java
@@ -7,10 +7,11 @@
package vavi.sound.midi.dx7;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import java.util.logging.Level;
import javax.sound.midi.Instrument;
import javax.sound.midi.MetaMessage;
@@ -28,9 +29,10 @@
import javax.sound.midi.VoiceStatus;
import vavi.sound.midi.MidiUtil;
-import vavi.util.Debug;
import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
+
/**
* Dx7Synthesizer.
@@ -45,6 +47,8 @@
*/
public class Dx7Synthesizer implements Synthesizer {
+ private static final Logger logger = getLogger(Dx7Synthesizer.class.getName());
+
static {
try {
try (InputStream is = Dx7Synthesizer.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound-dx7/pom.properties")) {
@@ -83,7 +87,7 @@ public Info getDeviceInfo() {
@Override
public void open() throws MidiUnavailableException {
synthesizer = MidiUtil.getDefaultSynthesizer(Dx7MidiDeviceProvider.class);
-Debug.println("wrapped synthesizer: " + synthesizer.getClass().getName());
+logger.log(Level.DEBUG, "wrapped synthesizer: " + synthesizer.getClass().getName());
synthesizer.open();
synthesizer.unloadAllInstruments(synthesizer.getDefaultSoundbank());
synthesizer.loadAllInstruments(dx7Oscillator = new Dx7Oscillator());
@@ -222,16 +226,16 @@ public void unloadInstruments(Soundbank soundbank, Patch[] patchList) {
}
- private List receivers = new ArrayList<>();
+ private final List receivers = new ArrayList<>();
// TODO move into DX7 class?
private class Dx7Receiver implements Receiver {
- Receiver receiver;
+ final Receiver receiver;
public Dx7Receiver(Receiver receiver) {
receivers.add(this);
this.receiver = receiver;
-Debug.println("receiver: " + this.receiver);
+logger.log(Level.DEBUG, "receiver: " + this.receiver);
}
@Override
@@ -246,9 +250,9 @@ public void send(MidiMessage message, long timeStamp) {
}
} else if (message instanceof SysexMessage sysexMessage) {
byte[] data = sysexMessage.getData();
-//Debug.printf(Level.FINE, "sysex: %02x %02x %02x", data[1], data[2], data[3]);
+//logger.log(Level.DEBUG, "sysex: %02x %02x %02x", data[1], data[2], data[3]);
-Debug.printf(Level.FINE, "sysex: %02X\n%s", sysexMessage.getStatus(), StringUtil.getDump(data));
+logger.log(Level.DEBUG, "sysex: %02X\n%s", sysexMessage.getStatus(), StringUtil.getDump(data));
switch (data[0]) {
case 0x43 -> {
switch (data[1]) {
@@ -256,7 +260,7 @@ public void send(MidiMessage message, long timeStamp) {
switch (data[2]) {
case 0x09: //
if (data[3] == 0x20 && data[4] == 0x00) { //
-Debug.println("sysex: bank change?");
+logger.log(Level.DEBUG, "sysex: bank change?");
}
break;
case 0x00: //
@@ -273,7 +277,7 @@ public void send(MidiMessage message, long timeStamp) {
receiver.send(sysexMessage, timeStamp);
} else if (message instanceof MetaMessage metaMessage) {
-Debug.printf("meta: %02x", metaMessage.getType());
+logger.log(Level.DEBUG, "meta: %02x", metaMessage.getType());
switch (metaMessage.getType()) {
case 0x2f -> {}
}
@@ -282,7 +286,7 @@ public void send(MidiMessage message, long timeStamp) {
assert false;
}
} catch (Throwable t) {
- Debug.printStackTrace(t);
+ logger.log(Level.DEBUG, t);
}
this.receiver.send(message, timeStamp);
}
diff --git a/src/test/java/vavi/sound/dx7/Dx7SynthesizerTest.java b/src/test/java/vavi/sound/dx7/Dx7SynthesizerTest.java
index 713d850..6623c2f 100644
--- a/src/test/java/vavi/sound/dx7/Dx7SynthesizerTest.java
+++ b/src/test/java/vavi/sound/dx7/Dx7SynthesizerTest.java
@@ -66,7 +66,7 @@ static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
- static float volume = Float.parseFloat(System.getProperty("vavi.test.volume.midi", "0.2"));
+ static final float volume = Float.parseFloat(System.getProperty("vavi.test.volume.midi", "0.2"));
@BeforeEach
void setup() throws IOException {
@@ -76,6 +76,7 @@ void setup() throws IOException {
}
@Property(name = "test.midi")
+ final
String midi = "src/test/resources/test.mid";
@Test
@@ -384,7 +385,7 @@ public static void t1(String[] args) throws Exception {
line.close();
}
- static byte[] sample_buf = new byte[128];
+ static final byte[] sample_buf = new byte[128];
static void writeData(SourceDataLine line, int[] buf, int n) {
int delta = 0x100;
diff --git a/src/test/java/vavi/sound/dx7/SawtoothTest.java b/src/test/java/vavi/sound/dx7/SawtoothTest.java
index e97c3e2..1113a65 100644
--- a/src/test/java/vavi/sound/dx7/SawtoothTest.java
+++ b/src/test/java/vavi/sound/dx7/SawtoothTest.java
@@ -6,14 +6,19 @@
package vavi.sound.dx7;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static vavi.sound.SoundUtil.volume;
@@ -24,9 +29,23 @@
* @author Naohide Sano (umjammer)
* @version 0.00 2020/10/31 umjammer initial version
*/
+@PropsEntity(url = "file:local.properties")
class SawtoothTest {
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
+ @Property(name = "vavi.test.volume")
+ final
+ double volume = 0.2;
+
+ @BeforeEach
+ void setup() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
@Test
void test() throws Exception {
@@ -87,7 +106,7 @@ void test() throws Exception {
line.close();
}
- static byte[] sampleBuf = new byte[128];
+ static final byte[] sampleBuf = new byte[128];
static void writeData(SourceDataLine line, int[] buf, int n) {
int delta = 0x100;