diff --git a/README.md b/README.md
index aee05a6..b55a047 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
# vavi-sound-sandbox
-🌏 play the world ♪
+ play in the sandbox ♪
### Status
@@ -138,6 +138,7 @@ clip.loop(Clip.LOOP_CONTINUOUSLY);
* need to fix: dro(old), midi, etc?
* opl3 volume
* opl3 midi reader
+ * https://github.com/Wohlstand/ADLMIDI-Player-Java
* https://github.com/fedex81/emuSandbox
* https://github.com/toyoshim/tss
* ~~Apple DLS Sound device~~ (done)
@@ -157,6 +158,7 @@ clip.loop(Clip.LOOP_CONTINUOUSLY);
* [thanks](http://asamomiji.jp/contents/mml-player)
* crackling at end https://stackoverflow.com/a/9630897
* https://github.com/trrk/FlMML-for-Android
+ * spi
### ebml
diff --git a/pom.xml b/pom.xml
index e096772..dad0fa9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -104,9 +104,10 @@
21
- --add-modules=jdk.incubator.vector--add-exportsjava.desktop/com.sun.media.sound=ALL-UNNAMED
+ --add-exports
+ java.base/sun.nio.ch=ALL-UNNAMEDtrue
@@ -155,8 +156,9 @@
-Xmx4G
- --add-modules jdk.incubator.vector
- --add-exports java.desktop/com.sun.media.sound=ALL-UNNAMED
+ --add-exports=java.desktop/com.sun.media.sound=ALL-UNNAMED
+ --add-opens=java.base/java.io=ALL-UNNAMED
+ --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
-javaagent:${project.build.directory}/vavi-instrumentation.jar
-Dvavix.lang.instrumentation.VaviInstrumentation.1=vavix.lang.instrumentation.PropertiesClassFileTransformer
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
@@ -255,7 +257,7 @@
com.github.umjammervavi-sound
- 1.0.19
+ 1.0.20com.github.umjammer
@@ -448,9 +450,9 @@
- com.github.umjammer
+ vavivavi-util-screenscraping
- 1.0.14
+ 1.0.15-SNAPSHOTtest
@@ -464,7 +466,7 @@
com.github.umjammer.vavi-commonsvavi-instrumentation
- 1.1.12
+ 1.1.14test
diff --git a/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLCompiler.java b/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLCompiler.java
index 1d0280e..e8c40a8 100644
--- a/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLCompiler.java
+++ b/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLCompiler.java
@@ -4,7 +4,10 @@
package jp.or.rim.kt.kemusiro.sound;
-import vavi.util.Debug;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+
+import static java.lang.System.getLogger;
/**
@@ -15,6 +18,8 @@
*/
public class MMLCompiler {
+ private static final Logger logger = getLogger(MMLCompiler.class.getName());
+
private MusicScore score;
private int tickPerBeat = 240;
private static final int maxAmplitude = 127;
@@ -156,7 +161,7 @@ public void compile(MusicScore newScore, String[] mml) throws MMLException {
public void compile(MusicScore newScore, int channel, String mml) throws MMLException {
StringBuilder buf = new StringBuilder(mml);
-Debug.println("mml: " + mml);
+logger.log(Level.DEBUG, "mml: " + mml);
char c;
score = newScore;
diff --git a/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLPlayer.java b/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLPlayer.java
index 8957384..9dcfc69 100644
--- a/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLPlayer.java
+++ b/src/main/java/jp/or/rim/kt/kemusiro/sound/MMLPlayer.java
@@ -5,9 +5,11 @@
package jp.or.rim.kt.kemusiro.sound;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.sampled.LineListener;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -20,6 +22,8 @@
*/
public class MMLPlayer implements Runnable {
+ private static final Logger logger = getLogger(MMLPlayer.class.getName());
+
private static final int samplingRate = 22100;
private static final int bitDepth = 8;
@@ -91,7 +95,7 @@ public void run() {
try {
play(mmls);
} catch (Exception e) {
- Debug.println(e);
+ logger.log(Level.INFO, e.getMessage(), e);
}
}
diff --git a/src/main/java/jp/or/rim/kt/kemusiro/sound/SoundPlayer.java b/src/main/java/jp/or/rim/kt/kemusiro/sound/SoundPlayer.java
index 069e19f..c403815 100644
--- a/src/main/java/jp/or/rim/kt/kemusiro/sound/SoundPlayer.java
+++ b/src/main/java/jp/or/rim/kt/kemusiro/sound/SoundPlayer.java
@@ -4,11 +4,14 @@
package jp.or.rim.kt.kemusiro.sound;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.DataLine;
import vavi.sound.SoundUtil;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -19,6 +22,8 @@
*/
public abstract class SoundPlayer {
+ private static final Logger logger = getLogger(SoundPlayer.class.getName());
+
protected AudioFormat format;
/**
@@ -76,7 +81,7 @@ public void close() {
/** Changes volume */
public void volume(float gain) {
-Debug.println("volume: " + gain + ", " + getClass()); // works, but not so different
+logger.log(Level.DEBUG, "volume: " + gain + ", " + getClass()); // works, but not so different
SoundUtil.volume(getLine(), gain);
}
}
diff --git a/src/main/java/vavi/apps/packetcast/PacketCaster.java b/src/main/java/vavi/apps/packetcast/PacketCaster.java
index 6ba7f63..7e1e3b6 100644
--- a/src/main/java/vavi/apps/packetcast/PacketCaster.java
+++ b/src/main/java/vavi/apps/packetcast/PacketCaster.java
@@ -10,8 +10,9 @@
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Calendar;
-
import javax.media.Controller;
import javax.media.ControllerErrorEvent;
import javax.media.ControllerListener;
@@ -28,7 +29,7 @@
import javax.media.protocol.FileTypeDescriptor;
import javax.swing.Timer;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -39,6 +40,8 @@
*/
public class PacketCaster {
+ private static final Logger logger = getLogger(PacketCaster.class.getName());
+
/**
* Main program
*/
@@ -68,10 +71,10 @@ public void actionPerformed(ActionEvent event) {
try {
// Transcode with the specified parameters.
long start = playingTime * 1000 * 1000;
-Debug.println("start: " + start);
+logger.log(Level.DEBUG, "start: " + start);
playingTime += interval;
long end = playingTime * 1000 * 1000;
-Debug.println("end: " + end);
+logger.log(Level.DEBUG, "end: " + end);
String outputURL = urlMaker.getUrl();
MediaLocator oml = new MediaLocator(outputURL);
doIt(iml, oml, new long[] { start }, new long[] { end });
diff --git a/src/main/java/vavi/sound/ilbc/Ilbc.java b/src/main/java/vavi/sound/ilbc/Ilbc.java
index 8d9ed09..dd2b289 100644
--- a/src/main/java/vavi/sound/ilbc/Ilbc.java
+++ b/src/main/java/vavi/sound/ilbc/Ilbc.java
@@ -16,9 +16,6 @@
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
-import vavi.util.Debug;
-import vavi.util.StringUtil;
-
/**
* iLBC Speech Coder ANSI-C Source Code
@@ -809,7 +806,7 @@ static int encode(Encoder encoder, byte[] encoded_data, byte[] data) {
// do the actual encoding
iLBC_encode(encoded_data, block, encoder);
-//Debug.println("\n" + StringUtil.getDump(encoded_data, 64));
+//logger.log(Level.TRACE, "\n" + StringUtil.getDump(encoded_data, 64));
return encoder.no_of_bytes;
}
@@ -868,7 +865,7 @@ public static void main(String[] argv) throws Exception {
// Runtime statistics
long runtime;
- double outtime;
+ double outTime;
InputStream iFile, cFile;
OutputStream oFile, eFile;
@@ -950,7 +947,7 @@ public static void main(String[] argv) throws Exception {
// Runtime statistics
- long starttime = System.currentTimeMillis();
+ long startTime = System.currentTimeMillis();
// loop over input blocks
@@ -1003,13 +1000,13 @@ public static void main(String[] argv) throws Exception {
// Runtime statistics
- runtime = System.currentTimeMillis() - starttime;
- outtime = ((double) blockCount * (double) mode / 1000.0);
- System.out.printf("\n\nLength of speech file: %.1f s\n", outtime);
+ runtime = System.currentTimeMillis() - startTime;
+ outTime = ((double) blockCount * (double) mode / 1000.0);
+ System.out.printf("\n\nLength of speech file: %.1f s\n", outTime);
System.out.printf("Packet loss : %.1f%%\n", 100.0 * packetLossCount / blockCount);
System.out.print("Time to run iLBC :");
- System.out.printf(" %.1f s (%.1f %% of realtime)\n\n", (double) runtime, (100 * runtime / outtime));
+ System.out.printf(" %.1f s (%.1f %% of realtime)\n\n", (double) runtime, (100 * runtime / outTime));
// close files
diff --git a/src/main/java/vavi/sound/mfi/ittake/IttakeMidiConverter.java b/src/main/java/vavi/sound/mfi/ittake/IttakeMidiConverter.java
index 2d702f4..eb4eb12 100644
--- a/src/main/java/vavi/sound/mfi/ittake/IttakeMidiConverter.java
+++ b/src/main/java/vavi/sound/mfi/ittake/IttakeMidiConverter.java
@@ -5,6 +5,8 @@
package vavi.sound.mfi.ittake;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.List;
import javax.sound.midi.InvalidMidiDataException;
@@ -32,6 +34,8 @@
import vavi.sound.mfi.vavi.track.VolumeMessage;
import vavi.util.Debug;
+import static java.lang.System.getLogger;
+
/**
* IttakeMidiConverter.
@@ -44,6 +48,8 @@
*/
public class IttakeMidiConverter implements MidiConverter {
+ private static final Logger logger = getLogger(IttakeMidiConverter.class.getName());
+
/** the device information */
private static final MfiDevice.Info info =
new MfiDevice.Info("MIDItoMLD",
@@ -91,7 +97,7 @@ public vavi.sound.mfi.Sequence toMfiSequence(Sequence midiSequence, int fileType
try {
return convert(midiSequence, fileType);
} catch (IOException | InvalidMfiDataException e) {
-Debug.printStackTrace(e);
+logger.log(Level.DEBUG, e.getMessage(), e);
throw (InvalidMidiDataException) new InvalidMidiDataException().initCause(e);
}
}
@@ -115,10 +121,10 @@ protected static vavi.sound.mfi.Sequence convert(Sequence sequence, int type)
throws InvalidMfiDataException, IOException {
javax.sound.midi.Track[] midiTracks = sequence.getTracks();
-Debug.println("divisionType: " + sequence.getDivisionType());
-Debug.println("microsecondLength: " + sequence.getMicrosecondLength());
-Debug.println("resolution: " + sequence.getResolution());
-Debug.println("tickLength: " + sequence.getTickLength());
+logger.log(Level.DEBUG, "divisionType: " + sequence.getDivisionType());
+logger.log(Level.DEBUG, "microsecondLength: " + sequence.getMicrosecondLength());
+logger.log(Level.DEBUG, "resolution: " + sequence.getResolution());
+logger.log(Level.DEBUG, "tickLength: " + sequence.getTickLength());
//
vavi.sound.mfi.Sequence mfiSequence = new vavi.sound.mfi.Sequence();
@@ -132,7 +138,7 @@ protected static vavi.sound.mfi.Sequence convert(Sequence sequence, int type)
context.setMfiResolution(6L << sequence.getResolution());
int headerIndex = mfiTrack.size(); // TODO
-Debug.println("headerIndex: " + headerIndex);
+logger.log(Level.DEBUG, "headerIndex: " + headerIndex);
CuePointMessage biginning = new CuePointMessage(0, 0);
mfiTrack.add(new MfiEvent(biginning, 0L));
int volume = 0;
@@ -156,7 +162,7 @@ protected static vavi.sound.mfi.Sequence convert(Sequence sequence, int type)
int t = 0;
int j = 0;
do {
-Debug.println("j: " + j);
+logger.log(Level.DEBUG, "j: " + j);
MidiEvent midiEvent = midiTracks[t].get(j);
MidiMessage midiMessage = midiEvent.getMessage();
presentTime = midiEvent.getTick();
@@ -176,7 +182,7 @@ protected static vavi.sound.mfi.Sequence convert(Sequence sequence, int type)
}
}
}
-Debug.println("here: " + j + ", " + timeOver);
+logger.log(Level.DEBUG, "here: " + j + ", " + timeOver);
} while (timeOver);
if (midiMessage instanceof ShortMessage shortMessage) {
diff --git a/src/main/java/vavi/sound/midi/jsyn/JSynMidiDeviceProvider.java b/src/main/java/vavi/sound/midi/jsyn/JSynMidiDeviceProvider.java
index 8a04c50..a09fa62 100644
--- a/src/main/java/vavi/sound/midi/jsyn/JSynMidiDeviceProvider.java
+++ b/src/main/java/vavi/sound/midi/jsyn/JSynMidiDeviceProvider.java
@@ -6,12 +6,13 @@
package vavi.sound.midi.jsyn;
-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 JSynMidiDeviceProvider extends MidiDeviceProvider {
- /** */
+ private static final Logger logger = getLogger(JSynMidiDeviceProvider.class.getName());
+
+ /** */
public final static int MANUFACTURER_ID = 0x5e;
/** */
@@ -39,11 +42,11 @@ public MidiDevice getDevice(MidiDevice.Info info)
throws IllegalArgumentException {
if (info == JSynSynthesizer.info) {
-Debug.println(Level.FINE, "★1 info: " + info);
+logger.log(Level.DEBUG, "★1 info: " + info);
JSynSynthesizer synthesizer = new JSynSynthesizer();
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/jsyn/JSynOscillator.java b/src/main/java/vavi/sound/midi/jsyn/JSynOscillator.java
index 8222720..6dc3801 100644
--- a/src/main/java/vavi/sound/midi/jsyn/JSynOscillator.java
+++ b/src/main/java/vavi/sound/midi/jsyn/JSynOscillator.java
@@ -7,6 +7,8 @@
package vavi.sound.midi.jsyn;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.midi.Instrument;
import javax.sound.midi.MidiChannel;
@@ -23,7 +25,7 @@
import com.sun.media.sound.ModelPatch;
import com.sun.media.sound.SimpleInstrument;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -35,6 +37,8 @@
@SuppressWarnings("restriction")
public class JSynOscillator extends ModelAbstractOscillator {
+ private static final Logger logger = getLogger(JSynOscillator.class.getName());
+
/** */
public class JSynInstrument extends SimpleInstrument {
final UnitVoice data;
@@ -104,7 +108,7 @@ public void init() {
@Override
public void setSampleRate(float sampleRate) {
if (JSynOscillator.sampleRate != sampleRate) {
-Debug.println("sampleRate: " + sampleRate);
+logger.log(Level.DEBUG, "sampleRate: " + sampleRate);
JSynOscillator.sampleRate = sampleRate;
}
super.setSampleRate(sampleRate);
@@ -120,7 +124,7 @@ public Instrument[] getInstruments() {
@Override
public Instrument getInstrument(Patch patch) {
-//Debug.println("patch: " + patch.getBank() + "," + patch.getProgram());
+//logger.log(Level.TRACE, "patch: " + patch.getBank() + "," + patch.getProgram());
for (Instrument ins : instruments) {
Patch p = ins.getPatch();
if (p.getBank() != patch.getBank())
@@ -133,10 +137,10 @@ public Instrument getInstrument(Patch patch) {
continue;
}
}
-//Debug.println("instrument: " + ins);
+//logger.log(Level.TRACE, "instrument: " + ins);
return ins;
}
-Debug.println("instrument not found for: " + patch.getBank() + "," + patch.getProgram());
+logger.log(Level.DEBUG, "instrument not found for: " + patch.getBank() + "," + patch.getProgram());
return instruments[0];
}
@@ -188,7 +192,7 @@ public int read(float[][] buffers, int offset, int len) throws IOException {
lineOut.generate(offset, offset + len);
double[] values = lineOut.getSynthesisEngine().getInputBuffer(0);
-Debug.println("@@@: " + values.length + ", " + len);
+logger.log(Level.DEBUG, "@@@: " + values.length + ", " + len);
for (; i < offset + len; i += BUFFER_SIZE) {
buffer[offset + i] = (float) values[i];
}
diff --git a/src/main/java/vavi/sound/midi/jsyn/JSynSynthesizer.java b/src/main/java/vavi/sound/midi/jsyn/JSynSynthesizer.java
index 1d3e84e..9c47de8 100644
--- a/src/main/java/vavi/sound/midi/jsyn/JSynSynthesizer.java
+++ b/src/main/java/vavi/sound/midi/jsyn/JSynSynthesizer.java
@@ -7,10 +7,11 @@
package vavi.sound.midi.jsyn;
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.MidiChannel;
import javax.sound.midi.MidiDevice;
@@ -30,9 +31,10 @@
import com.jsyn.unitgen.LineOut;
import com.jsyn.util.MultiChannelSynthesizer;
import com.jsyn.util.VoiceDescription;
-import vavi.util.Debug;
import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
+
/**
* JSynSynthesizer.
@@ -44,6 +46,8 @@
*/
public class JSynSynthesizer implements Synthesizer {
+ private static final Logger logger = getLogger(JSynSynthesizer.class.getName());
+
static {
try {
try (InputStream is = JSynSynthesizer.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound-sandbox/pom.properties")) {
@@ -94,7 +98,7 @@ public Info getDeviceInfo() {
@Override
public void open() throws MidiUnavailableException {
if (isOpen()) {
-Debug.println(Level.WARNING, "already open: " + hashCode());
+logger.log(Level.WARNING, "already open: " + hashCode());
return;
}
@@ -470,11 +474,11 @@ public void send(MidiMessage message, long timeStamp) {
channels[channel].setPitchBend(data1 | (data2 << 7));
break;
default:
-Debug.printf(Level.FINE, "%02X\n", command);
+logger.log(Level.DEBUG, "%02X".formatted(command));
}
} else if (message instanceof SysexMessage sysexMessage) {
byte[] data = sysexMessage.getData();
-Debug.printf(Level.FINE, "sysex: %02X\n%s", sysexMessage.getStatus(), StringUtil.getDump(data));
+logger.log(Level.DEBUG, "sysex: %02X\n%s".formatted(sysexMessage.getStatus(), StringUtil.getDump(data)));
switch (data[0]) {
case 0x7f: // Universal Realtime
@SuppressWarnings("unused")
@@ -482,7 +486,7 @@ public void send(MidiMessage message, long timeStamp) {
// Sub-ID, Sub-ID2
if (data[2] == 0x04 && data[3] == 0x01) { // Device Control / Master Volume
float gain = ((data[4] & 0x7f) | ((data[5] & 0x7f) << 7)) / 16383f;
-Debug.printf(Level.FINE, "sysex volume: gain: %4.0f%n", gain * 100);
+logger.log(Level.DEBUG, "sysex volume: gain: %4.0f%n".formatted(gain * 100));
multiSynth.setMasterAmplitude(gain * 100);
break;
}
@@ -492,7 +496,7 @@ public void send(MidiMessage message, long timeStamp) {
}
} else {
// TODO meta message
-Debug.printf(Level.FINE, message.getClass().getName());
+logger.log(Level.DEBUG, message.getClass().getName());
}
} else {
throw new IllegalStateException("receiver is not open");
diff --git a/src/main/java/vavi/sound/midi/opl3/Opl3MidiDeviceProvider.java b/src/main/java/vavi/sound/midi/opl3/Opl3MidiDeviceProvider.java
index 643d48d..ea5c928 100644
--- a/src/main/java/vavi/sound/midi/opl3/Opl3MidiDeviceProvider.java
+++ b/src/main/java/vavi/sound/midi/opl3/Opl3MidiDeviceProvider.java
@@ -6,12 +6,13 @@
package vavi.sound.midi.opl3;
-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 Opl3MidiDeviceProvider extends MidiDeviceProvider {
- /** */
+ private static final Logger logger = getLogger(Opl3MidiDeviceProvider.class.getName());
+
+ /** */
public final static int MANUFACTURER_ID = 0x43;
/** */
@@ -39,11 +42,11 @@ public MidiDevice getDevice(MidiDevice.Info info)
throws IllegalArgumentException {
if (info == Opl3Synthesizer.info) {
-Debug.println(Level.FINE, "★1 info: " + info);
+logger.log(Level.DEBUG, "★1 info: " + info);
Opl3Synthesizer synthesizer = new Opl3Synthesizer();
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/opl3/Opl3Soundbank.java b/src/main/java/vavi/sound/midi/opl3/Opl3Soundbank.java
index af6e4c9..a483ce5 100644
--- a/src/main/java/vavi/sound/midi/opl3/Opl3Soundbank.java
+++ b/src/main/java/vavi/sound/midi/opl3/Opl3Soundbank.java
@@ -6,6 +6,7 @@
package vavi.sound.midi.opl3;
+import java.util.Arrays;
import javax.sound.midi.Instrument;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
@@ -93,5 +94,10 @@ protected Opl3Instrument(Opl3Soundbank sounBbank, int bank, int program, String
public Object getData() {
return data;
}
+
+ @Override
+ public String toString() {
+ return Opl3Soundbank.class.getSimpleName() + "@%x".formatted(Arrays.stream(data).sum());
+ }
}
}
diff --git a/src/main/java/vavi/sound/midi/opl3/Opl3Synthesizer.java b/src/main/java/vavi/sound/midi/opl3/Opl3Synthesizer.java
index 9c09cbf..cb31ba4 100644
--- a/src/main/java/vavi/sound/midi/opl3/Opl3Synthesizer.java
+++ b/src/main/java/vavi/sound/midi/opl3/Opl3Synthesizer.java
@@ -7,14 +7,14 @@
package vavi.sound.midi.opl3;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.sound.midi.Instrument;
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiChannel;
@@ -40,9 +40,10 @@
import vavi.sound.opl3.MidPlayer;
import vavi.sound.opl3.MidPlayer.FileType;
import vavi.sound.opl3.Opl3Player;
-import vavi.util.Debug;
import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
+
/**
* Opl3Synthesizer.
@@ -61,6 +62,8 @@
*/
public class Opl3Synthesizer implements Synthesizer {
+ private static final Logger logger = getLogger(Opl3Synthesizer.class.getName());
+
static {
try {
try (InputStream is = Opl3Synthesizer.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound-sandbox/pom.properties")) {
@@ -77,8 +80,6 @@ public class Opl3Synthesizer implements Synthesizer {
}
}
- private static final Logger logger = Logger.getLogger(Opl3Synthesizer.class.getName());
-
private static final String version;
/** the device information */
@@ -141,7 +142,7 @@ public Info getDeviceInfo() {
public void open(FileType type, Adlib.Writer writer) throws MidiUnavailableException {
if (isOpen()) {
-Debug.println(Level.WARNING, "already open: " + hashCode());
+logger.log(Level.WARNING, "already open: " + hashCode());
return;
}
@@ -182,7 +183,7 @@ public void open(FileType type, Adlib.Writer writer) throws MidiUnavailableExcep
percussions[i] = new Percussion();
}
-Debug.println("type: " + type);
+logger.log(Level.DEBUG, "type: " + type);
this.type = type;
type.midiTypeFile.init(new Context());
@@ -208,8 +209,8 @@ private void init() throws MidiUnavailableException {
try {
DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, audioFormat, AudioSystem.NOT_SPECIFIED);
line = (SourceDataLine) AudioSystem.getLine(lineInfo);
-Debug.println(line.getClass().getName());
- line.addLineListener(event -> Debug.println("Line: " + event.getType()));
+logger.log(Level.DEBUG, line.getClass().getName());
+ line.addLineListener(event -> logger.log(Level.DEBUG, "Line: " + event.getType()));
line.open(audioFormat);
line.start();
@@ -223,7 +224,7 @@ private void init() throws MidiUnavailableException {
/** */
private void play() {
byte[] buf = new byte[4 * (int) audioFormat.getSampleRate() / 10];
-//Debug.printf("buf: %d", buf.length);
+//logger.log(Level.TRACE, "buf: %d".formatted(buf.length));
while (isOpen) {
try {
@@ -231,13 +232,13 @@ private void play() {
timestamp = System.currentTimeMillis();
msec = msec > 100 ? 100 : msec;
int l = adlib.read(buf, 0, 4 * (int) (audioFormat.getSampleRate() * msec / 1000.0));
-//Debug.printf("adlib: %d", l);
+//logger.log(Level.TRACE, "adlib: %d".formatted(l));
if (l > 0) {
line.write(buf, 0, l);
}
Thread.sleep(33); // TODO how to define?
} catch (Exception e) {
- e.printStackTrace();
+ logger.log(Level.INFO, e.getMessage(), e);
}
}
}
@@ -487,9 +488,9 @@ public void noteOn(int noteNumber, int velocity) {
percussions[voice].volume = 0;
}
}
-logger.finest(String.format("note on[%d]: (%d %d) %d", channel, inum, noteNumber, velocity));
+logger.log(Level.TRACE, "note on[%d]: (%d %d) %d".formatted(channel, inum, noteNumber, velocity));
} else {
-logger.finer("note is off");
+logger.log(Level.TRACE, "note is off");
}
//
voiceStatus[channel].note = noteNumber;
@@ -539,10 +540,10 @@ public void controlChange(int controller, int value) {
switch (controller) {
case 0x07 -> { // channel volume
voiceStatus[channel].volume = value;
-logger.fine(String.format("control change[%d]: vol(%02x): %d", channel, controller, value));
+logger.log(Level.DEBUG, "control change[%d]: vol(%02x): %d".formatted(channel, controller, value));
}
default ->
-logger.fine(String.format("control change unhandled[%d]: (%02x): %d", channel, controller, value));
+logger.log(Level.DEBUG, "control change unhandled[%d]: (%02x): %d".formatted(channel, controller, value));
}
type.midiTypeFile.controlChange(channel, controller, value);
@@ -559,8 +560,9 @@ public int getController(int controller) {
@Override
public void programChange(int program) {
inum = program & 0x7f;
+logger.log(Level.DEBUG, "instruments[" + inum + "]: " + instruments[inum]);
setIns(instruments[inum]);
-logger.fine(String.format("program change[%d]: %d", channel, inum));
+logger.log(Level.DEBUG, "program change[%d]: %d".formatted(channel, inum));
//
voiceStatus[channel].program = program;
}
@@ -700,19 +702,19 @@ public void send(MidiMessage message, long timeStamp) {
channels[channel].setPitchBend(data1 | (data2 << 7));
break;
default:
- Debug.printf("unhandled short: %02X", command);
+ logger.log(Level.DEBUG, "unhandled short: %02X".formatted(command));
}
}
case SysexMessage sysexMessage -> {
byte[] data = sysexMessage.getData();
-Debug.printf("sysex: %02X\n%s", sysexMessage.getStatus(), StringUtil.getDump(data, 32));
+logger.log(Level.DEBUG, "sysex: %02X\n%s".formatted(sysexMessage.getStatus(), StringUtil.getDump(data, 32)));
switch (data[1]) {
case 0x7 -> { // Universal Realtime
int c = data[2]; // 0x7f: Disregards channel
// Sub-ID, Sub-ID2
if (data[3] == 0x04 && data[4] == 0x01) { // Device Control / Master Volume
float gain = ((data[5] & 0x7f) | ((data[6] & 0x7f) << 7)) / 16383f;
-Debug.printf("sysex volume: gain: %3.0f", gain * 127);
+logger.log(Level.DEBUG, "sysex volume: gain: %3.0f".formatted(gain * 127));
for (c = 0; c < 16; c++) {
voiceStatus[c].volume = (int) (gain * 127); // TODO doesn't work
}
@@ -723,7 +725,7 @@ public void send(MidiMessage message, long timeStamp) {
case 0x10: // 7D 10 ch -- set an instrument to ch
// TODO maybe for LUCAS only
if (type != FileType.LUCAS) {
- Debug.println(Level.WARNING, "sysex test: set LUCAS_STYLE for " + type);
+ logger.log(Level.WARNING, "sysex test: set LUCAS_STYLE for " + type);
}
adlib.style = Adlib.LUCAS_STYLE | Adlib.MIDI_STYLE;
@@ -733,11 +735,11 @@ public void send(MidiMessage message, long timeStamp) {
break;
}
}
- default -> Debug.printf("sysex unhandled: %02x", data[1]);
+ default -> logger.log(Level.DEBUG, "sysex unhandled: %02x".formatted(data[1]));
}
}
case MetaMessage metaMessage -> {
-Debug.printf("meta: %02x", metaMessage.getType());
+logger.log(Level.DEBUG, "meta: %02x".formatted(metaMessage.getType()));
switch (metaMessage.getType()) {
case 0x2f -> {}
}
diff --git a/src/main/java/vavi/sound/midi/rococoa/RococoaMidiDeviceProvider.java b/src/main/java/vavi/sound/midi/rococoa/RococoaMidiDeviceProvider.java
index f40ee09..7ffd37a 100644
--- a/src/main/java/vavi/sound/midi/rococoa/RococoaMidiDeviceProvider.java
+++ b/src/main/java/vavi/sound/midi/rococoa/RococoaMidiDeviceProvider.java
@@ -6,12 +6,13 @@
package vavi.sound.midi.rococoa;
-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,6 +23,8 @@
*/
public class RococoaMidiDeviceProvider extends MidiDeviceProvider {
+ private static final Logger logger = getLogger(RococoaMidiDeviceProvider.class.getName());
+
/** Apple Computer */
public final static int MANUFACTURER_ID = 0x11;
@@ -39,11 +42,11 @@ public MidiDevice getDevice(MidiDevice.Info info)
throws IllegalArgumentException {
if (info == RococoaSynthesizer.info) {
-Debug.println(Level.FINE, "★1 info: " + info);
+logger.log(Level.DEBUG, "★1 info: " + info);
RococoaSynthesizer synthesizer = new RococoaSynthesizer();
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/rococoa/RococoaSoundbank.java b/src/main/java/vavi/sound/midi/rococoa/RococoaSoundbank.java
index 1e33ddf..6cd3b8d 100644
--- a/src/main/java/vavi/sound/midi/rococoa/RococoaSoundbank.java
+++ b/src/main/java/vavi/sound/midi/rococoa/RococoaSoundbank.java
@@ -26,7 +26,7 @@ public class RococoaSoundbank implements Soundbank {
static {
try {
- try (InputStream is = RococoaSynthesizer.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound-sandbox/pom.properties")) {
+ try (InputStream is = RococoaSoundbank.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound-sandbox/pom.properties")) {
if (is != null) {
Properties props = new Properties();
props.load(is);
diff --git a/src/main/java/vavi/sound/midi/rococoa/RococoaSynthesizer.java b/src/main/java/vavi/sound/midi/rococoa/RococoaSynthesizer.java
index 4569bf4..800bcb2 100644
--- a/src/main/java/vavi/sound/midi/rococoa/RococoaSynthesizer.java
+++ b/src/main/java/vavi/sound/midi/rococoa/RococoaSynthesizer.java
@@ -7,6 +7,8 @@
package vavi.sound.midi.rococoa;
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;
@@ -26,13 +28,14 @@
import javax.sound.midi.VoiceStatus;
import vavi.util.ByteUtil;
-import vavi.util.Debug;
import vavi.util.StringUtil;
import vavix.rococoa.avfoundation.AVAudioEngine;
import vavix.rococoa.avfoundation.AVAudioUnitMIDIInstrument;
import vavix.rococoa.avfoundation.AudioComponentDescription;
+import static java.lang.System.getLogger;
+
/**
* RococoaSynthesizer.
@@ -47,6 +50,8 @@
*/
public class RococoaSynthesizer implements Synthesizer {
+ private static final Logger logger = getLogger(RococoaSynthesizer.class.getName());
+
static {
try {
try (InputStream is = RococoaSynthesizer.class.getResourceAsStream("/META-INF/maven/vavi/vavi-sound-sandbox/pom.properties")) {
@@ -94,7 +99,7 @@ public Info getDeviceInfo() {
@Override
public void open() throws MidiUnavailableException {
if (isOpen()) {
-Debug.println("already open: " + hashCode());
+logger.log(Level.DEBUG, "already open: " + hashCode());
return;
}
@@ -105,14 +110,14 @@ public void open() throws MidiUnavailableException {
}
this.engine = AVAudioEngine.newInstance();
-Debug.println(engine);
+logger.log(Level.DEBUG, engine);
AudioComponentDescription description = new AudioComponentDescription();
description.componentType = AudioComponentDescription.kAudioUnitType_MusicDevice;
String audesc = System.getProperty(getClass().getName() + ".audesc", "appl:dls ");
String[] pair = audesc.split(":");
// for example "Ftcr:mc5p", "NiSc:nK1v"
-Debug.println("AudioUnit: " + pair[0] + ":" + pair[1]);
+logger.log(Level.DEBUG, "AudioUnit: " + pair[0] + ":" + pair[1]);
description.componentSubType = ByteUtil.readBeInt(pair[1].getBytes());
description.componentManufacturer = ByteUtil.readBeInt(pair[0].getBytes());
description.componentFlags = 0;
@@ -122,13 +127,13 @@ public void open() throws MidiUnavailableException {
if (midiSynth == null) {
throw new MidiUnavailableException(audesc);
}
-Debug.println(midiSynth + ", " + midiSynth.name() + ", " + midiSynth.version() + ", " + midiSynth.manufacturerName());
+logger.log(Level.DEBUG, midiSynth + ", " + midiSynth.name() + ", " + midiSynth.version() + ", " + midiSynth.manufacturerName());
engine.attachNode(midiSynth);
engine.connect_to_format(midiSynth, engine.mainMixerNode(), null);
engine.prepare();
boolean r = engine.start();
-Debug.println("stated: " + r + ", " + hashCode());
+logger.log(Level.DEBUG, "stated: " + r + ", " + hashCode());
}
@Override
@@ -459,11 +464,11 @@ public void send(MidiMessage message, long timeStamp) {
channels[channel].setPolyPressure(data1, data2);
break;
case ShortMessage.CONTROL_CHANGE:
-//Debug.printf("control change: %02X, %d %d\n", command, data1, data2);
+//logger.log(Level.TRACE, "control change: %02X, %d %d".formatted(command, data1, data2));
channels[channel].controlChange(data1, data2);
break;
case ShortMessage.PROGRAM_CHANGE:
-//Debug.printf("program change: %02X, %d %d\n", command, data1, data2);
+//logger.log(Level.TRACE, "program change: %02X, %d %d".formatted(command, data1, data2));
channels[channel].programChange(data1);
break;
case ShortMessage.CHANNEL_PRESSURE:
@@ -473,15 +478,15 @@ public void send(MidiMessage message, long timeStamp) {
channels[channel].setPitchBend(data1 | (data2 << 7));
break;
default:
-Debug.printf("unknown short: %02X\n", command);
+logger.log(Level.DEBUG, "unknown short: %02X".formatted(command));
}
} else if (message instanceof SysexMessage sysexMessage) {
byte[] data = sysexMessage.getData();
-Debug.printf("sysex: %02X\n%s", sysexMessage.getStatus(), StringUtil.getDump(data));
+logger.log(Level.DEBUG, "sysex: %02X\n%s".formatted(sysexMessage.getStatus(), StringUtil.getDump(data)));
midiSynth.sendMIDISysExEvent(data);
} else {
// TODO meta message
-Debug.printf(message.getClass().getName());
+logger.log(Level.DEBUG, message.getClass().getName());
}
} else {
throw new IllegalStateException("receiver is not open");
diff --git a/src/main/java/vavi/sound/mp3/Mp3Decoder.java b/src/main/java/vavi/sound/mp3/Mp3Decoder.java
index ddfb7bb..012d356 100644
--- a/src/main/java/vavi/sound/mp3/Mp3Decoder.java
+++ b/src/main/java/vavi/sound/mp3/Mp3Decoder.java
@@ -6,11 +6,12 @@
package vavi.sound.mp3;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
import java.util.StringJoiner;
-import vavi.util.Debug;
-import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
/**
@@ -22,25 +23,21 @@
* @version 2.00 030817 nsano java port
*/
class Mp3Decoder {
- /** */
- private static class GrInfo {
- final int length;
- final int bigValues;
- final int gain;
- GrInfo(int length, int bigValues, int gain) {
- this.length = length;
- this.bigValues = bigValues;
- this.gain = gain;
- }
- @Override public String toString() {
- return new StringJoiner(", ", GrInfo.class.getSimpleName() + "[", "]")
- .add("length=" + length)
- .add("bigValues=" + bigValues)
- .add("gain=" + gain)
- .toString();
+ private static final Logger logger = getLogger(Mp3Decoder.class.getName());
+
+ /** */
+ private record GrInfo(int length, int bigValues, int gain) {
+
+ @Override
+ public String toString() {
+ return new StringJoiner(", ", GrInfo.class.getSimpleName() + "[", "]")
+ .add("length=" + length)
+ .add("bigValues=" + bigValues)
+ .add("gain=" + gain)
+ .toString();
+ }
}
- }
/** */
static class MpegDecodeParam {
@@ -139,13 +136,13 @@ static class MpegHeader {
final int mode;
/** Gets header information. */
public MpegHeader(byte[] buf, int offset) {
-Debug.println("offset: " + offset);
+logger.log(Level.DEBUG, "offset: " + offset);
this.version = (buf[offset + 1] & 0x18) >> 3;
this.layer = (buf[offset + 1] & 0x06) >> 1;
this.bitrate = m_bitrate[3 - layer][(buf[offset + 2] & 0xf0) >> 4];
this.frequency = m_frequency[version == 3 ? 0 : 1][(buf[offset + 2] & 0x0c) >> 2];
this.mode = (buf[offset + 3] & 0xc0) >> 6;
-//Debug.println(this);
+//logger.log(Level.TRACE, this);
}
@Override public String toString() {
@@ -268,7 +265,7 @@ public void decode(MpegDecodeParam param) throws IllegalArgumentException {
MpegHeader header = param.header;
m_frame_size = (144 * header.bitrate * 1000) / m_freq;
-Debug.println("m_frame_size: " + m_frame_size + ", bitrate: "+ header.bitrate);
+logger.log(Level.DEBUG, "m_frame_size: " + m_frame_size + ", bitrate: "+ header.bitrate);
if (param.inputSize < m_frame_size) {
throw new IllegalArgumentException("inputSize: " + param.inputSize + " < frameSize: " + m_frame_size);
@@ -278,7 +275,7 @@ public void decode(MpegDecodeParam param) throws IllegalArgumentException {
param.inputSize = m_frame_size;
param.outputSize = m_pcm_size;
-//Debug.println(StringUtil.paramString(param));
+//logger.log(Level.TRACE, StringUtil.paramString(param));
}
/**
@@ -387,7 +384,7 @@ private int l3dstream_sideinfo(GrInfo[][] info, int channels) {
for (int gr = 0; gr < 2; gr++) {
for (int ch = 0; ch < channels; ch++) {
info[gr][ch] = new GrInfo(bitget(12), bitget(9), bitget(8));
-Debug.println(info[gr][ch]);
+logger.log(Level.DEBUG, info[gr][ch]);
bitget(4);
bitget(1);
bitget(5);
@@ -590,9 +587,9 @@ private void huff_decodebits(int[] xy, int n) {
while (true) {
int bits = signBits(point);
-//Debug.println("bits: " + bits);
+//logger.log(Level.TRACE, "bits: " + bits);
code = bitget2(bits) + 1;
-//Debug.println("code: " + code);
+//logger.log(Level.TRACE, "code: " + code);
if (purgeBits(code + point) != 0) {
break;
@@ -671,7 +668,7 @@ private int bitget(int n) {
if (m_bits < n) {
while (m_bits <= 24) {
-Debug.printf("%02x", base[m_bs_ptr]);
+logger.log(Level.DEBUG, "%02x".formatted(base[m_bs_ptr]));
m_bitbuf = ((m_bitbuf << 8)) | (base[m_bs_ptr++] & 0xff);
m_bits += 8;
}
diff --git a/src/main/java/vavi/sound/mp3/Mp3InputStream.java b/src/main/java/vavi/sound/mp3/Mp3InputStream.java
index e5706a0..2f3753f 100644
--- a/src/main/java/vavi/sound/mp3/Mp3InputStream.java
+++ b/src/main/java/vavi/sound/mp3/Mp3InputStream.java
@@ -10,10 +10,13 @@
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
-import vavi.util.Debug;
import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
+
/**
* Mp3InputStream.
@@ -26,6 +29,8 @@
*/
public class Mp3InputStream extends FilterInputStream {
+ private static final Logger logger = getLogger(Mp3InputStream.class.getName());
+
/** */
private final Mp3Decoder.MpegDecodeInfo decodeInfo;
@@ -58,16 +63,16 @@ public Mp3InputStream(InputStream in) throws IOException {
// find first sync
int firstSyncAddress = Mp3Decoder.findSync(buf, 0, readBytes);
-Debug.printf("firstSyncAddress: %08x", firstSyncAddress);
+logger.log(Level.DEBUG, "firstSyncAddress: %08x".formatted(firstSyncAddress));
decodeInfo = decoder.getInfo(buf, firstSyncAddress, readBytes - firstSyncAddress);
-Debug.println(decodeInfo);
+logger.log(Level.DEBUG, decodeInfo);
//
in.reset();
-Debug.println("mp3 in.available(): " + in.available());
+logger.log(Level.DEBUG, "mp3 in.available(): " + in.available());
int length = firstSyncAddress;
// int length = firstSyncAddress + 4 + (decodeInfo.header.mode != 3 ? 32 : 17);
-Debug.println("skip length: " + length);
+logger.log(Level.DEBUG, "skip length: " + length);
int skipBytes = 0;
while (skipBytes < length) {
int l = (int) in.skip(length - skipBytes);
@@ -88,16 +93,16 @@ public Mp3InputStream(InputStream in) throws IOException {
int totalSamples = (frames * decodeInfo.outputSize * 8) / 16 / decodeInfo.channels;
int totalSeconds = totalSamples / decodeInfo.frequency;
-Debug.println("---- mp3 ----");
-Debug.println("size : " + size);
-Debug.println("dataSize : " + dataSize);
+logger.log(Level.DEBUG, "---- mp3 ----");
+logger.log(Level.DEBUG, "size : " + size);
+logger.log(Level.DEBUG, "dataSize : " + dataSize);
-Debug.println("channels : " + channels);
-Debug.println("frequency : " + frequency + " [Hz]");
-Debug.println("bitRate : " + bitRate + " [bit/s]");
-Debug.println("totalFrames : " + totalFrames);
-Debug.println("totalSamples: " + totalSamples);
-Debug.println("totalSeconds: " + totalSeconds + " [s]");
+logger.log(Level.DEBUG, "channels : " + channels);
+logger.log(Level.DEBUG, "frequency : " + frequency + " [Hz]");
+logger.log(Level.DEBUG, "bitRate : " + bitRate + " [bit/s]");
+logger.log(Level.DEBUG, "totalFrames : " + totalFrames);
+logger.log(Level.DEBUG, "totalSamples: " + totalSamples);
+logger.log(Level.DEBUG, "totalSeconds: " + totalSeconds + " [s]");
}
/**
@@ -106,7 +111,7 @@ public Mp3InputStream(InputStream in) throws IOException {
*/
@Override
public int available() throws IOException {
-Debug.println("wave available: " + in.available() + ", " + decodeInfo.inputSize + ", " + decodeInfo.outputSize);
+logger.log(Level.DEBUG, "wave available: " + in.available() + ", " + decodeInfo.inputSize + ", " + decodeInfo.outputSize);
return in.available() / decodeInfo.inputSize * decodeInfo.outputSize;
}
@@ -126,16 +131,16 @@ public int read() throws IOException {
public int read(byte[] data, int offset, int length) throws IOException {
if (!skipNextSync()) {
-Debug.println("End of Frames");
+logger.log(Level.DEBUG, "End of Frames");
return -1;
}
Mp3Decoder.MpegDecodeParam param = new Mp3Decoder.MpegDecodeParam();
-//Debug.println("length: " + length);
-Debug.println("decodeInfo: " + decodeInfo);
+//logger.log(Level.TRACE, "length: " + length);
+logger.log(Level.DEBUG, "decodeInfo: " + decodeInfo);
param.inputSize = decodeInfo.inputSize;
-Debug.println("param.inputSize: " + param.inputSize);
+logger.log(Level.DEBUG, "param.inputSize: " + param.inputSize);
param.inputBuf = new byte[param.inputSize];
int readBytes = 0;
while (readBytes < param.inputSize) {
@@ -147,7 +152,7 @@ public int read(byte[] data, int offset, int length) throws IOException {
}
//
-Debug.println("mp3:\n" + StringUtil.getDump(param.inputBuf, 16));
+logger.log(Level.DEBUG, "mp3:\n" + StringUtil.getDump(param.inputBuf, 16));
decoder.prepareDecode(param.inputBuf, 0, param.inputSize);
param.outputSize = decodeInfo.outputSize;
@@ -203,10 +208,10 @@ private boolean skipNextSync() throws IOException {
while (l < length) {
l += (int) in.skip(length - l);
}
-Debug.println("skip: " + length);
+logger.log(Level.DEBUG, "skip: " + length);
return true;
} catch (IllegalArgumentException e) {
-Debug.println("no more sync");
+logger.log(Level.DEBUG, "no more sync");
in.reset();
return false; // no more data
}
diff --git a/src/main/java/vavi/sound/opl3/Adlib.java b/src/main/java/vavi/sound/opl3/Adlib.java
index 8d5675a..250980b 100644
--- a/src/main/java/vavi/sound/opl3/Adlib.java
+++ b/src/main/java/vavi/sound/opl3/Adlib.java
@@ -6,9 +6,10 @@
package vavi.sound.opl3;
-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;
/**
@@ -20,6 +21,9 @@
* @version 0.00 2020/10/23 umjammer initial version
*/
public class Adlib {
+
+ private static final Logger logger = getLogger(Adlib.class.getName());
+
public static final int LUCAS_STYLE = 1;
public static final int CMF_STYLE = 2;
public static final int MIDI_STYLE = 4;
@@ -229,7 +233,7 @@ public int read(int address) {
}
public void write(int address, int data) {
-Debug.printf(Level.FINEST, "write: %04x, %02x", address, data);
+logger.log(Level.TRACE, "write: %04x, %02x".formatted(address, data));
writer.write(0, address, data);
this.data[address] = data;
}
diff --git a/src/main/java/vavi/sound/opl3/AdvancedSierraFile.java b/src/main/java/vavi/sound/opl3/AdvancedSierraFile.java
index bc1a488..b153624 100644
--- a/src/main/java/vavi/sound/opl3/AdvancedSierraFile.java
+++ b/src/main/java/vavi/sound/opl3/AdvancedSierraFile.java
@@ -8,14 +8,15 @@
import java.io.DataInputStream;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.net.URI;
-import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.logging.Logger;
-import vavi.sound.midi.opl3.Opl3Soundbank;
import vavi.sound.midi.opl3.Opl3Synthesizer.Context;
+import static java.lang.System.getLogger;
+
/**
* AdvancedSierraFile. (SCI)
@@ -25,9 +26,7 @@
*/
class AdvancedSierraFile extends SierraFile {
- private static final Logger logger = Logger.getLogger(MidiFile.class.getName());
-
- private URI uri;
+ private static final Logger logger = getLogger(AdvancedSierraFile.class.getName());
@Override
int markSize() {
@@ -36,65 +35,19 @@ int markSize() {
@Override
boolean matchFormatImpl(DataInputStream dis) throws IOException {
- if (uri != null) loadSierraIns(Path.of(uri));
return dis.readUnsignedByte() == 0x84 &&
dis.readUnsignedByte() == 0 &&
- dis.readUnsignedByte() == 0xf0;
+ dis.readUnsignedByte() == 0xf0; // advanced sierra flag
}
private int sierraPos;
- private static int[] fromSierra(int[] buf) {
- int[] x = new int[11];
- x[0] = buf[9] * 0x80 + buf[10] * 0x40 + buf[5] * 0x20 + buf[11] * 0x10 + buf[1];
- x[1] = buf[22] * 0x80 + buf[23] * 0x40 + buf[18] * 0x20 + buf[24] * 0x10 + buf[14];
- x[2] = (buf[0] << 6) + buf[8];
- x[3] = (buf[13] << 6) + buf[21];
- x[4] = (buf[3] << 4) + buf[6];
- x[5] = (buf[16] << 4) + buf[19];
- x[6] = (buf[4] << 4) + buf[7];
- x[7] = (buf[17] << 4) + buf[20];
- x[8] = buf[26];
- x[9] = buf[27];
- x[10] = (buf[2] << 1) + (1 - (buf[12] & 1));
- return x;
- }
-
- private void loadSierraIns(Path path) throws IOException {
-
- Path patch = path.getParent().resolve("patch.003");
- DataInputStream dis = new DataInputStream(Files.newInputStream(patch.toFile().toPath()));
- dis.skipBytes(2);
- stins = 0;
-
- for (int j = 0; j < 2; ++j) {
- for (int k = 0; k < 48; ++k) {
- int p = j * 48 + k;
- logger.fine(String.format("%2d: ", p));
-
- int[] buf = new int[28];
-
- for (int i = 0; i < 28; ++i) {
- buf[i] = dis.readUnsignedByte();
- }
-
- smyinsbank[p] = Opl3Soundbank.newInstrument(0, p, "sierra." + p, fromSierra(buf));
-
- ++stins;
- }
-
- dis.skipBytes(2);
- }
-
- dis.close();
- }
-
private void sierra_next_section(MidPlayer player) throws IOException {
for (int t = 0; t < 16; ++t) {
player.tracks[t].on = false;
}
-logger.info("next adv sierra section:");
+logger.log(Level.INFO, "next adv sierra section:");
player.pos = sierraPos;
int t = 0;
@@ -106,7 +59,7 @@ private void sierra_next_section(MidPlayer player) throws IOException {
player.tracks[t].tend = player.flen;
player.tracks[t].iwait = 0;
player.tracks[t].pv = 0;
-logger.info(String.format("track %d starts at %x", t, player.tracks[t].spos));
+logger.log(Level.INFO, String.format("track %d starts at %x", t, player.tracks[t].spos));
t++;
player.takeBE(2);
}
@@ -121,6 +74,9 @@ private void sierra_next_section(MidPlayer player) throws IOException {
@Override
void rewind(int subSong, MidPlayer player) throws IOException {
this.uri = (URI) player.getProperties().get("uri");
+logger.log(Level.DEBUG, "uri: " + uri);
+ if (uri != null) loadSierraIns(uri);
+
player.tins = stins;
player.deltas = 32;
player.takeBE(12); // worthless empty space and "stuff" :)
diff --git a/src/main/java/vavi/sound/opl3/CmfFile.java b/src/main/java/vavi/sound/opl3/CmfFile.java
index 57e684b..0d2d390 100644
--- a/src/main/java/vavi/sound/opl3/CmfFile.java
+++ b/src/main/java/vavi/sound/opl3/CmfFile.java
@@ -8,14 +8,17 @@
import java.io.DataInputStream;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
-import java.util.logging.Logger;
import vavi.sound.midi.opl3.Opl3Soundbank;
import vavi.sound.midi.opl3.Opl3Soundbank.Opl3Instrument;
import vavi.sound.midi.opl3.Opl3Synthesizer.Context;
import vavi.sound.opl3.MidPlayer.MidiTypeFile;
+import static java.lang.System.getLogger;
+
/**
* CmfFile (CMF).
@@ -25,7 +28,7 @@
*/
class CmfFile extends MidiTypeFile {
- private static final Logger logger = Logger.getLogger(CmfFile.class.getName());
+ private static final Logger logger = getLogger(CmfFile.class.getName());
@Override
int markSize() {
@@ -72,12 +75,12 @@ void rewind(int subSong, MidPlayer player) throws IOException {
}
player.takeLE(2); // basic tempo
}
- logger.info(String.format("numinstr: 0x%04x", player.tins));
+ logger.log(Level.INFO, String.format("numinstr: 0x%04x", player.tins));
this.tins = player.tins;
- logger.info(String.format("ioff: 0x%04x, moff: 0x%04x, deltas: %d, msqtr: %d, numi: %d, v: %04x", n, m, player.deltas, player.msqtr, player.tins, v));
+ logger.log(Level.INFO, String.format("ioff: 0x%04x, moff: 0x%04x, deltas: %d, msqtr: %d, numi: %d, v: %04x", n, m, player.deltas, player.msqtr, player.tins, v));
player.takeBE(n - 40);
- logger.info(String.format("pos1: 0x%04x", player.pos));
+ logger.log(Level.INFO, String.format("pos1: 0x%04x", player.pos));
this.instruments = new Opl3Instrument[this.tins];
for (int p = 0; p < player.tins; ++p) {
@@ -87,9 +90,9 @@ void rewind(int subSong, MidPlayer player) throws IOException {
x[j] = player.takeBE(1);
}
this.instruments[p] = Opl3Soundbank.newInstrument(0, p, "oldlucas." + p, x);
- logger.fine(String.format("%d: %s", p, Arrays.toString((int[]) this.instruments[p].getData())));
+ logger.log(Level.DEBUG, "%d: %s".formatted(p, Arrays.toString((int[]) this.instruments[p].getData())));
}
- logger.info(String.format("pos2: 0x%04x", player.pos));
+ logger.log(Level.INFO, "pos2: 0x%04x".formatted(player.pos));
player.tracks[0].on = true;
player.tracks[0].tend = player.flen; // music until the end of the file
@@ -139,7 +142,7 @@ public void controlChange(int channel, int controller, int value) {
// }
}
case 0x67 -> { // 103: undefined
- logger.fine(String.format("control change[%d]: (%02x): %d", channel, controller, value));
+ logger.log(Level.DEBUG, "control change[%d]: (%02x): %d".formatted(channel, controller, value));
// if ((adlib.style & Adlib.CMF_STYLE) != 0) {
adlib.mode = value;
if (adlib.mode == Adlib.RYTHM) {
diff --git a/src/main/java/vavi/sound/opl3/Dro2Player.java b/src/main/java/vavi/sound/opl3/Dro2Player.java
index 49686f8..c28db3e 100644
--- a/src/main/java/vavi/sound/opl3/Dro2Player.java
+++ b/src/main/java/vavi/sound/opl3/Dro2Player.java
@@ -21,12 +21,14 @@
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import vavi.io.LittleEndianDataInputStream;
+import static java.lang.System.getLogger;
+
/**
* DOSBox Raw OPL v2.0 player (DRO).
@@ -37,7 +39,8 @@
* @author Wraithverge
*/
class Dro2Player extends Opl3Player {
- private static final Logger logger = Logger.getLogger(Dro2Player.class.getName());
+
+ private static final Logger logger = getLogger(Dro2Player.class.getName());
private LittleEndianDataInputStream data;
private int pos;
@@ -81,7 +84,7 @@ public boolean matchFormat(InputStream bitStream) {
try {
dis.reset();
} catch (IOException e) {
- logger.fine(e.toString());
+ logger.log(Level.DEBUG, e.toString());
}
}
}
@@ -120,13 +123,13 @@ public void load(InputStream is) throws IOException {
toReg[i] = dis.readUnsignedByte();
}
-logger.fine("id: " + DroPlayer.ID);
-logger.fine("version: " + 2);
-logger.fine("length: " + length);
-logger.fine("mstotal: " + msTotal);
-logger.fine("opl3Type: " + opl3Type);
-logger.fine("delay256: " + delay256);
-logger.fine("delayShift8: " + delayShift8);
+logger.log(Level.DEBUG, "id: " + DroPlayer.ID);
+logger.log(Level.DEBUG, "version: " + 2);
+logger.log(Level.DEBUG, "length: " + length);
+logger.log(Level.DEBUG, "mstotal: " + msTotal);
+logger.log(Level.DEBUG, "opl3Type: " + opl3Type);
+logger.log(Level.DEBUG, "delay256: " + delay256);
+logger.log(Level.DEBUG, "delayShift8: " + delayShift8);
data = dis;
diff --git a/src/main/java/vavi/sound/opl3/DroPlayer.java b/src/main/java/vavi/sound/opl3/DroPlayer.java
index 7f9c734..17f7c9a 100644
--- a/src/main/java/vavi/sound/opl3/DroPlayer.java
+++ b/src/main/java/vavi/sound/opl3/DroPlayer.java
@@ -21,12 +21,14 @@
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import vavi.io.LittleEndianDataInputStream;
+import static java.lang.System.getLogger;
+
/**
* DOSBox Raw OPL Player (DRO).
@@ -46,7 +48,7 @@
*/
class DroPlayer extends Opl3Player {
- private static final Logger logger = Logger.getLogger(DroPlayer.class.getName());
+ private static final Logger logger = getLogger(DroPlayer.class.getName());
protected static final String ID = "DBRAWOPL";
@@ -90,7 +92,7 @@ public boolean matchFormat(InputStream bitStream) {
try {
dis.reset();
} catch (IOException e) {
- logger.fine(e.toString());
+ logger.log(Level.DEBUG, e.toString());
}
}
}
@@ -118,14 +120,14 @@ public void load(InputStream is) throws IOException {
if (zero[0] != 0 || zero[1] != 0 || zero[2] != 0) {
// need these three bytes!
dis.reset();
-logger.fine("not zero: " + Arrays.toString(zero));
+logger.log(Level.DEBUG, "not zero: " + Arrays.toString(zero));
}
-logger.fine("id: " + ID);
-logger.fine("version: " + 1);
-logger.fine("mstotal: " + mstotal);
-logger.fine("length: " + length);
-logger.fine("oplType: " + opl3_mode);
+logger.log(Level.DEBUG, "id: " + ID);
+logger.log(Level.DEBUG, "version: " + 1);
+logger.log(Level.DEBUG, "mstotal: " + mstotal);
+logger.log(Level.DEBUG, "length: " + length);
+logger.log(Level.DEBUG, "oplType: " + opl3_mode);
data = dis;
@@ -175,7 +177,7 @@ public boolean update() throws IOException {
if (pos >= length) return false;
int v = data.readUnsignedByte();
-logger.fine(String.format("%d, %d, %d, %02x", opl3_mode, currChip, iIndex, v));
+logger.log(Level.DEBUG, "%d, %d, %d, %02x".formatted(opl3_mode, currChip, iIndex, v));
++pos;
if (opl3_mode == 0) {
write(0, iIndex, v);
diff --git a/src/main/java/vavi/sound/opl3/MidPlayer.java b/src/main/java/vavi/sound/opl3/MidPlayer.java
index 531582f..f869ef6 100644
--- a/src/main/java/vavi/sound/opl3/MidPlayer.java
+++ b/src/main/java/vavi/sound/opl3/MidPlayer.java
@@ -22,12 +22,12 @@
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.sound.midi.ControllerEventListener;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MetaEventListener;
@@ -45,12 +45,13 @@
import vavi.sound.midi.MidiConstants;
import vavi.sound.midi.MidiConstants.MetaEvent;
-import vavi.sound.midi.MidiUtil;
import vavi.sound.midi.opl3.Opl3Soundbank;
import vavi.sound.midi.opl3.Opl3Synthesizer;
import vavi.sound.midi.opl3.Opl3Synthesizer.Context;
import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
+
/**
* MIDI & MIDI-like file player
@@ -113,7 +114,7 @@
*/
public class MidPlayer extends Opl3Player implements Sequencer {
- private static final Logger logger = Logger.getLogger(MidPlayer.class.getName());
+ private static final Logger logger = getLogger(MidPlayer.class.getName());
/** midi like file types */
public enum FileType {
@@ -141,6 +142,7 @@ static int maxMarkSize(InputStream is) {
}
}
+ /** mark/reset are inside this method */
public static abstract class MidiTypeFile {
boolean matchFormat(InputStream bitStream) {
DataInputStream dis = new DataInputStream(bitStream);
@@ -154,11 +156,12 @@ boolean matchFormat(InputStream bitStream) {
try {
dis.reset();
} catch (IOException e) {
- logger.log(Level.FINE, e.getMessage());
+ logger.log(Level.DEBUG, e.toString());
}
}
}
abstract int markSize();
+ /** no need to mark/reset inside this method */
abstract boolean matchFormatImpl(DataInputStream dis) throws IOException;
abstract void rewind(int subSong, MidPlayer player) throws IOException;
public abstract void init(Context context);
@@ -219,7 +222,7 @@ public void initOn() {
@Override
public boolean matchFormat(InputStream bitStream) {
-logger.finer("\n" + StringUtil.getDump(bitStream, 0, 64));
+logger.log(Level.TRACE, "\n" + StringUtil.getDump(bitStream, 0, 64));
try {
type = FileType.getFileType(bitStream);
return true;
@@ -298,7 +301,7 @@ public void load(InputStream is) throws IOException {
DataInputStream dis = new DataInputStream(is);
subsongs = 1;
-logger.fine("type: " + type);
+logger.log(Level.DEBUG, "type: " + type);
dis.reset();
flen = dis.available();
@@ -344,7 +347,7 @@ public boolean update() throws IOException {
tracks[t].pv = v;
int c = v & 0x0f;
-logger.finer(String.format("[%2X]", v));
+logger.log(Level.TRACE, "[%2X]".formatted(v));
int data1;
int data2;
@@ -408,10 +411,10 @@ public boolean update() throws IOException {
for (int i = 2; i < b.length; i++) {
b[i] = (byte) (takeBE(1) & 0xff);
}
- logger.finer(String.format("sysex: %02x, %d\n%s", v, l, StringUtil.getDump(b, Math.min(l + 2, 64))));
+logger.log(Level.TRACE, "sysex: %02x, %d\n%s".formatted(v, l, StringUtil.getDump(b, Math.min(l + 2, 64))));
midiMessage = new SysexMessage();
((SysexMessage) midiMessage).setMessage(b, b.length);
- logger.finest("sysex: len: " + midiMessage.getLength());
+logger.log(Level.TRACE, "sysex: len: " + midiMessage.getLength());
if (f) {
takeBE(1);
}
@@ -422,7 +425,7 @@ public boolean update() throws IOException {
case 0xfd:
case 0xfe:
default:
- logger.fine(String.format("sysex: unhandled: %02x", v));
+ logger.log(Level.DEBUG, "sysex: unhandled: %02x".formatted(v));
break;
case 0xf2:
data1 = takeBE(1);
@@ -443,27 +446,28 @@ public boolean update() throws IOException {
// this ends the track for sierra.
if (type == FileType.SIERRA || type == FileType.ADVSIERRA) {
tracks[t].tend = pos;
- logger.info(String.format("endmark: %d -- %x\n", pos, pos));
+logger.log(Level.INFO, "endmark: %d -- %x".formatted(pos, pos));
}
break;
case 0xff: // meta
v = takeBE(1);
- l = takeBE(1);
-logger.fine(String.format("meta: %02x, %s\n%s", v, MidiConstants.MetaEvent.valueOf(v), StringUtil.getDump(data, 0, l)));
+ l = takeLen();
+logger.log(Level.DEBUG, "meta: %02x, %s, %d\n%s".formatted(v, MidiConstants.MetaEvent.valueOf(v), l, StringUtil.getDump(data, 0, l)));
switch (v) {
case 0x2f:
- logger.info(String.format("meta: %02x", v));
+ logger.log(Level.INFO, String.format("meta: %02x", v));
if (data.available() > 0) {
- logger.fine("out of spec data for meta:0x2f: " + data.available());
+ logger.log(Level.DEBUG, "out of spec data for meta:0x2f: " + data.available());
+ l += data.available();
}
takeBE(l); // TODO out of spec.
break;
case 0x51:
msqtr = takeBE(l); // set tempo
- logger.fine(String.format("(qtr=%d)", msqtr));
+ logger.log(Level.DEBUG, "(qtr=%d)".formatted(msqtr));
break;
default:
- logger.finer(String.format("meta unhandled: %02x, %02x", v, l));
+ logger.log(Level.TRACE, String.format("meta unhandled: %02x, %02x", v, l));
for (int i = 0; i < l; ++i) {
takeBE(1);
}
@@ -474,18 +478,18 @@ public boolean update() throws IOException {
break;
default:
// if we get down here, an error occurred
- logger.warning(String.format("unknown midi command!: %02x at %d", v, pos));
+ logger.log(Level.WARNING, "unknown midi command!: %02x at %d".formatted(v, pos));
break;
}
} catch (InvalidMidiDataException e) {
- logger.log(Level.SEVERE, e.getMessage(), e);
+ logger.log(Level.ERROR, e.getMessage(), e);
}
if (midiMessage != null) {
transmitter.getReceiver().send(midiMessage, -1);
}
-logger.finer(String.format("pos: %d, end: %d", pos, tracks[t].tend));
+logger.log(Level.TRACE, "pos: %d, end: %d".formatted(pos, tracks[t].tend));
if (pos < tracks[t].tend) {
int w;
if (type != FileType.SIERRA && type != FileType.ADVSIERRA) {
@@ -531,7 +535,7 @@ public boolean update() throws IOException {
}
}
-// logger.info(String.format("iwait: %d, deltas: %d, msqtr: %d", iwait, deltas, msqtr));
+// logger.log(Level.INFO, String.format("iwait: %d, deltas: %d, msqtr: %d", iwait, deltas, msqtr));
if (iwait != 0 && eos) {
for (int t = 0; t < MAX_CHANNELS; ++t) {
if (tracks[t].on) {
@@ -547,9 +551,9 @@ public boolean update() throws IOException {
for (int t = 0; t < MAX_CHANNELS; ++t) {
if (tracks[t].on) {
if (tracks[t].pos < tracks[t].tend) {
- logger.finer(String.format("iwait: %d", tracks[t].iwait));
+ logger.log(Level.TRACE, String.format("iwait: %d", tracks[t].iwait));
} else {
- logger.finer("stop");
+ logger.log(Level.TRACE, "stop");
}
}
}
@@ -575,7 +579,7 @@ public static int[] fromSysex(byte[] data) {
x[7] = 0xff - (((data[pos + 20] & 0xff) << 4) + (data[pos + 21] & 0xff));
x[9] = ((data[pos + 22] & 0xff) << 4) + (data[pos + 23] & 0xff);
x[10] = ((data[pos + 24] & 0xff) << 4) + (data[pos + 24] & 0xff);
-logger.fine(String.format("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10]));
+logger.log(Level.DEBUG, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x".formatted(x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10]));
return x;
}
diff --git a/src/main/java/vavi/sound/opl3/MidiFile.java b/src/main/java/vavi/sound/opl3/MidiFile.java
index 7fe1762..b922bcc 100644
--- a/src/main/java/vavi/sound/opl3/MidiFile.java
+++ b/src/main/java/vavi/sound/opl3/MidiFile.java
@@ -8,12 +8,15 @@
import java.io.DataInputStream;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
-import java.util.logging.Logger;
import vavi.sound.midi.opl3.Opl3Synthesizer.Context;
import vavi.sound.opl3.MidPlayer.MidiTypeFile;
+import static java.lang.System.getLogger;
+
/**
* MidiFile.
@@ -26,7 +29,7 @@
*/
class MidiFile extends MidiTypeFile {
- private static final Logger logger = Logger.getLogger(MidiFile.class.getName());
+ private static final Logger logger = getLogger(MidiFile.class.getName());
@Override
int markSize() {
@@ -36,15 +39,15 @@ int markSize() {
@Override
boolean matchFormatImpl(DataInputStream dis) throws IOException {
if (!Boolean.parseBoolean(System.getProperty("vavi.sound.opl3.MidiFile", "false"))) {
-logger.fine("vavi.sound.opl3.MidiFile: false");
+logger.log(Level.DEBUG, "vavi.sound.opl3.MidiFile: false");
return false;
}
-logger.fine("use vavi.sound.opl3.MidiFile");
+logger.log(Level.DEBUG, "use vavi.sound.opl3.MidiFile");
byte[] chunkType = new byte[4];
dis.readFully(chunkType);
dis.skipBytes(4);
int format = dis.readUnsignedShort();
-logger.fine("format: " + format);
+logger.log(Level.DEBUG, "format: " + format);
return Arrays.equals("MThd".getBytes(), chunkType) && format == 0;
}
@@ -56,13 +59,13 @@ void rewind(int subSong, MidPlayer player) throws IOException {
}
player.takeBE(3 + 4 + 2 + 2); // skip header
player.deltas = player.takeBE(2);
-logger.fine(String.format("deltas: %d", player.deltas));
+logger.log(Level.DEBUG, "deltas: %d".formatted(player.deltas));
player.takeBE(4);
player.tracks[0].on = true;
player.tracks[0].tend = player.takeBE(4);
player.tracks[0].spos = player.pos;
-logger.fine(String.format("tracklen: %d", player.tracks[0].tend));
+logger.log(Level.DEBUG, "tracklen: %d".formatted(player.tracks[0].tend));
}
protected Context context;
diff --git a/src/main/java/vavi/sound/opl3/OPL3.java b/src/main/java/vavi/sound/opl3/OPL3.java
index 557bf82..a9b1bc1 100644
--- a/src/main/java/vavi/sound/opl3/OPL3.java
+++ b/src/main/java/vavi/sound/opl3/OPL3.java
@@ -73,9 +73,12 @@ public final class OPL3 {
// The methods read() and write() are the only
// ones needed by the user to interface with the emulator.
- // read() returns one frame at a time, to be played at 49700 Hz,
- // with each frame being four 16-bit samples,
- // corresponding to the OPL3 four output channels CHA...CHD.
+
+ /**
+ * read() returns one frame at a time, to be played at 49700 Hz,
+ * with each frame being four 16-bit samples,
+ * corresponding to the OPL3 four output channels CHA...CHD.
+ */
public short[] read() {
short[] output = new short[4];
double[] outputBuffer = new double[4];
@@ -98,7 +101,7 @@ public short[] read() {
// with a maximum of 18 channels,
// and multiplies it to get the 16 bit signed output.
for (int outputChannelNumber = 0; outputChannelNumber < 4; outputChannelNumber++)
- output[outputChannelNumber] = (short) (outputBuffer[outputChannelNumber] / 18 * 0x7FFF);
+ output[outputChannelNumber] = (short) (outputBuffer[outputChannelNumber] / 18 * 0x7fff);
// Advances the OPL3-wide vibrato index, which is used by
// PhaseGenerator.getPhase() in each Operator.
@@ -115,7 +118,7 @@ public short[] read() {
}
public void write(int array, int address, int data) {
- // The OPL3 has two registers arrays, each with adresses ranging
+ // The OPL3 has two registers arrays, each with addresses ranging
// from 0x00 to 0xF5.
// This emulator uses one array, with the two original register arrays
// starting at 0x00 and at 0x100.
@@ -125,7 +128,7 @@ public void write(int array, int address, int data) {
return;
registers[registerAddress] = data;
- switch (address & 0xE0) {
+ switch (address & 0xe0) {
// The first 3 bits masking gives the type of the register by using its base address:
// 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0
// When it is needed, we further separate the register type inside each base address,
@@ -147,37 +150,37 @@ else if (address == 0x05)
update_1_NTS1_6();
break;
- case 0xA0:
+ case 0xa0:
// 0xBD is a control register for the entire OPL3:
- if (address == 0xBD) {
+ if (address == 0xbd) {
if (array == 0)
update_DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1();
break;
}
// Registers for each channel are in A0-A8, B0-B8, C0-C8, in both register arrays.
// 0xB0...0xB8 keeps kon,block,fnum(h) for each channel.
- if ((address & 0xF0) == 0xB0 && address <= 0xB8) {
+ if ((address & 0xf0) == 0xb0 && address <= 0xb8) {
// If the address is in the second register array, adds 9 to the channel number.
// The channel number is given by the last four bits, like in A0,...,A8.
- channels[array][address & 0x0F].update_2_KON1_BLOCK3_FNUMH2();
+ channels[array][address & 0x0f].update_2_KON1_BLOCK3_FNUMH2();
break;
}
// 0xA0...0xA8 keeps fnum(l) for each channel.
- if ((address & 0xF0) == 0xA0 && address <= 0xA8)
- channels[array][address & 0x0F].update_FNUML8();
+ if ((address & 0xf0) == 0xa0 && address <= 0xa8)
+ channels[array][address & 0x0f].update_FNUML8();
break;
// 0xC0...0xC8 keeps cha,chb,chc,chd,fb,cnt for each channel:
- case 0xC0:
- if (address <= 0xC8)
- channels[array][address & 0x0F].update_CHD1_CHC1_CHB1_CHA1_FB3_CNT1();
+ case 0xc0:
+ if (address <= 0xc8)
+ channels[array][address & 0x0f].update_CHD1_CHC1_CHB1_CHA1_FB3_CNT1();
break;
// Registers for each of the 36 Operators:
default:
- int operatorOffset = address & 0x1F;
+ int operatorOffset = address & 0x1f;
if (operators[array][operatorOffset] == null)
break;
- switch (address&0xE0) {
+ switch (address & 0xe0) {
// 0x20...0x35 keeps am,vib,egt,ksr,mult for each operator:
case 0x20:
operators[array][operatorOffset].update_AM1_VIB1_EGT1_KSR1_MULT4();
@@ -195,7 +198,7 @@ else if (address == 0x05)
operators[array][operatorOffset].update_SL4_RR4();
break;
// 0xE0...0xF5 keeps ws for each operator:
- case 0xE0:
+ case 0xe0:
operators[array][operatorOffset].update_5_WS3();
}
}
@@ -254,7 +257,7 @@ private void initChannels2op() {
// Channels 4, 5, 6 -> Operator offsets 0x8,0xB; 0x9,0xC; 0xA,0xD
channels2op[array][channelNumber + 3] = new Channel2Op(baseAddress + 3,
operators[array][channelNumber + 0x8],
- operators[array][channelNumber + 0xB]);
+ operators[array][channelNumber + 0xb]);
// Channels 7, 8, 9 -> Operators 0x10,0x13; 0x11,0x14; 0x12,0x15
channels2op[array][channelNumber + 6] = new Channel2Op(baseAddress + 6,
operators[array][channelNumber + 0x10],
@@ -273,7 +276,7 @@ private void initChannels4op() {
operators[array][channelNumber],
operators[array][channelNumber + 0x3],
operators[array][channelNumber + 0x8],
- operators[array][channelNumber + 0xB]);
+ operators[array][channelNumber + 0xb]);
}
}
@@ -318,7 +321,7 @@ private void update_DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1() {
setRhythmMode();
}
- int new_bd = (dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x10) >> 4;
+ int new_bd = (dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x10) >> 4;
if (new_bd != bd) {
bd = new_bd;
if (bd == 1) {
@@ -327,7 +330,7 @@ private void update_DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1() {
}
}
- int new_sd = (dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x08) >> 3;
+ int new_sd = (dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x08) >> 3;
if (new_sd != sd) {
sd = new_sd;
if (sd == 1) {
@@ -343,7 +346,7 @@ private void update_DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1() {
}
}
- int new_tc = (dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x02) >> 1;
+ int new_tc = (dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x02) >> 1;
if (new_tc != tc) {
tc = new_tc;
if (tc == 1) {
@@ -351,7 +354,7 @@ private void update_DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1() {
}
}
- int new_hh = dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x01;
+ int new_hh = dam1_dvb1_ryt1_bd1_sd1_tom1_tc1_hh1 & 0x01;
if (new_hh != hh) {
hh = new_hh;
if (hh == 1) {
@@ -457,12 +460,12 @@ void update_2_KON1_BLOCK3_FNUMH2() {
// Frequency Number (hi-register) and Block. These two registers, together with fnuml,
// sets the Channel´s base frequency;
- block = (_2_kon1_block3_fnumh2 & 0x1C) >> 2;
+ block = (_2_kon1_block3_fnumh2 & 0x1c) >> 2;
fNumH = _2_kon1_block3_fnumh2 & 0x03;
updateOperators();
// Key On. If changed, calls Channel.keyOn() / keyOff().
- int newKon = (_2_kon1_block3_fnumh2 & 0x20) >> 5;
+ int newKon = (_2_kon1_block3_fnumh2 & 0x20) >> 5;
if (newKon != kon) {
if (newKon == 1)
keyOn();
@@ -475,7 +478,7 @@ void update_2_KON1_BLOCK3_FNUMH2() {
void update_FNUML8() {
int fNumL8 = registers[channelBaseAddress+ChannelData.FNUML8_Offset];
// Frequency Number, low register.
- fNumL = fNumL8&0xFF;
+ fNumL = fNumL8 & 0xff;
updateOperators();
}
@@ -776,7 +779,7 @@ void update_AM1_VIB1_EGT1_KSR1_MULT4() {
ksr = (am1_vib1_egt1_ksr1_mult4 & 0x10) >> 4;
// Multiple. Multiplies the Channel.baseFrequency to get the Operator.operatorFrequency.
// This register is used in PhaseGenerator.setFrequency().
- mult = am1_vib1_egt1_ksr1_mult4 & 0x0F;
+ mult = am1_vib1_egt1_ksr1_mult4 & 0x0f;
phaseGenerator.setFrequency(f_number, block, mult);
envelopeGenerator.setActualAttackRate(ar, ksr, keyScaleNumber);
@@ -789,11 +792,11 @@ void update_KSL2_TL6() {
int ksl2_tl6 = registers[operatorBaseAddress+OperatorData.KSL2_TL6_Offset];
// Key Scale Level. Sets the attenuation in accordance with the octave.
- ksl = (ksl2_tl6 & 0xC0) >> 6;
+ ksl = (ksl2_tl6 & 0xc0) >> 6;
// Total Level. Sets the overall damping for the envelope.
- tl = ksl2_tl6 & 0x3F;
+ tl = ksl2_tl6 & 0x3f;
- envelopeGenerator.setAtennuation(f_number, block, ksl);
+ envelopeGenerator.setAttenuation(f_number, block, ksl);
envelopeGenerator.setTotalLevel(tl);
}
@@ -802,9 +805,9 @@ void update_AR4_DR4() {
int ar4_dr4 = registers[operatorBaseAddress+OperatorData.AR4_DR4_Offset];
// Attack Rate.
- ar = (ar4_dr4 & 0xF0) >> 4;
+ ar = (ar4_dr4 & 0xf0) >> 4;
// Decay Rate.
- dr = ar4_dr4 & 0x0F;
+ dr = ar4_dr4 & 0x0f;
envelopeGenerator.setActualAttackRate(ar, ksr, keyScaleNumber);
envelopeGenerator.setActualDecayRate(dr, ksr, keyScaleNumber);
@@ -815,9 +818,9 @@ void update_SL4_RR4() {
int sl4_rr4 = registers[operatorBaseAddress+OperatorData.SL4_RR4_Offset];
// Sustain Level.
- sl = (sl4_rr4 & 0xF0) >> 4;
+ sl = (sl4_rr4 & 0xf0) >> 4;
// Release Rate.
- rr = sl4_rr4 & 0x0F;
+ rr = sl4_rr4 & 0x0f;
envelopeGenerator.setActualSustainLevel(sl);
envelopeGenerator.setActualReleaseRate(rr, ksr, keyScaleNumber);
@@ -825,7 +828,7 @@ void update_SL4_RR4() {
void update_5_WS3() {
int _5_ws3 = registers[operatorBaseAddress+OperatorData._5_WS3_Offset];
- ws = _5_ws3 & 0x07;
+ ws = _5_ws3 & 0x07;
}
double getOperatorOutput(double modulator) {
@@ -928,18 +931,18 @@ void setActualSustainLevel(int sl) {
// The datasheet states that the SL formula is
// sustainLevel = -24*d7 -12*d6 -6*d5 -3*d4,
// translated as:
- sustainLevel = -3*sl;
+ sustainLevel = -3 * sl;
}
void setTotalLevel(int tl) {
// The datasheet states that the TL formula is
// TL = -(24*d5 + 12*d4 + 6*d3 + 3*d2 + 1.5*d1 + 0.75*d0),
// translated as:
- totalLevel = tl*-0.75;
+ totalLevel = tl * -0.75;
}
- void setAtennuation(int f_number, int block, int ksl) {
- int hi4bits = (f_number>>6)&0x0F;
+ void setAttenuation(int f_number, int block, int ksl) {
+ int hi4bits = (f_number >> 6) & 0x0F;
switch (ksl) {
case 0:
attenuation = 0;
@@ -964,7 +967,7 @@ void setActualAttackRate(int attackRate, int ksr, int keyScaleNumber) {
// per level.
//
// This method sets an attack increment and attack minimum value
- // that creates a exponential dB curve with 'period0to100' seconds in length
+ // that creates an exponential dB curve with 'period0to100' seconds in length
// and 'period10to90' seconds between 10% and 90% of the curve total level.
actualAttackRate = calculateActualRate(attackRate, ksr, keyScaleNumber);
double period0to100inSeconds = EnvelopeGeneratorData.attackTimeValuesTable[actualAttackRate][0] / 1000d;
@@ -987,7 +990,6 @@ void setActualAttackRate(int attackRate, int ksr, int keyScaleNumber) {
xMinimumInAttack = percentageToX(0.1) - (period0to100inSamples-period10to100inSamples)*xAttackIncrement;
}
-
void setActualDecayRate(int decayRate, int ksr, int keyScaleNumber) {
actualDecayRate = calculateActualRate(decayRate, ksr, keyScaleNumber);
double period10to90inSeconds = EnvelopeGeneratorData.decayAndReleaseTimeValuesTable[actualDecayRate][1] / 1000d;
@@ -1157,7 +1159,7 @@ void setFrequency(int fNumber, int block, int mult) {
// So the increment in each sample, to go from 0 to 1, is:
// increment = (1-0) / samples in the period ->
// increment = 1 / (OPL3Data.sampleRate/operatorFrequency) ->
- phaseIncrement = operatorFrequency/OPL3Data.sampleRate;
+ phaseIncrement = operatorFrequency / OPL3Data.sampleRate;
}
double getPhase(int vib) {
@@ -1184,8 +1186,8 @@ public String toString() {
/**
* Rhythm
*
- * The getOperatorOutput() method in TopCymbalOperator, HighHatOperator and SnareDrumOperator
- * were made through purely empyrical reverse engineering of the OPL3 output.
+ * The {@link Operator#getOperatorOutput(double)} method in {@link TopCymbalOperator}, {@link HighHatOperator}
+ * and {@link SnareDrumOperator} were made through purely empirical reverse engineering of the OPL3 output.
*/
private abstract class RhythmChannel extends Channel2Op {
@@ -1376,7 +1378,7 @@ private static class OPL3Data {
// OPL3-wide registers offsets:
static final int
_1_NTS1_6_Offset = 0x08,
- DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1_Offset = 0xBD,
+ DAM1_DVB1_RYT1_BD1_SD1_TOM1_TC1_HH1_Offset = 0xbd,
_7_NEW1_Offset = 0x105,
_2_CONNECTIONSEL6_Offset = 0x104;
@@ -1458,7 +1460,7 @@ private static void loadTremoloTable() {
calculateIncrement(tremoloDepth[1], 0, 1 / (2 * tremoloFrequency))
};
- int tremoloTableLength = (int)(sampleRate/tremoloFrequency);
+ int tremoloTableLength = (int) (sampleRate / tremoloFrequency);
// First array used when AM = 0 and second array used when AM = 1.
tremoloTable = new double[2][tremoloTableLength];
@@ -1493,9 +1495,9 @@ static double calculateIncrement(double begin, double end, double period) {
private static class ChannelData {
static final int
- _2_KON1_BLOCK3_FNUMH2_Offset = 0xB0,
- FNUML8_Offset = 0xA0,
- CHD1_CHC1_CHB1_CHA1_FB3_CNT1_Offset = 0xC0;
+ _2_KON1_BLOCK3_FNUMH2_Offset = 0xb0,
+ FNUML8_Offset = 0xa0,
+ CHD1_CHC1_CHB1_CHA1_FB3_CNT1_Offset = 0xc0;
// Feedback rate in fractions of 2*Pi, normalized to (0,1):
// 0, Pi/16, Pi/8, Pi/4, Pi/2, Pi, 2*Pi, 4*Pi turns to be:
@@ -1512,7 +1514,7 @@ private static class OperatorData {
KSL2_TL6_Offset = 0x40,
AR4_DR4_Offset = 0x60,
SL4_RR4_Offset = 0x80,
- _5_WS3_Offset = 0xE0;
+ _5_WS3_Offset = 0xe0;
enum Type {NO_MODULATION, CARRIER, FEEDBACK}
@@ -1549,7 +1551,7 @@ enum Type {NO_MODULATION, CARRIER, FEEDBACK}
}
private static void loadWaveforms() {
- //OPL3 has eight waveforms:
+ // OPL3 has eight waveforms:
waveforms = new double[8][waveLength];
int i;
diff --git a/src/main/java/vavi/sound/opl3/OldLucasFile.java b/src/main/java/vavi/sound/opl3/OldLucasFile.java
index 1b14ce6..030f0fc 100644
--- a/src/main/java/vavi/sound/opl3/OldLucasFile.java
+++ b/src/main/java/vavi/sound/opl3/OldLucasFile.java
@@ -8,13 +8,16 @@
import java.io.DataInputStream;
import java.io.IOException;
-import java.util.logging.Logger;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import vavi.sound.midi.opl3.Opl3Soundbank;
import vavi.sound.midi.opl3.Opl3Soundbank.Opl3Instrument;
import vavi.sound.midi.opl3.Opl3Synthesizer.Context;
import vavi.sound.opl3.MidPlayer.MidiTypeFile;
+import static java.lang.System.getLogger;
+
/**
* OldLucasFile.
@@ -24,7 +27,7 @@
*/
class OldLucasFile extends MidiTypeFile {
- private static final Logger logger = Logger.getLogger(OldLucasFile.class.getName());
+ private static final Logger logger = getLogger(OldLucasFile.class.getName());
@Override
int markSize() {
@@ -70,7 +73,7 @@ void rewind(int subSong, MidPlayer player) throws IOException {
this.instruments = new Opl3Instrument[this.tins];
for (int p = 0; p < v; ++p) {
-logger.fine(String.format("\n%d: ", p));
+logger.log(Level.DEBUG, "\n%d: ".formatted(p));
int[] ins = new int[16];
diff --git a/src/main/java/vavi/sound/opl3/Opl3Player.java b/src/main/java/vavi/sound/opl3/Opl3Player.java
index 537fde8..0ba42ae 100644
--- a/src/main/java/vavi/sound/opl3/Opl3Player.java
+++ b/src/main/java/vavi/sound/opl3/Opl3Player.java
@@ -22,16 +22,19 @@
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.Logger;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import vavi.sound.sampled.opl3.Opl3Encoding;
import vavi.sound.sampled.opl3.Opl3FileFormatType;
+import static java.lang.System.getLogger;
+
/**
* Player base class.
@@ -40,7 +43,7 @@
*/
public abstract class Opl3Player {
- private static final Logger logger = Logger.getLogger(Opl3Player.class.getName());
+ private static final Logger logger = getLogger(Opl3Player.class.getName());
/** generic properties */
protected Map props = new HashMap<>();
@@ -62,7 +65,7 @@ public enum FileType {
this.player = player;
}
public static Opl3Player getPlayer(AudioFormat.Encoding encoding) {
-logger.fine("encoding: " + encoding);
+logger.log(Level.DEBUG, "encoding: " + encoding);
return Arrays.stream(values()).filter(e -> e.encoding == encoding).findFirst().get().player;
}
/** @param ext lower case w/o '.' */
@@ -88,12 +91,13 @@ protected void write(int array, int address, int data) {
opl.write(array, address, data);
}
+ /** must implement mark/reset inside this method */
public abstract boolean matchFormat(InputStream is);
public abstract void load(InputStream is) throws IOException;
public byte[] read(int len) {
-//logger.warning("Enter in read method");
+//logger.log(Level.WARNING, "Enter in read method");
byte[] buf = new byte[len];
@@ -106,7 +110,7 @@ public byte[] read(int len) {
buf[i + 2] = (byte) (chB & 0xff);
buf[i + 3] = (byte) (chB >> 8 & 0xff);
}
-//logger.info("read: " + len);
+//logger.log(Level.TRACE, "read: " + len);
return buf;
}
@@ -121,6 +125,7 @@ public byte[] read(int len) {
public void setProperties(Map props) {
this.props.clear();
this.props.putAll(props);
+logger.log(Level.TRACE, "props: " + this.props);
}
public Map getProperties() {
diff --git a/src/main/java/vavi/sound/opl3/SierraFile.java b/src/main/java/vavi/sound/opl3/SierraFile.java
index e8b2941..e16d8a6 100644
--- a/src/main/java/vavi/sound/opl3/SierraFile.java
+++ b/src/main/java/vavi/sound/opl3/SierraFile.java
@@ -8,11 +8,22 @@
import java.io.DataInputStream;
import java.io.IOException;
-
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+
+import vavi.sound.midi.opl3.Opl3Soundbank;
import vavi.sound.midi.opl3.Opl3Soundbank.Opl3Instrument;
import vavi.sound.midi.opl3.Opl3Synthesizer.Context;
import vavi.sound.opl3.MidPlayer.MidiTypeFile;
+import static java.lang.System.getLogger;
+
/**
* SierraFile (SCI).
@@ -22,6 +33,11 @@
*/
class SierraFile extends MidiTypeFile {
+ private static final Logger logger = getLogger(SierraFile.class.getName());
+
+ /** for patch file location */
+ protected URI uri;
+
@Override
int markSize() {
return 3;
@@ -31,7 +47,78 @@ int markSize() {
boolean matchFormatImpl(DataInputStream dis) throws IOException {
return dis.readUnsignedByte() == 0x84 &&
dis.readUnsignedByte() == 0 &&
- dis.readUnsignedByte() != 0xf0;
+ dis.readUnsignedByte() != 0xf0; // not advanced sierra
+ }
+
+ /** convert byte buffer to int buffer for an instrument */
+ private static int[] fromSierra(int[] buf) {
+ int[] x = new int[11];
+ x[0] = buf[9] * 0x80 + buf[10] * 0x40 + buf[5] * 0x20 + buf[11] * 0x10 + buf[1];
+ x[1] = buf[22] * 0x80 + buf[23] * 0x40 + buf[18] * 0x20 + buf[24] * 0x10 + buf[14];
+ x[2] = (buf[0] << 6) + buf[8];
+ x[3] = (buf[13] << 6) + buf[21];
+ x[4] = (buf[3] << 4) + buf[6];
+ x[5] = (buf[16] << 4) + buf[19];
+ x[6] = (buf[4] << 4) + buf[7];
+ x[7] = (buf[17] << 4) + buf[20];
+ x[8] = buf[26];
+ x[9] = buf[27];
+ x[10] = (buf[2] << 1) + (1 - (buf[12] & 1));
+ return x;
+ }
+
+ /** load patch (.003) file */
+ protected void loadSierraIns(URI uri) throws IOException {
+
+ URL url;
+ if (uri.getPath().contains("..") || uri.getScheme() == null || "file".equals(uri.getScheme())) {
+ url = Path.of(uri.getPath()).toAbsolutePath().toUri().toURL();
+ } else {
+ url = uri.toURL();
+ }
+
+ String filename = URLDecoder.decode(url.toExternalForm(), StandardCharsets.UTF_8);
+ filename = filename.substring(filename.lastIndexOf('/') + 1);
+
+ String path = url.getFile();
+ String patchFileName = path.substring(0, path.lastIndexOf('/')) + '/' + filename.substring(0, 3) + "patch.003";
+ URL patchFileURL;
+ try {
+ patchFileURL = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), patchFileName, url.getQuery(), url.getRef()).toURL();
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+
+logger.log(Level.DEBUG, "patch: " + patchFileURL);
+ DataInputStream dis = new DataInputStream(patchFileURL.openStream());
+ dis.skipBytes(2);
+ stins = 0;
+
+ for (int j = 0; j < 2; ++j) {
+ for (int k = 0; k < 48; ++k) {
+ int p = j * 48 + k;
+logger.log(Level.TRACE, "%2d: ".formatted(p));
+
+ int[] buf = new int[28];
+
+ for (int i = 0; i < 28; ++i) {
+ buf[i] = dis.readUnsignedByte();
+ }
+
+ smyinsbank[p] = Opl3Soundbank.newInstrument(0, p, "sierra." + p, fromSierra(buf));
+logger.log(Level.TRACE, "instrument[" + p + "]: " + smyinsbank[p]);
+
+ ++stins;
+ }
+
+ dis.skipBytes(2);
+ }
+
+// TODO fill null for avoiding npe
+for (int i = 96; i < 128; i++) {
+ smyinsbank[i] = smyinsbank[0];
+}
+ dis.close();
}
protected final Opl3Instrument[] smyinsbank = new Opl3Instrument[128];
@@ -43,6 +130,10 @@ boolean matchFormatImpl(DataInputStream dis) throws IOException {
@Override
void rewind(int subSong, MidPlayer player) throws IOException {
+ this.uri = (URI) player.getProperties().get("uri");
+logger.log(Level.DEBUG, "uri: " + uri);
+ if (uri != null) loadSierraIns(uri);
+
player.tins = stins;
player.takeBE(3);
player.deltas = 32;
diff --git a/src/main/java/vavi/sound/opl3/readme.md b/src/main/java/vavi/sound/opl3/readme.md
index d4effc0..96b7daa 100644
--- a/src/main/java/vavi/sound/opl3/readme.md
+++ b/src/main/java/vavi/sound/opl3/readme.md
@@ -21,3 +21,4 @@
* https://github.com/scemino/NScumm.Audio
* 🚧🚫 maybe dual opl implementation is needed ... see [javamod](https://github.com/umjammer/javamod)
+ * vavi.sound.midi.opl3 and vavi.sound.opl3 are interdependence (Context, Opl3Instrument)
diff --git a/src/main/java/vavi/sound/pcm/equalizing/sse/Equalizer.java b/src/main/java/vavi/sound/pcm/equalizing/sse/Equalizer.java
index 4ffad17..50dd7ee 100644
--- a/src/main/java/vavi/sound/pcm/equalizing/sse/Equalizer.java
+++ b/src/main/java/vavi/sound/pcm/equalizing/sse/Equalizer.java
@@ -14,6 +14,8 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.RandomAccessFile;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -22,9 +24,10 @@
import java.util.Properties;
import vavi.io.LittleEndianDataOutputStream;
-import vavi.util.Debug;
import vavi.util.SplitRadixFft;
+import static java.lang.System.getLogger;
+
/**
* Shibatch Super Equalizer.
@@ -35,6 +38,8 @@
*/
class Equalizer {
+ private static final Logger logger = getLogger(Equalizer.class.getName());
+
/** */
static class Parameter implements Comparable {
/** */
@@ -286,19 +291,19 @@ static void process_param(double[] bc, List param, List pa
p.upper = i == bands.length ? fs : bands[i];
p.gain = bc[i];
param2.add(p);
-Debug.println("0: ch: " + ch + ": [" + i + "]: " + p);
+logger.log(Level.DEBUG, "0: ch: " + ch + ": [" + i + "]: " + p);
}
//
for (int i = 0; i < param.size(); i++) {
-//Debug.println("1: ch: " + ch + ": [" + i + "]");
+//logger.log(Level.TRACE, "1: ch: " + ch + ": [" + i + "]");
Parameter e = param.get(i);
if ((ch == 0 && !e.left) || (ch == 1 && !e.right)) {
-//Debug.println("ch " + ch + ": ignore: unmatched channel");
+//logger.log(Level.TRACE, "ch " + ch + ": ignore: unmatched channel");
continue;
}
if (e.lower >= e.upper) {
-Debug.println("ch " + ch + ": lower >= upper: " + e.lower + ", " + e.upper);
+logger.log(Level.DEBUG, "ch " + ch + ": lower >= upper: " + e.lower + ", " + e.upper);
continue;
}
@@ -306,7 +311,7 @@ static void process_param(double[] bc, List param, List pa
while (pi.hasNext()) {
p = pi.next();
if (p.upper > e.lower) {
-//Debug.println("ch " + ch + ": p.upper > e.lower: " + p.upper + ", " + e.lower);
+//logger.log(Level.TRACE, "ch " + ch + ": p.upper > e.lower: " + p.upper + ", " + e.lower);
break;
}
}
@@ -314,7 +319,7 @@ static void process_param(double[] bc, List param, List pa
while (pi.hasNext() && p.lower < e.upper) {
if (e.lower <= p.lower && p.upper <= e.upper) {
p.gain *= Math.pow(10, e.gain / 20);
-Debug.println("1.5.1: gain: " + p.gain);
+logger.log(Level.DEBUG, "1.5.1: gain: " + p.gain);
p = pi.next();
continue;
}
@@ -323,14 +328,14 @@ static void process_param(double[] bc, List param, List pa
e2.lower = e.upper;
e2.upper = p.upper;
e2.gain = p.gain;
-Debug.println("1.5.2: gain: " + p.gain);
+logger.log(Level.DEBUG, "1.5.2: gain: " + p.gain);
param2.add(i + 1, e2);
e2 = new Parameter();
e2.lower = e.lower;
e2.upper = e.upper;
e2.gain = p.gain * Math.pow(10, e.gain / 20);
-Debug.println("1.5.3: gain: " + p.gain);
+logger.log(Level.DEBUG, "1.5.3: gain: " + p.gain);
param2.add(i + 1, e2);
p.upper = e.lower;
@@ -345,7 +350,7 @@ static void process_param(double[] bc, List param, List pa
e2.lower = e.lower;
e2.upper = p.upper;
e2.gain = p.gain * Math.pow(10, e.gain / 20);
-Debug.println("1.5.4: gain: " + p.gain);
+logger.log(Level.DEBUG, "1.5.4: gain: " + p.gain);
param2.add(i + 1, e2);
p.upper = e.lower;
@@ -363,7 +368,7 @@ static void process_param(double[] bc, List param, List pa
p.upper = e.upper;
p.gain = p.gain * Math.pow(10, e.gain / 20);
-Debug.println("1.5.5: gain: " + p.gain);
+logger.log(Level.DEBUG, "1.5.5: gain: " + p.gain);
p = pi.next();
p = pi.next();
@@ -374,7 +379,7 @@ static void process_param(double[] bc, List param, List pa
}
int i = 0;
for (Parameter pp : param2) {
- Debug.println("2: ch: " + ch + ": [" + (i++) + "]: " + pp);
+ logger.log(Level.DEBUG, "2: ch: " + ch + ": [" + (i++) + "]: " + pp);
}
}
@@ -396,7 +401,7 @@ static void process_param2(double[] bc, List param, List p
p.upper = i == bands.length ? fs : bands[i];
p.gain = bc[i];
param2.add(p);
-Debug.println("0: ch: " + ch + ": [" + i + "]: " + p);
+logger.log(Level.DEBUG, "0: ch: " + ch + ": [" + i + "]: " + p);
}
//
@@ -409,7 +414,7 @@ static void process_param2(double[] bc, List param, List p
}
int i = 0;
for (Parameter pp : param2) {
- Debug.println("2: ch: " + ch + ": [" + (i++) + "]: " + pp);
+ logger.log(Level.DEBUG, "2: ch: " + ch + ": [" + (i++) + "]: " + pp);
}
}
@@ -524,7 +529,7 @@ int equ_modifySamples(byte[] buf, int nsamples, int nch, int bps) {
}
p = 0;
-//Debug.println("bps: " + bps);
+//logger.log(Level.TRACE, "bps: " + bps);
while (nbufsamples + nsamples >= winlen) {
switch (bps) {
case 8:
@@ -866,7 +871,7 @@ public static void main(String[] argv) throws Exception {
double lpreamp = lslpos[0] == 96 ? 0 : Math.pow(10, lslpos[0] / -20.0);
double rpreamp = rslpos[0] == 96 ? 0 : Math.pow(10, rslpos[0] / -20.0);
-Debug.println("---- init ----");
+logger.log(Level.DEBUG, "---- init ----");
for (int i = 0; i < 18; i++) {
//
Parameter param = new Parameter();
@@ -876,7 +881,7 @@ public static void main(String[] argv) throws Exception {
param.gain = lbands[i];
param.lower = bands[i];
param.upper = i == bands.length - 1 ? -1 : bands[i + 1];
-Debug.println(param);
+logger.log(Level.DEBUG, param);
params.add(param);
//
rbands[i] = rslpos[i + 1] == 96 ? 0 : rpreamp * Math.pow(10, rslpos[i + 1] / -20.0);
@@ -885,10 +890,10 @@ public static void main(String[] argv) throws Exception {
param.gain = rbands[i];
param.lower = bands[i];
param.upper = i == bands.length - 1 ? -1 : bands[i + 1];
-Debug.println(param);
+logger.log(Level.DEBUG, param);
params.add(param);
}
-Debug.println("---- init ----");
+logger.log(Level.DEBUG, "---- init ----");
//----
@@ -990,7 +995,6 @@ private static final class RAOutputStream extends OutputStream {
public RAOutputStream(RandomAccessFile raf) throws IOException {
this.raf = raf;
}
- /** */
@Override
public void write(int b) throws IOException {
raf.write(b);
diff --git a/src/main/java/vavi/sound/pcm/resampling/laoe/Resampler.java b/src/main/java/vavi/sound/pcm/resampling/laoe/Resampler.java
index a4a669a..faaf86f 100644
--- a/src/main/java/vavi/sound/pcm/resampling/laoe/Resampler.java
+++ b/src/main/java/vavi/sound/pcm/resampling/laoe/Resampler.java
@@ -18,7 +18,10 @@
package vavi.sound.pcm.resampling.laoe;
-import vavi.util.Debug;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+
+import static java.lang.System.getLogger;
/**
@@ -36,6 +39,8 @@
*/
public class Resampler {
+ private static final Logger logger = getLogger(Resampler.class.getName());
+
/**
*
sampleRateFactor = 1.0
*
order = 2
@@ -44,8 +49,8 @@ public Resampler() {
}
/**
- * @param inRate
- * @param outRate
+ * @param inRate input sample rate
+ * @param outRate out put sample rate
* @param order order of interpolate 0 ~ 3
*/
public Resampler(float inRate, float outRate, int order) {
@@ -186,7 +191,7 @@ private static int interpolate1(int[] data, double index) {
return (int) (data[ip % data.length] * (1 - fp) + data[(ip + 1) % data.length] * fp);
} catch (ArrayIndexOutOfBoundsException e) {
-Debug.println(e);
+logger.log(Level.INFO, e.getMessage(), e);
return 0;
}
}
@@ -203,7 +208,7 @@ private static int interpolate2(int[] data, double index) {
// Newton's 2nd order interpolation
int ip = (int) index;
double fp = index - ip;
-//System.err.printf("%f, %d\n", fp, ip);
+//logger.log(Level.TRACE, "%f, %d".formatted(fp, ip));
double d0 = data[ip % data.length];
double d1 = data[(ip + 1) % data.length];
double d2 = data[(ip + 2) % data.length];
@@ -215,7 +220,7 @@ private static int interpolate2(int[] data, double index) {
return (int) (a0 + a1 * fp + a2 * fp * (fp - 1));
} catch (ArrayIndexOutOfBoundsException e) {
-Debug.println(e);
+logger.log(Level.INFO, e.getMessage(), e);
return 0;
}
}
@@ -243,7 +248,7 @@ private static int interpolate3(int[] data, double index) {
return (int) ((((a * fp) + b) * fp + c) * fp + data[ip % data.length]);
} catch (ArrayIndexOutOfBoundsException e) {
-Debug.println(e);
+logger.log(Level.INFO, e.getMessage(), e);
return 0;
}
}
diff --git a/src/main/java/vavi/sound/pcm/resampling/rohm/Resampler.java b/src/main/java/vavi/sound/pcm/resampling/rohm/Resampler.java
index 21bd0bb..e44385c 100644
--- a/src/main/java/vavi/sound/pcm/resampling/rohm/Resampler.java
+++ b/src/main/java/vavi/sound/pcm/resampling/rohm/Resampler.java
@@ -44,7 +44,7 @@ int[] resample(int[] pbyPcmData) {
// number of samples after frequency conversion.
int nNewSampleNum = (int) (pbyPcmData.length * (nFreq / nSampleFreq));
-//Debug.println(nFreq + ", "+ nSampleFreq + ", " + pbyPcmData.length + ", " + nNewSampleNum);
+//logger.log(Level.TRACE, nFreq + ", "+ nSampleFreq + ", " + pbyPcmData.length + ", " + nNewSampleNum);
// memory allocation
int[] pbyNewPcm = new int[nNewSampleNum];
@@ -87,7 +87,7 @@ int[] resample(int[] pbyPcmData) {
// 16bit.
else {
-//Debug.println(nIndex1 + ", "+ nIndex2);
+//logger.log(Level.TRACE, nIndex1 + ", "+ nIndex2);
// values of index 1 and 2
int n1 = pbyPcmData[nIndex1];
int n2 = pbyPcmData[nIndex2];
diff --git a/src/main/java/vavi/sound/pcm/resampling/sox/Fifo.java b/src/main/java/vavi/sound/pcm/resampling/sox/Fifo.java
index 908887e..a5b35ca 100644
--- a/src/main/java/vavi/sound/pcm/resampling/sox/Fifo.java
+++ b/src/main/java/vavi/sound/pcm/resampling/sox/Fifo.java
@@ -18,7 +18,11 @@
package vavi.sound.pcm.resampling.sox;
-import vavi.util.Debug;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+
+import static java.lang.System.getLogger;
+
/**
* Addressable FIFO buffer.
@@ -28,6 +32,8 @@
*/
class Fifo {
+ private static final Logger logger = getLogger(Fifo.class.getName());
+
/** */
double[] data;
/** Number of bytes allocated for data. */
@@ -59,7 +65,7 @@ int reserve(int n) {
int p = end;
end += n;
-Debug.printf("fifo: length: %d, start: %d, end: %d, point: %d, n: %08x", allocation, begin, end, p, n);
+logger.log(Level.DEBUG, "fifo: length: %d, start: %d, end: %d, point: %d, n: %08x".formatted(allocation, begin, end, p, n));
return p;
}
if (begin > FIFO_MIN) {
diff --git a/src/main/java/vavi/sound/pcm/resampling/sox/PerfectResampler.java b/src/main/java/vavi/sound/pcm/resampling/sox/PerfectResampler.java
index 8ab878a..131a5b8 100644
--- a/src/main/java/vavi/sound/pcm/resampling/sox/PerfectResampler.java
+++ b/src/main/java/vavi/sound/pcm/resampling/sox/PerfectResampler.java
@@ -18,13 +18,15 @@
package vavi.sound.pcm.resampling.sox;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
-import java.util.logging.Level;
-import vavi.util.Debug;
import vavi.util.I0Bessel;
import vavi.util.SplitRadixFft;
+import static java.lang.System.getLogger;
+
/**
* change sample rate
@@ -37,6 +39,8 @@
*/
public class PerfectResampler {
+ private static final Logger logger = getLogger(PerfectResampler.class.getName());
+
/** */
private static void coef(double[] coef_p, int interp_order, int fir_len, int phase_num, int coef_interp_num, int fir_coef_num, double value) {
coef_p[(fir_len) * ((interp_order) + 1) * (phase_num) + ((interp_order) + 1) * (fir_coef_num) + (interp_order - coef_interp_num)] = value;
@@ -67,7 +71,7 @@ private static double[] prepare_coefs(double[] coefs, int num_coefs, int num_pha
double c = 0;
double d = 0; // = 0 to kill compiler warning
int pos = i * num_phases + j - 1;
-Debug.printf(Level.FINE, "coefs:%d, index:%d\n", coefs.length, pos - 1);
+logger.log(Level.DEBUG, "coefs:%d, index:%d\n".formatted(coefs.length, pos - 1));
fm1 = (pos > 0 ? coefs[pos - 1] : 0) * multiplier;
switch (interp_order) {
case 1:
@@ -220,7 +224,7 @@ private static int stage_read_p(Stage s) {
int outputP = output_fifo.reserve(f.dft_length);
output = output_fifo.data;
output_fifo.trim_by((f.dft_length + overlap) >> 1);
-//Debug.printf("%d, %d, %d, %d, %d\n", input.length, inputP, output.length, outputP, f.dft_length);
+//logger.log(Level.TRACE, "%d, %d, %d, %d, %d".formatted(input.length, inputP, output.length, outputP, f.dft_length));
System.arraycopy(input, inputP, output, outputP, Math.min(f.dft_length, input.length - inputP)); // TODO added min
double[] o = new double[f.dft_length];
@@ -229,7 +233,7 @@ private static int stage_read_p(Stage s) {
s.bit_rev_table = new int[dft_br_len(f.dft_length)];
s.sin_cos_table = new double[dft_sc_len(f.dft_length)];
}
-//Debug.printf("%d, %s\n", f.dft_length, s.bit_rev_table.length);
+//logger.log(Level.TRACE, "%d, %s".formatted(f.dft_length, s.bit_rev_table.length));
SplitRadixFft.rdft(f.dft_length, 1, o, s.bit_rev_table, s.sin_cos_table);
o[0] *= f.coefs[0];
@@ -278,7 +282,7 @@ private static int stage_read_p(Stage s) {
s.bit_rev_table = new int[dft_br_len(f.dft_length)];
s.sin_cos_table = new double[dft_sc_len(f.dft_length)];
}
-Debug.printf("%d, %s\n", f.dft_length, s.bit_rev_table);
+logger.log(Level.DEBUG, "%d, %s".formatted(f.dft_length, s.bit_rev_table));
SplitRadixFft.rdft(f.dft_length, 1, o, s.bit_rev_table, s.sin_cos_table);
o[0] *= f.coefs[0];
@@ -514,7 +518,7 @@ private static void half_band_filter_init(RateShared rateShared,
assert (num_taps[0] & 1) != 0;
f.num_taps = num_taps[0];
f.dft_length = dft_length;
-Debug.printf("fir_len=%d dft_length=%d Fp=%f atten=%f mult=%d\n", num_taps[0], dft_length, Fp, atten, multiplier);
+logger.log(Level.DEBUG, "fir_len=%d dft_length=%d Fp=%f atten=%f mult=%d".formatted(num_taps[0], dft_length, Fp, atten, multiplier));
if (rateShared.bit_rev_table == null) {
rateShared.bit_rev_table = new int[dft_br_len(dft_length)];
rateShared.sin_cos_table = new double[dft_sc_len(dft_length)];
@@ -668,11 +672,11 @@ public void exec(Stage p, Fifo output_fifo) {
int i;
int num_in = stage_occupancy(p);
int max_num_out = (int) (1 + num_in * p.out_in_ratio);
-Debug.printf("%d, %d, %.2f\n", num_in, max_num_out, p.out_in_ratio);
+logger.log(Level.DEBUG, "%d, %d, %.2f".formatted(num_in, max_num_out, p.out_in_ratio));
int outputP = output_fifo.reserve(max_num_out);
double[] output = output_fifo.data;
-//Debug.printf("%d, %d\n", output.length, outputP);
+//logger.log(Level.TRACE, "%d, %d".formatted(output.length, outputP));
for (i = 0; p.at.integer < num_in * p.divisor; ++i, p.at.integer += p.step.integer) {
int quot = p.at.integer / p.divisor;
int rem = p.at.integer % p.divisor;
@@ -1161,14 +1165,14 @@ private void rate_init(Rate rate,
}
rate.stages[rate.level + 1].step.all((long) (factor * Stage.MULT32 + .5));
rate.stages[rate.level + 1].out_in_ratio = Stage.MULT32 * divisor / rate.stages[rate.level + 1].step.all();
-Debug.printf("out_in_ratio: %.2f, divisor: %d, step.all: %d", rate.stages[rate.level + 1].out_in_ratio, divisor, rate.stages[rate.level + 1].step.all());
+logger.log(Level.DEBUG, "out_in_ratio: %.2f, divisor: %d, step.all: %d".formatted(rate.stages[rate.level + 1].out_in_ratio, divisor, rate.stages[rate.level + 1].step.all()));
if (divisor != 1) {
assert rate.stages[rate.level + 1].step.fraction == 0;
} else if (quality != Quality.Quick) {
assert rate.stages[rate.level + 1].step.integer == 0;
}
-Debug.printf("i/o=%f; %.9f:%d @ level %d\n", rate.factor, factor, divisor, rate.level);
+logger.log(Level.DEBUG, "i/o=%f; %.9f:%d @ level %d".formatted(rate.factor, factor, divisor, rate.level));
mult = 1 + (rate.upsample ? 1 : 0); // Compensate for zero-stuffing in double_sample
rate.input_stage_num = -(rate.upsample ? 1 : 0);
@@ -1202,7 +1206,7 @@ private void rate_init(Rate rate,
double[] coefs = design_lpf(f.pass, f.stop, 1., false, f.att, num_taps, phases);
assert num_taps[0] == f.num_coefs * phases - 1;
rate.stages[rate.level + 1].shared.poly_fir_coefs = prepare_coefs(coefs, f.num_coefs, phases, interp_order, mult);
-Debug.printf("fir_len=%d phases=%d coef_interp=%d mult=%d size=%d\n", f.num_coefs, phases, interp_order, mult, 0/*sigfigs3((num_taps[0] + 1) * (interp_order + 1) * 8)*/); // * 8 double
+logger.log(Level.DEBUG, "fir_len=%d phases=%d coef_interp=%d mult=%d size=%d".formatted(f.num_coefs, phases, interp_order, mult, 0/*sigfigs3((num_taps[0] + 1) * (interp_order + 1) * 8)*/)); // * 8 double
}
rate.stages[rate.level + 1].fn = f1.fn;
rate.stages[rate.level + 1].pre_post = f.num_coefs - 1;
@@ -1268,7 +1272,7 @@ private void rate_init(Rate rate,
int p = s.fifo.reserve(s.preload);
Arrays.fill(s.fifo.data, p, p + s.preload, 0);
if (i < rate.output_stage_num) {
-Debug.printf("stage=%-3dpre_post=%-3dpre=%-3dpreload=%d\n", i, s.pre_post, s.pre, s.preload);
+logger.log(Level.DEBUG, "stage=%-3dpre_post=%-3dpre=%-3dpreload=%d".formatted(i, s.pre_post, s.pre, s.preload));
}
}
}
@@ -1284,7 +1288,7 @@ private static void rate_process(Rate p) {
/** */
private static int rate_input(Rate p, double[] samples, int n) {
p.samples_in += n;
-//Debug.println("write: " + n);
+//logger.log(Level.TRACE, "write: " + n);
return p.stages[p.input_stage_num + 1].fifo.write(n, samples);
}
@@ -1380,7 +1384,7 @@ public void flow(int[] ibuf, int[] obuf, int[] isamp, int[] osamp) {
int[] odone = { osamp[0] };
int sP = rate_output(priv.rate, null, odone);
-Debug.println("odone: " + odone[0]);
+logger.log(Level.DEBUG, "odone: " + odone[0]);
double[] s = priv.rate.stages[priv.rate.output_stage_num + 1].fifo.data;
int obufP = 0;
for (i = 0; i < odone[0]; ++i) {
diff --git a/src/main/java/vavi/sound/pcm/resampling/sox/Polyphase.java b/src/main/java/vavi/sound/pcm/resampling/sox/Polyphase.java
index f50ff3d..9d56160 100644
--- a/src/main/java/vavi/sound/pcm/resampling/sox/Polyphase.java
+++ b/src/main/java/vavi/sound/pcm/resampling/sox/Polyphase.java
@@ -18,11 +18,12 @@
package vavi.sound.pcm.resampling.sox;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
import java.util.Random;
-import java.util.logging.Level;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -37,6 +38,8 @@
*/
public class Polyphase {
+ private static final Logger logger = getLogger(Polyphase.class.getName());
+
/** */
private static final double ISCALE = 0x10000;
/** */
@@ -111,13 +114,13 @@ private static int prime(int n, int[] q0) {
int p = 0; // primes
int q = 0; // q0
-Debug.printf(Level.FINE, "factors(%d) =", n);
+logger.log(Level.DEBUG, "factors(%d) =".formatted(n));
while (n > 1) {
while ((pr = primes[p]) != 0 && (n % pr) != 0) {
p++;
}
if (pr == 0) {
-Debug.printf(Level.FINE, "Number %d too large of a prime.", n);
+logger.log(Level.DEBUG, "Number %d too large of a prime.".formatted(n));
pr = n;
}
q0[q++] = pr;
@@ -125,7 +128,7 @@ private static int prime(int n, int[] q0) {
}
q0[q] = 0;
for (pr = 0; pr < q; pr++) {
-Debug.printf(Level.FINE, " %d", q0[pr]);
+logger.log(Level.DEBUG, " %d".formatted(q0[pr]));
}
return q;
}
@@ -152,7 +155,7 @@ private int permute(int[] m, int[] l, int ct, int ct1, int amalg) {
int tmp;
long j;
j = Math.abs(random.nextInt() % 32768L) + Math.abs((random.nextInt() % 32768L) << 13); // reasonably big
-//Debug.println("j: " + j);
+//logger.log(Level.TRACE, "j: " + j);
j = j % k; // non-negative!
k--;
if (j != k) {
@@ -207,9 +210,9 @@ private int optimize_factors(int numer, int denom, int[] l1, int[] l2) {
cost = 0;
f = denom;
u = Math.min(ct1, ct2) + 1;
-//Debug.printf(Level.FINE, "pfacts(%d): ", numer);
+//logger.log(Level.DEBUG, "pfacts(%d): ".formatted(numer)));
u1 = permute(m1, l1, ct1, u, amalg);
-//Debug.printf(Level.FINE, "pfacts(%d): ", denom);
+//logger.log(Level.DEBUG, "pfacts(%d): ".formatted(denom)));
u2 = permute(m2, l2, ct2, u, amalg);
u = Math.max(u1, u2);
for (j = 0; j < u; j++) {
@@ -305,12 +308,12 @@ private void fir_design(double[] buffer, int length, double cutoff) {
hamming(buffer, length); // Design Hamming window: 43 dB cutoff
}
-//Debug.printf(Level.FINE, "# fir_design length=%d, cutoff=%8.4f\n", length, cutoff);
+//logger.log(Level.DEBUG, "# fir_design length=%d, cutoff=%8.4f\n".formatted(length, cutoff)));
// Design filter: windowed sinc function
double sum = 0.0;
for (int j = 0; j < length; j++) {
buffer[j] *= sinc((Math.PI * cutoff * (j - length / 2f))); // center at length / 2
-//Debug.printf(Level.FINE, "%.1f %.6f\n", (double) j, buffer[j]);
+//logger.log(Level.DEBUG, "%.1f %.6f\n".formatted((double) j, buffer[j])));
sum += buffer[j];
}
sum = 1.0 / sum;
@@ -318,7 +321,7 @@ private void fir_design(double[] buffer, int length, double cutoff) {
for (int j = 0; j < length; j++) {
buffer[j] *= sum;
}
-//Debug.printf(Level.FINE, "# end\n\n");
+//logger.log(Level.DEBUG, .formatted("# end\n\n")));
}
// /** */
@@ -395,8 +398,8 @@ public Polyphase(float inrate, float outrate, int win_type, int win_width, float
work.total = total;
// l1 and l2 are now lists of the up/down factors for conversion
-Debug.printf("Poly: input rate %.1f, output rate %.1f. %d stages.\n", inrate, outrate, total);
-Debug.printf("Poly: window: %s size: %d cutoff: %.2f.\n", (win_type == 0) ? "nut" : "ham", win_width, cutoff);
+logger.log(Level.DEBUG, "Poly: input rate %.1f, output rate %.1f. %d stages.".formatted(inrate, outrate, total));
+logger.log(Level.DEBUG, "Poly: window: %s size: %d cutoff: %.2f.".formatted((win_type == 0) ? "nut" : "ham", win_width, cutoff));
// Create an array of filters and past history
float uprate = inrate;
@@ -417,12 +420,12 @@ public Polyphase(float inrate, float outrate, int win_type, int win_width, float
// s.size = size;
s.hsize = f_len / s.up; // this much of window is past-history
s.held = 0;
-Debug.printf("Poly: stage %d: Up by %d, down by %d, i_samps %d, hsize %d\n", k + 1, s.up, s.down, -1/* size */, s.hsize);
+logger.log(Level.DEBUG, "Poly: stage %d: Up by %d, down by %d, i_samps %d, hsize %d".formatted(k + 1, s.up, s.down, -1/* size */, s.hsize));
s.filt_len = f_len;
s.filt_array = new double[f_len];
// s.window = new double[s.hsize + size];
uprate *= s.up;
-Debug.printf("Poly: : filt_len %d, cutoff freq %.1f\n", f_len, uprate * cutoff / f_cutoff);
+logger.log(Level.DEBUG, "Poly: : filt_len %d, cutoff freq %.1f".formatted(f_len, uprate * cutoff / f_cutoff));
uprate /= s.down;
fir_design(s.filt_array, f_len, cutoff / f_cutoff);
// s.filt_array[f_len - 1] = 0;
@@ -445,7 +448,7 @@ public Polyphase(float inrate, float outrate, int win_type, int win_width, float
s.filt_array = null;
// s.window = new double[size];
}
-Debug.printf("Poly: output samples %d, oskip %d\n", -1 /* size */, work.oskip);
+logger.log(Level.DEBUG, "Poly: output samples %d, oskip %d".formatted(-1 /* size */, work.oskip));
}
/**
@@ -456,16 +459,16 @@ public Polyphase(float inrate, float outrate, int win_type, int win_width, float
*
*/
private static double st_prod(double[] q, int qP, int qstep, double[] p, int pP, int n) {
-//Debug.printf("qP: %d, qstep: %d, pP: %d, n: %d, (%d)\n", qP, qstep, pP, n, q.length);
+//logger.log(Level.TRACE, "qP: %d, qstep: %d, pP: %d, n: %d, (%d)".formatted(qP, qstep, pP, n, q.length));
double sum = 0;
int p0 = pP - n; // p
while (pP > p0) {
-//Debug.printf("p[%d]: %f, q[%d]: %f\n", pP, p[pP], qP, q[qP]);
+//logger.log(Level.TRACE, "p[%d]: %f, q[%d]: %f".formatted(pP, p[pP], qP, q[qP]));
sum += p[pP] * q[qP];
qP += qstep;
pP -= 1;
}
-//Debug.printf("sum: %f\n", sum);
+//logger.log(Level.TRACE, "sum: %f".formatted(sum));
return sum;
}
@@ -479,13 +482,13 @@ private static void polyphase(double[] output, int oP, PolyStage s) {
//for (mm = 0; mm < s.filt_len; mm++) { System.err.printf("cf_%d %f\n", mm, s.filt_array[mm]); }
// assumes s.size divisible by down (now true)
int o_top = (s.size * up) / down; // output
-//Debug.printf(" isize %d, osize %d, up %d, down %d, N %d", s.size, o_top-output, up, down, f_len);
+//logger.log(Level.TRACE, " isize %d, osize %d, up %d, down %d, N %d".formatted(s.size, o_top - output, up, down, f_len));
for (int mm = 0, o = 0; o < o_top; mm += down, o++) { // o: output pointer
int q = mm % up; // decimated coef pointer, s.filt_array
int p = in + (mm / up);
double sum = st_prod(s.filt_array, q, up, s.window, p, f_len / up);
output[oP + o] = sum * up;
-//Debug.printf("%f\n", output[oP + o]);
+//logger.log(Level.TRACE, "%f".formatted(output[oP + o]));
}
}
@@ -506,7 +509,7 @@ private static void update_hist(double[] hist, int hist_size, int in_size) {
/** TODO check */
private static int clipfloat(double sample) {
-//Debug.printf("%f\n", sample);
+//logger.log(Level.TRACE, "%f".formatted(sample));
if (sample > ST_SAMPLE_MAX) {
return ST_SAMPLE_MAX;
}
@@ -527,19 +530,19 @@ public int[] resample(int[] ibuf) {
f = 1;
}
size = f * work.outskip; // reasonable input block size
-Debug.println(Level.FINE, "size 0: " + size);
+logger.log(Level.DEBUG, "size 0: " + size);
}
for (j = 0; j < work.total; j++) {
PolyStage s = work.stage[j];
s.size = size;
s.window = new double[s.hsize + size];
size = (size * s.up) / s.down; // this is integer
-Debug.println(Level.FINE, "size [" + j + "]: " + size);
+logger.log(Level.DEBUG, "size [" + j + "]: " + size);
}
{
PolyStage s = work.stage[j];
s.size = size;
-Debug.println(Level.FINE, "size [" + j + "]: " + size);
+logger.log(Level.DEBUG, "size [" + j + "]: " + size);
s.window = new double[size];
}
@@ -551,7 +554,7 @@ public int[] resample(int[] ibuf) {
//----
// Sanity check: how much can we tolerate?
-//Debug.printf(Level.FINE, "isamp=%d osamp=%d\n", isamp[0], osamp[0]); System.err.flush();
+//logger.log(Level.TRACE, "isamp=%d osamp=%d".formatted(isamp[0], osamp[0]); System.err.flush()));
PolyStage s0 = work.stage[0]; // the first stage
PolyStage s1 = work.stage[work.total]; // the 'last' stage is output buffer
{
@@ -569,7 +572,7 @@ public int[] resample(int[] ibuf) {
work.inpipe += work.factor * in_size;
for (int k = 0; k < in_size; k++) {
//if (k < 300) {
-// Debug.printf(Level.FINE, "%d\n", ibuf[k]);
+// logger.log(Level.TRACE, "%d".formatted(ibuf[k]));
//}
s0.window[q++] = ibuf[k] / ISCALE;
}
@@ -589,10 +592,10 @@ public int[] resample(int[] ibuf) {
PolyStage s = work.stage[k];
int out = work.stage[k + 1].hsize; // rate.stage[k + 1].window
-//Debug.printf(Level.FINE, "stage: %d insize=%d\n", k + 1, s.window.length); System.err.flush();
+//logger.log(Level.TRACE, "stage: %d insize=%d".formatted(k + 1, s.window.length); System.err.flush());
//for (int l = 0; l < s.window.length; l++) {
// if (l < 300) {
-// Debug.printf(Level.FINE, "%f\n", s.window[l]);
+// logger.log(Level.TRACE, "%f".formatted(s.window[l]));
// }
//}
polyphase(work.stage[k + 1].window, out, s);
@@ -612,21 +615,21 @@ public int[] resample(int[] ibuf) {
int oskip = work.oskip;
int out_size = s1.held;
-//Debug.println(Level.FINE, "out_size 0: " + out_size);
+//logger.log(Level.TRACE, "out_size 0: " + out_size);
int out_buf = s1.hsize; // s1.window
if (ibuf == null && out_size > Math.ceil(work.inpipe)) {
out_size = (int) Math.ceil(work.inpipe);
-//Debug.println(Level.FINE, "out_size 1: " + out_size);
+//logger.log(Level.TRACE, "out_size 1: " + out_size);
}
if (out_size > oskip + osamp) {
out_size = oskip + osamp;
-//Debug.println(Level.FINE, "out_size 2: " + out_size);
+//logger.log(Level.TRACE, "out_size 2: " + out_size);
}
obuf = new int[out_size];
-Debug.println(Level.FINE, "out_size: " + out_size);
+logger.log(Level.DEBUG, "out_size: " + out_size);
for (q = 0, k = oskip; k < out_size; k++) {
obuf[q++] = clipfloat(s1.window[out_buf + k] * ISCALE); // should clip - limit
}
diff --git a/src/main/java/vavi/sound/pcm/resampling/sox/PolyphaseInputStream.java b/src/main/java/vavi/sound/pcm/resampling/sox/PolyphaseInputStream.java
index 81cfddc..9023f9a 100644
--- a/src/main/java/vavi/sound/pcm/resampling/sox/PolyphaseInputStream.java
+++ b/src/main/java/vavi/sound/pcm/resampling/sox/PolyphaseInputStream.java
@@ -11,11 +11,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import vavi.io.OutputEngine;
import vavi.io.OutputEngineInputStream;
import vavi.util.ByteUtil;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -26,6 +29,8 @@
*/
class PolyphaseInputStream extends FilterInputStream {
+ private static final Logger logger = getLogger(PolyphaseInputStream.class.getName());
+
/** */
public PolyphaseInputStream(InputStream is, float in, float out) throws IOException {
super(new OutputEngineInputStream(new PolyphaseOutputEngine(is, in, out)));
@@ -75,7 +80,7 @@ public void execute() throws IOException {
samples[i] = ByteUtil.readLeShort(sample, i * 2); // LE
}
int[] resamples = resampler.resample(samples); // TODO single channel ???
-Debug.println(r / 2 + ", " + resamples.length);
+logger.log(Level.DEBUG, r / 2 + ", " + resamples.length);
byte[] result = new byte[resamples.length * 2];
for (int i = 0; i < resamples.length; i++) {
ByteUtil.writeLeShort((short) resamples[i], result, i * 2); // LE
diff --git a/src/main/java/vavi/sound/pcm/resampling/sox/Resampler.java b/src/main/java/vavi/sound/pcm/resampling/sox/Resampler.java
index 5811613..4dbb06d 100644
--- a/src/main/java/vavi/sound/pcm/resampling/sox/Resampler.java
+++ b/src/main/java/vavi/sound/pcm/resampling/sox/Resampler.java
@@ -6,9 +6,10 @@
package vavi.sound.pcm.resampling.sox;
-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;
/**
@@ -51,6 +52,8 @@
*/
public class Resampler {
+ private static final Logger logger = getLogger(Resampler.class.getName());
+
private static final int LC = 7;
private static final int NC = 1 << LC;
private static final int LA = 16;
@@ -163,10 +166,10 @@ public Resampler(float inRate,
if (beta <= 2.0) {
this.beta = 0;
-Debug.println("Nuttall window, cutoff " + rollOff);
+logger.log(Level.DEBUG, "Nuttall window, cutoff " + rollOff);
} else {
this.beta = beta;
-Debug.println("Kaiser window, cutoff " + rollOff + ", beta " + beta);
+logger.log(Level.DEBUG, "Kaiser window, cutoff " + rollOff + ", beta " + beta);
}
if (inRate == outRate) {
@@ -174,7 +177,7 @@ public Resampler(float inRate,
}
work.factor = outRate / inRate;
-Debug.println("r.factor: " + work.factor);
+logger.log(Level.DEBUG, "r.factor: " + work.factor);
float gcdRate = getGcdRate(inRate, outRate);
work.inRate = inRate / gcdRate;
@@ -195,11 +198,11 @@ public Resampler(float inRate,
// returns error # <=0, or adjusted wing-len > 0
makeFilter(true);
-Debug.println("nMult: " + nMult + ", nWing: " + work.nWing + ", nq: " + work.nq);
+logger.log(Level.DEBUG, "nMult: " + nMult + ", nWing: " + work.nWing + ", nq: " + work.nq);
if (work.quadr < 0) { // exact coeff's method
work.xh = (int) (work.nWing / work.outRate);
-Debug.println("resample: rate ratio " + work.inRate + " : " + work.outRate + ", coeff interpolation not needed");
+logger.log(Level.DEBUG, "resample: rate ratio " + work.inRate + " : " + work.outRate + ", coeff interpolation not needed");
} else {
work.dhb = NP; // Fixed-point Filter sampling-time-increment
if (work.factor < 1.0) {
@@ -247,7 +250,7 @@ public int[] resample(int[] iBuf) {
int nOut;
// constrain amount we actually process
-Debug.println("xp: " + work.xp + ", xRead: " + work.xRead + ", iSamp: " + iBuf.length + ", xOff: " + work.xOff);
+logger.log(Level.DEBUG, "xp: " + work.xp + ", xRead: " + work.xRead + ", iSamp: " + iBuf.length + ", xOff: " + work.xOff);
int xSize = 2 * work.xOff + iBuf.length;
int ySize = (int) (iBuf.length * work.factor);
@@ -257,13 +260,13 @@ public int[] resample(int[] iBuf) {
//
int nProc = work.x.length - work.xp;
-Debug.println("nProc 1: " + nProc + ", xSize: " + work.x.length + ", ySize: " + work.y.length);
+logger.log(Level.DEBUG, "nProc 1: " + nProc + ", xSize: " + work.x.length + ", ySize: " + work.y.length);
int nx = nProc - work.xRead; // space for right-wing future-data
if (nx <= 0) {
throw new IllegalStateException("Can not handle this sample rate change. nx not positive: " + nx);
}
-Debug.println("nx " + nx + ", nProc: " + nProc);
+logger.log(Level.DEBUG, "nx " + nx + ", nProc: " + nProc);
int i;
if (iBuf.length == 0) {
@@ -286,7 +289,7 @@ public int[] resample(int[] iBuf) {
}
if (work.quadr < 0) { // exact coeff's method
nOut = srcEX(nProc);
-Debug.println("nProc " + nProc + " --> " + nOut);
+logger.log(Level.DEBUG, "nProc " + nProc + " --> " + nOut);
// Move converter nProc samples back in time
work.t -= (int) (nProc * work.outRate);
// Advance by number of samples processed
@@ -296,11 +299,11 @@ public int[] resample(int[] iBuf) {
if (creep != 0) {
work.t -= (int) (creep * work.outRate); // Remove time accumulation
work.xp += creep; // and add it to read pointer
-Debug.println("nProc " + nProc + ", creep " + creep);
+logger.log(Level.DEBUG, "nProc " + nProc + ", creep " + creep);
}
} else { // approx coeff's method
nOut = srcUD(nProc);
-Debug.println("nProc " + nProc + " --> " + nOut);
+logger.log(Level.DEBUG, "nProc " + nProc + " --> " + nOut);
// Move converter nProc samples back in time
work.time -= nProc;
// Advance by number of samples processed
@@ -310,13 +313,13 @@ public int[] resample(int[] iBuf) {
if (creep != 0) {
work.time -= creep; // Remove time accumulation
work.xp += creep; // and add it to read pointer
-Debug.println("nProc " + nProc + ", creep " + creep);
+logger.log(Level.DEBUG, "nProc " + nProc + ", creep " + creep);
}
}
// Copy back portion of input signal that must be re-used
int k = work.xp - work.xOff;
-Debug.println("k: " + k + ", last: " + last);
+logger.log(Level.DEBUG, "k: " + k + ", last: " + last);
for (i = 0; i < last - k; i++) {
work.x[i] = work.x[i + k];
}
@@ -347,11 +350,11 @@ public int[] resample(int[] iBuf) {
*/
public int[] drain() {
-//Debug.println("Xoff %d, Xt %d <--- DRAIN",this.Xoff, this.Xt);
+//logger.log(Level.TRACE, "Xoff %d, Xt %d <--- DRAIN".formatted(this.xOff, this.xt));
// stuff end with Xoff zeros
int[] oBuf = resample(new int[work.xOff]);
-Debug.println("DRAIN: " + work.xOff);
+logger.log(Level.DEBUG, "DRAIN: " + work.xOff);
return oBuf;
}
@@ -431,12 +434,12 @@ private int srcUD(int nx) {
// Output sampling period
// Step through input signal
double dt = 1.0f / work.factor;
-// Debug.println("factor %f, dt %f, ", factor, dt);
-// Debug.println("Time %f, ",this.Time);
+// logger.log(Level.DEBUG, "factor %f, dt %f, ", factor, dt));
+// logger.log(Level.DEBUG, "Time %f, ",this.Time));
// (Xh * dhb) >> La is max index into imp[]
-// Debug.println("ct=" + ct);
-// Debug.println("ct=" + (double) this.nWing * NA / this.dhb + " " + this.Xh);
-// Debug.println("ct=%ld, T=%.6f, dhb=%6f, dt=%.6f", this.Xh, time - Math.floor(time),(double) this.dhb / NA, dt);
+// logger.log(Level.DEBUG, "ct=" + ct));
+// logger.log(Level.DEBUG, "ct=" + (double) this.nWing * NA / this.dhb + " " + this.Xh));
+// logger.log(Level.DEBUG, "ct=%ld, T=%.6f, dhb=%6f, dt=%.6f", this.Xh, time - Math.floor(time),(double) this.dhb / NA, dt));
int y_pointer = 0;
int n = (int) Math.ceil(nx / dt);
while (n-- != 0) {
@@ -463,7 +466,7 @@ private int srcUD(int nx) {
time += dt; // Move to next sample by time increment
}
work.time = time;
-//Debug.println("time " + this.time);
+//logger.log(Level.TRACE, "time " + time);
return y_pointer; // Return the number of output samples
}
@@ -562,7 +565,7 @@ private void makeFilter(boolean normalize) {
dcGain += impR[i];
}
dcGain = 2 * dcGain + impR[0]; // DC gain of real coefficients
-Debug.printf(Level.FINER, "dCgain err=%.12f", dcGain - 1.0);
+logger.log(Level.TRACE, "dCgain err=%.12f".formatted(dcGain - 1.0));
dcGain = 1.0f / dcGain;
for (int i = 0; i < mWing; i++) {
diff --git a/src/main/java/vavi/sound/pcm/resampling/sox/ResamplerInputStream.java b/src/main/java/vavi/sound/pcm/resampling/sox/ResamplerInputStream.java
index fdc067b..7975512 100644
--- a/src/main/java/vavi/sound/pcm/resampling/sox/ResamplerInputStream.java
+++ b/src/main/java/vavi/sound/pcm/resampling/sox/ResamplerInputStream.java
@@ -11,11 +11,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import vavi.io.OutputEngine;
import vavi.io.OutputEngineInputStream;
import vavi.util.ByteUtil;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -26,6 +29,8 @@
*/
class ResamplerInputStream extends FilterInputStream {
+ private static final Logger logger = getLogger(ResamplerInputStream.class.getName());
+
/** */
public ResamplerInputStream(InputStream is, float in, float out) throws IOException {
super(new OutputEngineInputStream(new ResamplerOutputEngine(is, in, out)));
@@ -75,7 +80,7 @@ public void execute() throws IOException {
samples[i] = ByteUtil.readLeShort(sample, i * 2); // LE
}
int[] resamples = resampler.resample(samples); // TODO single channel ???
-Debug.println(r / 2 + ", " + resamples.length);
+logger.log(Level.DEBUG, r / 2 + ", " + resamples.length);
byte[] result = new byte[resamples.length * 2];
for (int i = 0; i < resamples.length; i++) {
ByteUtil.writeLeShort((short) resamples[i], result, i * 2); // LE
diff --git a/src/main/java/vavi/sound/sampled/bigclip/BigClip.java b/src/main/java/vavi/sound/sampled/bigclip/BigClip.java
new file mode 100644
index 0000000..6beb404
--- /dev/null
+++ b/src/main/java/vavi/sound/sampled/bigclip/BigClip.java
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2024 by Naohide Sano, All rights reserved.
+ *
+ * Programmed by Naohide Sano
+ */
+
+package vavi.sound.sampled.bigclip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.util.Arrays;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Clip;
+import javax.sound.sampled.Control;
+import javax.sound.sampled.Line;
+import javax.sound.sampled.LineEvent;
+import javax.sound.sampled.LineListener;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.SourceDataLine;
+import javax.sound.sampled.UnsupportedAudioFileException;
+
+import static java.lang.System.getLogger;
+
+
+/**
+ * Reformatted and adapted version of BigClip as posted to:
+ * http://stackoverflow.com/questions/9470148/how-do-you-play-a-long-audio-clip-in-java
+ *
+ * An implementation of the javax.sound.sampled.Clip that is designed to handle Clips of arbitrary
+ * size, limited only by the amount of memory available to the app. It uses the post 1.4 thread
+ * behaviour (daemon thread) that will stop the sound running after the main has exited.
+ *
2012-12-18 - Fixed bug with LOOP_CONTINUOUSLY and some bugs with drain() and buffer sizes.
+ *
2012-02-29 - Reworked play/loop to fix several bugs.
+ *
2009-09-01 - Fixed bug that had clip ..clipped at the end, by calling drain() (before calling
+ * stop()) on the dataline after the play loop was complete. Improvement to frame and microsecond
+ * position determination.
+ *
2009-08-17 - added convenience constructor that accepts a Clip. Changed the private
+ * convertFrameToM..seconds methods from 'micro' to 'milli' to reflect that they were dealing with
+ * units of 1000/th of a second.
+ *
2009-08-14 - got rid of flush() after the sound loop, as it was cutting off tracks just
+ * before the end, and was found to be not needed for the fast-forward/rewind functionality it was
+ * introduced to support.
+ *
2009-08-11 - First binary release.
N.B. Remove @Override notation and logging to use in
+ * 1.3+
+ *
+ * TODO spi, volume
+ *
+ * @author Andrew Thompson
+ * @author Alejandro Garcia
+ * @author Michael Thomas
+ * @version 2012-12-18
+ * @since 1.5
+ */
+class BigClip implements Clip, LineListener {
+
+ private static final Logger logger = getLogger(BigClip.class.getName());
+
+ /** The DataLine used by this Clip. */
+ private SourceDataLine dataLine;
+
+ /** The raw bytes of the audio data. */
+ private byte[] audioData;
+
+ /** The stream wrapper for the audioData. */
+ private ByteArrayInputStream inputStream;
+
+ /** Loop count set by the calling code. */
+ private int loopCount = 1;
+ /** Internal count of how many loops to go. */
+ private int countDown = 1;
+ /** The start of a loop point. Defaults to 0. */
+ private int loopPointStart;
+ /** The end of a loop point. Defaults to the end of the Clip. */
+ private int loopPointEnd;
+
+ /** Stores the current frame position of the clip. */
+ private int framePosition;
+
+ /** Thread used to run() sound. */
+ private Thread thread;
+ /** Whether the sound is currently playing or active. */
+ private boolean active;
+ /** Stores the last time bytes were dumped to the audio stream. */
+ private long timeLastPositionSet;
+
+ private static final int bufferUpdateFactor = 2;
+
+ /**
+ * Default constructor for a BigClip. Does nothing. Information from the AudioInputStream passed
+ * in open() will be used to get an appropriate SourceDataLine.
+ */
+ public BigClip() {
+ }
+
+ /**
+ * There are a number of AudioSystem methods that will return a configured Clip. This
+ * convenience constructor allows us to obtain a SourceDataLine for the BigClip that uses the
+ * same AudioFormat as the original Clip.
+ *
+ * @param clip Clip The Clip used to configure the BigClip.
+ */
+ public BigClip(Clip clip) throws LineUnavailableException {
+ dataLine = AudioSystem.getSourceDataLine(clip.getFormat());
+ }
+
+ /**
+ * Provides the entire audio buffer of this clip.
+ *
+ * @return audioData byte[] The bytes of the audio data that is loaded in this Clip.
+ */
+ public byte[] getAudioData() {
+ return audioData;
+ }
+
+ /** Converts a frame count to a duration in milliseconds. */
+ private long convertFramesToMilliseconds(int frames) {
+ return (frames / (long) dataLine.getFormat().getSampleRate()) * 1000;
+ }
+
+ /** Converts a duration in milliseconds to a frame count. */
+ private int convertMillisecondsToFrames(long milliseconds) {
+ return (int) (milliseconds / dataLine.getFormat().getSampleRate());
+ }
+
+ @Override
+ public void update(LineEvent le) {
+ logger.log(Level.TRACE, "update: " + le);
+ }
+
+ @Override
+ public void loop(int count) {
+ logger.log(Level.TRACE, "loop(" + count + ") - framePosition: " + framePosition);
+ loopCount = count;
+ countDown = count;
+ active = true;
+ inputStream.reset();
+
+ start();
+ }
+
+ @Override
+ public void setLoopPoints(int start, int end) {
+ if (start < 0 || start > audioData.length - 1 || end < 0 || end > audioData.length) {
+ throw new IllegalArgumentException("Loop points '" + start + "' and '" + end
+ + "' cannot be set for buffer of size " + audioData.length);
+ }
+ if (start > end) {
+ throw new IllegalArgumentException("End position " + end + " preceeds start position "
+ + start);
+ }
+
+ loopPointStart = start;
+ framePosition = loopPointStart;
+ loopPointEnd = end;
+ }
+
+ @Override
+ public void setMicrosecondPosition(long milliseconds) {
+ framePosition = convertMillisecondsToFrames(milliseconds);
+ }
+
+ @Override
+ public long getMicrosecondPosition() {
+ return convertFramesToMilliseconds(getFramePosition());
+ }
+
+ @Override
+ public long getMicrosecondLength() {
+ return convertFramesToMilliseconds(getFrameLength());
+ }
+
+ @Override
+ public void setFramePosition(int frames) {
+ framePosition = frames;
+ int offset = framePosition * format.getFrameSize();
+ try {
+ inputStream.reset();
+ inputStream.read(new byte[offset]);
+ } catch (Exception e) {
+ logger.log(Level.ERROR, e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public int getFramePosition() {
+ long timeSinceLastPositionSet = System.currentTimeMillis() - timeLastPositionSet;
+ int size = dataLine.getBufferSize() * (format.getChannels() / 2) / bufferUpdateFactor;
+
+ // Step down to the next whole frame.
+ size /= dataLine.getFormat().getFrameSize();
+ size *= dataLine.getFormat().getFrameSize();
+
+ int framesSinceLast =
+ (int) ((timeSinceLastPositionSet / 1000f) * dataLine.getFormat().getFrameRate());
+ int framesRemainingTillTime = size - framesSinceLast;
+ return framePosition - framesRemainingTillTime;
+ }
+
+ @Override
+ public int getFrameLength() {
+ return audioData.length / format.getFrameSize();
+ }
+
+ AudioFormat format;
+
+ @Override
+ public void open(AudioInputStream stream)
+ throws IOException, LineUnavailableException {
+
+ AudioInputStream is1;
+ format = stream.getFormat();
+
+ if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
+ is1 = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, stream);
+ } else {
+ is1 = stream;
+ }
+ format = is1.getFormat();
+ InputStream is2 = is1;
+
+ byte[] buf = new byte[1 << 16];
+ int numRead = 0;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ numRead = is2.read(buf);
+ while (numRead > -1) {
+ baos.write(buf, 0, numRead);
+ numRead = is2.read(buf, 0, buf.length);
+ }
+ is2.close();
+ audioData = baos.toByteArray();
+ AudioFormat afTemp;
+ if (format.getChannels() < 2) {
+ int frameSize = format.getSampleSizeInBits() * 2 / 8;
+ afTemp = new AudioFormat(format.getEncoding(), format.getSampleRate(),
+ format.getSampleSizeInBits(), 2, frameSize,
+ format.getFrameRate(), format.isBigEndian());
+ } else {
+ afTemp = format;
+ }
+
+ setLoopPoints(0, audioData.length);
+ dataLine = AudioSystem.getSourceDataLine(afTemp);
+ dataLine.open();
+ inputStream = new ByteArrayInputStream(audioData);
+ }
+
+ @Override
+ public void open(AudioFormat format, byte[] data, int offset, int bufferSize) throws LineUnavailableException {
+ byte[] input = new byte[bufferSize];
+ System.arraycopy(data, offset, input, 0, input.length);
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+ try {
+ AudioInputStream ais1 = AudioSystem.getAudioInputStream(inputStream);
+ AudioInputStream ais2 = AudioSystem.getAudioInputStream(format, ais1);
+ open(ais2);
+ } catch (UnsupportedAudioFileException | IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ // TODO - throw IAE for invalid frame size, format.
+ }
+
+ @Override
+ public float getLevel() {
+ return dataLine.getLevel();
+ }
+
+ @Override
+ public long getLongFramePosition() {
+ return dataLine.getLongFramePosition() * 2 / format.getChannels();
+ }
+
+ @Override
+ public int available() {
+ return dataLine.available();
+ }
+
+ @Override
+ public int getBufferSize() {
+ return dataLine.getBufferSize();
+ }
+
+ @Override
+ public AudioFormat getFormat() {
+ return format;
+ }
+
+ @Override
+ public boolean isActive() {
+ return dataLine.isActive();
+ }
+
+ @Override
+ public boolean isRunning() {
+ return dataLine.isRunning();
+ }
+
+ @Override
+ public boolean isOpen() {
+ return dataLine.isOpen();
+ }
+
+ @Override
+ public void stop() {
+ logger.log(Level.TRACE, "BigClip.stop()");
+ active = false;
+ // why did I have this commented out?
+ dataLine.stop();
+ if (thread != null) {
+ try {
+ active = false;
+ thread.join();
+ } catch (InterruptedException ignored) {
+ }
+ }
+ }
+
+ public byte[] convertMonoToStereo(byte[] data, int bytesRead) {
+ byte[] tempData = new byte[bytesRead * 2];
+ if (format.getSampleSizeInBits() == 8) {
+ for (int ii = 0; ii < bytesRead; ii++) {
+ byte b = data[ii];
+ tempData[ii * 2] = b;
+ tempData[ii * 2 + 1] = b;
+ }
+ } else {
+ for (int ii = 0; ii < bytesRead - 1; ii += 2) {
+ byte b1 = data[ii];
+ byte b2 = data[ii + 1];
+ tempData[ii * 2] = b1;
+ tempData[ii * 2 + 1] = b2;
+ tempData[ii * 2 + 2] = b1;
+ tempData[ii * 2 + 3] = b2;
+ }
+ }
+ return tempData;
+ }
+
+ @Override
+ public void start() {
+ Runnable r = () -> {
+ dataLine.start();
+
+ active = true;
+
+ int bytesRead = 0;
+ int frameSize = dataLine.getFormat().getFrameSize();
+ int bufSize = dataLine.getBufferSize();
+ boolean startOrMove = true;
+ byte[] data = new byte[bufSize];
+ int offset = framePosition * frameSize;
+ bytesRead = inputStream.read(new byte[offset], 0, offset);
+ logger.log(Level.TRACE, "bytesRead " + bytesRead);
+ bytesRead += inputStream.read(data, 0, data.length);
+
+ logger.log(Level.TRACE, "loopCount " + loopCount);
+ logger.log(Level.TRACE, "countDown " + countDown);
+ logger.log(Level.TRACE, "bytesRead " + bytesRead);
+
+ while (bytesRead != -1 && (loopCount == Clip.LOOP_CONTINUOUSLY || countDown > 0) && active) {
+ logger.log(Level.TRACE, "BigClip.start() loop " + framePosition);
+ int framesRead;
+ byte[] tempData;
+ if (format.getChannels() < 2) {
+ tempData = convertMonoToStereo(data, bytesRead);
+ framesRead = bytesRead / format.getFrameSize();
+ bytesRead *= 2;
+ } else {
+ framesRead = bytesRead / dataLine.getFormat().getFrameSize();
+ tempData = Arrays.copyOfRange(data, 0, bytesRead);
+ }
+
+ framePosition += framesRead;
+ if (framePosition >= loopPointEnd) {
+ framePosition = loopPointStart;
+ inputStream.reset();
+ countDown--;
+ logger.log(Level.TRACE, "Loop Count: " + countDown);
+ }
+ timeLastPositionSet = System.currentTimeMillis();
+
+ byte[] newData = tempData;
+ dataLine.write(newData, 0, newData.length);
+ if (startOrMove) {
+ int len = bufSize / bufferUpdateFactor;
+
+ // Step down to the next whole frame.
+ len /= frameSize;
+ len *= frameSize;
+
+ data = new byte[len];
+ startOrMove = false;
+ }
+
+ bytesRead = inputStream.read(data, 0, data.length);
+ if (bytesRead < 0 && (--countDown > 0 || loopCount == Clip.LOOP_CONTINUOUSLY)) {
+ inputStream.read(new byte[offset], 0, offset);
+ logger.log(Level.TRACE, "loopCount " + loopCount);
+ logger.log(Level.TRACE, "countDown " + countDown);
+ inputStream.reset();
+ bytesRead = inputStream.read(data, 0, data.length);
+ }
+ }
+
+ logger.log(Level.TRACE, "BigClip.start() loop ENDED" + framePosition);
+ active = false;
+ countDown = 1;
+ framePosition = 0;
+ inputStream.reset();
+ dataLine.stop();
+
+ };
+ thread = new Thread(r);
+ // makes thread behaviour compatible with JavaSound post 1.4
+ thread.setDaemon(true);
+ thread.start();
+ }
+
+ @Override
+ public void flush() {
+ dataLine.flush();
+ }
+
+ @Override
+ public void drain() {
+ dataLine.drain();
+ }
+
+ @Override
+ public void removeLineListener(LineListener listener) {
+ dataLine.removeLineListener(listener);
+ }
+
+ @Override
+ public void addLineListener(LineListener listener) {
+ dataLine.addLineListener(listener);
+ }
+
+ @Override
+ public Control getControl(Control.Type control) {
+ return dataLine.getControl(control);
+ }
+
+ @Override
+ public Control[] getControls() {
+ if (dataLine == null) {
+ return new Control[0];
+ } else {
+ return dataLine.getControls();
+ }
+ }
+
+ @Override
+ public boolean isControlSupported(Control.Type control) {
+ return dataLine.isControlSupported(control);
+ }
+
+ @Override
+ public void close() {
+ dataLine.close();
+ }
+
+ @Override
+ public void open() throws LineUnavailableException {
+ throw new IllegalArgumentException("illegal call to open() in interface Clip");
+ }
+
+ @Override
+ public Line.Info getLineInfo() {
+ return dataLine.getLineInfo();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/vavi/sound/sampled/ilbc/Ilbc2PcmAudioInputStream.java b/src/main/java/vavi/sound/sampled/ilbc/Ilbc2PcmAudioInputStream.java
index fed3e3b..877cf68 100644
--- a/src/main/java/vavi/sound/sampled/ilbc/Ilbc2PcmAudioInputStream.java
+++ b/src/main/java/vavi/sound/sampled/ilbc/Ilbc2PcmAudioInputStream.java
@@ -10,14 +10,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.logging.Level;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import vavi.io.OutputEngine;
import vavi.io.OutputEngineInputStream;
import vavi.sound.ilbc.Decoder;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -28,6 +30,8 @@
*/
class Ilbc2PcmAudioInputStream extends AudioInputStream {
+ private static final Logger logger = getLogger(Ilbc2PcmAudioInputStream.class.getName());
+
/**
* Constructor.
*
@@ -55,7 +59,7 @@ private static class IlbcOutputEngine implements OutputEngine {
public IlbcOutputEngine(InputStream is) throws IOException {
this.is = is;
decoder = new Decoder(30, 1); // TODO parameter x2
-Debug.println(Level.FINE, "iLBC");
+logger.log(Level.DEBUG, "iLBC");
decoded = new byte[decoder.getDecodedLength()];
buf = new byte[decoder.getEncodedLength()];
}
diff --git a/src/main/java/vavi/sound/sampled/ilbc/IlbcEncoding.java b/src/main/java/vavi/sound/sampled/ilbc/IlbcEncoding.java
index bd842c9..751b7f1 100644
--- a/src/main/java/vavi/sound/sampled/ilbc/IlbcEncoding.java
+++ b/src/main/java/vavi/sound/sampled/ilbc/IlbcEncoding.java
@@ -26,7 +26,7 @@ public class IlbcEncoding extends AudioFormat.Encoding {
*
* @param name Name of the iLBC encoding.
*/
- public IlbcEncoding(String name) {
+ private IlbcEncoding(String name) {
super(name);
}
}
diff --git a/src/main/java/vavi/sound/sampled/ldclep/LdCelp2PcmAudioInputStream.java b/src/main/java/vavi/sound/sampled/ldclep/LdCelp2PcmAudioInputStream.java
index ab559fd..5a4d28b 100644
--- a/src/main/java/vavi/sound/sampled/ldclep/LdCelp2PcmAudioInputStream.java
+++ b/src/main/java/vavi/sound/sampled/ldclep/LdCelp2PcmAudioInputStream.java
@@ -10,17 +10,19 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
-import java.util.logging.Level;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import vavi.io.OutputEngine;
import vavi.io.OutputEngineInputStream;
import vavi.sound.ldcelp.Decoder;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -31,6 +33,8 @@
*/
class LdCelp2PcmAudioInputStream extends AudioInputStream {
+ private static final Logger logger = getLogger(LdCelp2PcmAudioInputStream.class.getName());
+
/**
* Constructor.
*
@@ -58,7 +62,7 @@ private static class LdCelpOutputEngine implements OutputEngine {
public LdCelpOutputEngine(InputStream is) throws IOException {
this.is = is;
decoder = new Decoder(true); // TODO parameter postfilter
-Debug.println(Level.FINE, "LD-CELP");
+logger.log(Level.DEBUG, "LD-CELP");
}
@Override
diff --git a/src/main/java/vavi/sound/sampled/ldclep/LdCelpEncoding.java b/src/main/java/vavi/sound/sampled/ldclep/LdCelpEncoding.java
index 7e3b0d7..07dc035 100644
--- a/src/main/java/vavi/sound/sampled/ldclep/LdCelpEncoding.java
+++ b/src/main/java/vavi/sound/sampled/ldclep/LdCelpEncoding.java
@@ -26,7 +26,7 @@ public class LdCelpEncoding extends AudioFormat.Encoding {
*
* @param name Name of the LD-CELP encoding.
*/
- public LdCelpEncoding(String name) {
+ private LdCelpEncoding(String name) {
super(name);
}
}
diff --git a/src/main/java/vavi/sound/sampled/opl3/Opl3AudioFileReader.java b/src/main/java/vavi/sound/sampled/opl3/Opl3AudioFileReader.java
index 5b9e2df..fd444d6 100644
--- a/src/main/java/vavi/sound/sampled/opl3/Opl3AudioFileReader.java
+++ b/src/main/java/vavi/sound/sampled/opl3/Opl3AudioFileReader.java
@@ -10,23 +10,26 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.Level;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.spi.AudioFileReader;
+import vavi.sound.SoundUtil;
import vavi.sound.opl3.Opl3Player.FileType;
-import vavi.util.Debug;
+import static java.lang.System.Logger.Level.DEBUG;
+import static java.lang.System.Logger.Level.TRACE;
+import static java.lang.System.getLogger;
+import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
import static vavi.sound.opl3.Opl3Player.opl3;
@@ -40,30 +43,32 @@
*/
public class Opl3AudioFileReader extends AudioFileReader {
- private URI uri;
+ private static final Logger logger = getLogger(Opl3AudioFileReader.class.getName());
@Override
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException {
- try (InputStream inputStream = Files.newInputStream(file.toPath())) {
- uri = file.toURI();
- return getAudioFileFormat(inputStream, (int) file.length());
+ try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
+ URI uri = file.toURI();
+ return getAudioFileFormat(inputStream, (int) file.length(), uri);
}
}
@Override
public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException {
- try (InputStream inputStream = url.openStream()) {
+ try (InputStream inputStream = new BufferedInputStream(url.openStream())) {
+ URI uri = null;
try {
uri = url.toURI();
} catch (URISyntaxException ignore) {
}
- return getAudioFileFormat(inputStream);
+ return getAudioFileFormat(inputStream, NOT_SPECIFIED, uri);
}
}
@Override
public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
- return getAudioFileFormat(stream, AudioSystem.NOT_SPECIFIED);
+ URI uri = SoundUtil.getSource(stream);
+ return getAudioFileFormat(stream, NOT_SPECIFIED, uri);
}
/**
@@ -73,33 +78,36 @@ public AudioFileFormat getAudioFileFormat(InputStream stream) throws Unsupported
* @param mediaLength unused
* @return an AudioInputStream object based on the audio file data contained
* in the input stream.
+ * @param uri for advanced sierra file
* @throws UnsupportedAudioFileException if the File does not point to a
* valid audio file data recognized by the system.
* @throws IOException if an I/O exception occurs.
*/
- protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLength) throws UnsupportedAudioFileException, IOException {
-Debug.println(Level.FINE, "enter: available: " + bitStream.available());
+ protected static AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLength, URI uri) throws UnsupportedAudioFileException, IOException {
+logger.log(DEBUG, "enter: available: " + bitStream.available());
AudioFormat.Encoding encoding;
try {
encoding = FileType.getEncoding(bitStream);
} catch (Exception e) {
-Debug.println(Level.FINER, "error exit: available: " + bitStream.available());
-Debug.printStackTrace(Level.FINEST, e);
+logger.log(DEBUG, "error exit: available: " + bitStream.available());
+logger.log(TRACE, e.getMessage(), e);
throw (UnsupportedAudioFileException) new UnsupportedAudioFileException().initCause(e);
}
AudioFileFormat.Type type = FileType.getType(encoding);
Map props = new HashMap<>();
+logger.log(TRACE, "uri: " + uri);
props.put("uri", uri); // for advanced sierra file
// specification for around frame might cause AudioInputStream modification at below (*1)
- AudioFormat format = new AudioFormat(encoding, opl3.getSampleRate(), AudioSystem.NOT_SPECIFIED, opl3.getChannels(), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, opl3.isBigEndian(), props);
- return new AudioFileFormat(type, format, AudioSystem.NOT_SPECIFIED);
+ AudioFormat format = new AudioFormat(encoding, opl3.getSampleRate(), NOT_SPECIFIED, opl3.getChannels(), NOT_SPECIFIED, NOT_SPECIFIED, opl3.isBigEndian(), props);
+ return new AudioFileFormat(type, format, NOT_SPECIFIED);
}
@Override
public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException {
InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()));
try {
- return getAudioInputStream(inputStream, (int) file.length());
+ URI uri = file.toURI();
+ return getAudioInputStream(inputStream, (int) file.length(), uri);
} catch (UnsupportedAudioFileException | IOException e) {
inputStream.close();
throw e;
@@ -110,7 +118,12 @@ public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFi
public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException {
InputStream inputStream = new BufferedInputStream(url.openStream());
try {
- return getAudioInputStream(inputStream);
+ URI uri = null;
+ try {
+ uri = url.toURI();
+ } catch (URISyntaxException ignore) {
+ }
+ return getAudioInputStream(inputStream, NOT_SPECIFIED, uri);
} catch (UnsupportedAudioFileException | IOException e) {
inputStream.close();
throw e;
@@ -119,7 +132,8 @@ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFile
@Override
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException {
- return getAudioInputStream(stream, AudioSystem.NOT_SPECIFIED);
+ URI uri = SoundUtil.getSource(stream);
+ return getAudioInputStream(stream, NOT_SPECIFIED, uri);
}
/**
@@ -131,12 +145,13 @@ public AudioInputStream getAudioInputStream(InputStream stream) throws Unsupport
* @param mediaLength unused
* @return an AudioInputStream object based on the audio file data contained
* in the input stream.
+ * @param uri for advanced sierra file
* @throws UnsupportedAudioFileException if the File does not point to a
* valid audio file data recognized by the system.
* @throws IOException if an I/O exception occurs.
*/
- protected AudioInputStream getAudioInputStream(InputStream inputStream, int mediaLength) throws UnsupportedAudioFileException, IOException {
- AudioFileFormat audioFileFormat = getAudioFileFormat(inputStream, mediaLength);
+ protected static AudioInputStream getAudioInputStream(InputStream inputStream, int mediaLength, URI uri) throws UnsupportedAudioFileException, IOException {
+ AudioFileFormat audioFileFormat = getAudioFileFormat(inputStream, mediaLength, uri);
// (*1) audioFileFormat should not be detailed about frame size
return new AudioInputStream(inputStream, audioFileFormat.getFormat(), audioFileFormat.getFrameLength());
}
diff --git a/src/main/java/vavi/sound/sampled/opl3/Opl3Encoding.java b/src/main/java/vavi/sound/sampled/opl3/Opl3Encoding.java
index 7c09f50..d3367a6 100644
--- a/src/main/java/vavi/sound/sampled/opl3/Opl3Encoding.java
+++ b/src/main/java/vavi/sound/sampled/opl3/Opl3Encoding.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 by Naohide Sano, All rights reserved.
+ * Copyright (c) 2020 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
@@ -14,7 +14,7 @@
* Encodings used by the OPL3 audio decoder.
*
* @author Naohide Sano (nsano)
- * @version 0.00 111022 nsano initial version
+ * @version 0.00 201022 nsano initial version
*/
public class Opl3Encoding extends AudioFormat.Encoding {
@@ -28,7 +28,7 @@ public class Opl3Encoding extends AudioFormat.Encoding {
*
* @param name Name of the OPL3 encoding.
*/
- public Opl3Encoding(String name) {
+ private Opl3Encoding(String name) {
super(name);
}
}
diff --git a/src/main/java/vavi/sound/sampled/opl3/Opl3FileFormatType.java b/src/main/java/vavi/sound/sampled/opl3/Opl3FileFormatType.java
index 03d67d6..7690b7d 100644
--- a/src/main/java/vavi/sound/sampled/opl3/Opl3FileFormatType.java
+++ b/src/main/java/vavi/sound/sampled/opl3/Opl3FileFormatType.java
@@ -30,7 +30,7 @@ public class Opl3FileFormatType extends AudioFileFormat.Type {
* @param name the name of the OPL3 File Format.
* @param extension the file extension for this OPL3 File Format.
*/
- public Opl3FileFormatType(String name, String extension) {
+ private Opl3FileFormatType(String name, String extension) {
super(name, extension);
}
}
diff --git a/src/main/java/vavi/sound/sampled/opl3/Opl3ToPcmAudioInputStream.java b/src/main/java/vavi/sound/sampled/opl3/Opl3ToPcmAudioInputStream.java
index abfbdd6..0b133df 100644
--- a/src/main/java/vavi/sound/sampled/opl3/Opl3ToPcmAudioInputStream.java
+++ b/src/main/java/vavi/sound/sampled/opl3/Opl3ToPcmAudioInputStream.java
@@ -1,5 +1,7 @@
/*
- * http://opl3.cozendey.com/
+ * Copyright (c) 2020 by Naohide Sano, All rights reserved.
+ *
+ * Programmed by Naohide Sano
*/
package vavi.sound.sampled.opl3;
@@ -16,7 +18,6 @@
import vavi.io.OutputEngineInputStream;
import vavi.sound.opl3.Opl3Player;
import vavi.sound.opl3.Opl3Player.FileType;
-import vavi.util.Debug;
import static java.lang.System.getLogger;
@@ -26,6 +27,7 @@
*
* @author Naohide Sano (umjammer)
* @version 0.00 2020/10/23 umjammer initial version
+ * @see "http://opl3.cozendey.com/"
*/
public class Opl3ToPcmAudioInputStream extends AudioInputStream {
@@ -36,7 +38,7 @@ public Opl3ToPcmAudioInputStream(InputStream stream, AudioFormat format, long le
super(new OutputEngineInputStream(new Opl3OutputEngine(stream, sourceFormat)), format, length);
}
- /** */
+ /** */
private static class Opl3OutputEngine implements OutputEngine {
/** */
@@ -51,8 +53,9 @@ private static class Opl3OutputEngine implements OutputEngine {
/** */
public Opl3OutputEngine(InputStream is, AudioFormat format) throws IOException {
player = FileType.getPlayer(format.getEncoding());
- player.load(is);
+logger.log(Level.TRACE, "props: " + format.properties());
player.setProperties(format.properties());
+ player.load(is);
sampleRate = format.getSampleRate();
}
diff --git a/src/main/java/vavi/sound/sampled/opus/Opus2PcmAudioInputStream.java b/src/main/java/vavi/sound/sampled/opus/Opus2PcmAudioInputStream.java
index 3c53fde..1a9c560 100644
--- a/src/main/java/vavi/sound/sampled/opus/Opus2PcmAudioInputStream.java
+++ b/src/main/java/vavi/sound/sampled/opus/Opus2PcmAudioInputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 by Naohide Sano, All rights reserved.
+ * Copyright (c) 2011 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
diff --git a/src/main/java/vavi/sound/sampled/opus/OpusAudioFileReader.java b/src/main/java/vavi/sound/sampled/opus/OpusAudioFileReader.java
index d3b209c..9d2ea0e 100644
--- a/src/main/java/vavi/sound/sampled/opus/OpusAudioFileReader.java
+++ b/src/main/java/vavi/sound/sampled/opus/OpusAudioFileReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 by Naohide Sano, All rights reserved.
+ * Copyright (c) 2011 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
@@ -11,23 +11,25 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.System.Logger;
import java.net.URL;
import java.nio.file.Files;
import java.util.HashMap;
-import java.util.logging.Level;
-
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.spi.AudioFileReader;
import org.gagravarr.ogg.OggFile;
import org.gagravarr.opus.OpusFile;
-
import vavi.util.Debug;
+import static java.lang.System.Logger.Level.DEBUG;
+import static java.lang.System.Logger.Level.TRACE;
+import static java.lang.System.getLogger;
+import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
+
/**
* Provider for Opus audio file reading services. This implementation can parse
@@ -39,6 +41,8 @@
*/
public class OpusAudioFileReader extends AudioFileReader {
+ private static final Logger logger = getLogger(OpusAudioFileReader.class.getName());
+
@Override
public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException {
try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
@@ -55,7 +59,7 @@ public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileEx
@Override
public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
- return getAudioFileFormat(stream, AudioSystem.NOT_SPECIFIED); // TODO ???
+ return getAudioFileFormat(stream, NOT_SPECIFIED); // TODO ???
}
/**
@@ -70,7 +74,7 @@ public AudioFileFormat getAudioFileFormat(InputStream stream) throws Unsupported
* @throws IOException if an I/O exception occurs.
*/
protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLength) throws UnsupportedAudioFileException, IOException {
-Debug.println(Level.FINE, "enter available: " + bitStream.available());
+logger.log(DEBUG, "enter available: " + bitStream.available());
OpusFile opus;
try {
bitStream.mark(32);
@@ -86,8 +90,8 @@ protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLen
} catch (IOException e) {
throw e;
} catch (Exception e) {
-Debug.println(Level.FINER, e);
-Debug.printStackTrace(Level.FINEST, e);
+logger.log(DEBUG, e.toString());
+logger.log(TRACE, e.getMessage(), e);
throw (UnsupportedAudioFileException) new UnsupportedAudioFileException(e.getMessage()).initCause(e);
} finally {
try {
@@ -95,12 +99,12 @@ protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLen
} catch (IOException e) {
Debug.printStackTrace(e);
}
-Debug.println(Level.FINE, "finally available: " + bitStream.available());
+logger.log(DEBUG, "finally available: " + bitStream.available());
}
- AudioFormat format = new AudioFormat(OpusEncoding.OPUS, opus.getInfo().getSampleRate(), AudioSystem.NOT_SPECIFIED, opus.getInfo().getNumChannels(), AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true, new HashMap<>() {{
+ AudioFormat format = new AudioFormat(OpusEncoding.OPUS, opus.getInfo().getSampleRate(), NOT_SPECIFIED, opus.getInfo().getNumChannels(), NOT_SPECIFIED, NOT_SPECIFIED, true, new HashMap<>() {{
put("opus", opus);
}});
- return new AudioFileFormat(OpusFileFormatType.OPUS, format, AudioSystem.NOT_SPECIFIED);
+ return new AudioFileFormat(OpusFileFormatType.OPUS, format, NOT_SPECIFIED);
}
@Override
@@ -127,7 +131,7 @@ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFile
@Override
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException {
- return getAudioInputStream(stream, AudioSystem.NOT_SPECIFIED);
+ return getAudioInputStream(stream, NOT_SPECIFIED);
}
/**
diff --git a/src/main/java/vavi/sound/sampled/opus/OpusEncoding.java b/src/main/java/vavi/sound/sampled/opus/OpusEncoding.java
index a48489a..4842569 100644
--- a/src/main/java/vavi/sound/sampled/opus/OpusEncoding.java
+++ b/src/main/java/vavi/sound/sampled/opus/OpusEncoding.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 by Naohide Sano, All rights reserved.
+ * Copyright (c) 2011 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
@@ -26,7 +26,7 @@ public class OpusEncoding extends AudioFormat.Encoding {
*
* @param name Name of the Opus encoding.
*/
- public OpusEncoding(String name) {
+ private OpusEncoding(String name) {
super(name);
}
}
diff --git a/src/main/java/vavi/sound/sampled/opus/OpusFileFormatType.java b/src/main/java/vavi/sound/sampled/opus/OpusFileFormatType.java
index 397930b..b332920 100644
--- a/src/main/java/vavi/sound/sampled/opus/OpusFileFormatType.java
+++ b/src/main/java/vavi/sound/sampled/opus/OpusFileFormatType.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 by Naohide Sano, All rights reserved.
+ * Copyright (c) 2011 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
@@ -28,7 +28,7 @@ public class OpusFileFormatType extends AudioFileFormat.Type {
* @param name the name of the OPUS File Format.
* @param extension the file extension for this OPUS File Format.
*/
- public OpusFileFormatType(String name, String extension) {
+ private OpusFileFormatType(String name, String extension) {
super(name, extension);
}
}
diff --git a/src/main/java/vavi/sound/sampled/opus/OpusFormatConversionProvider.java b/src/main/java/vavi/sound/sampled/opus/OpusFormatConversionProvider.java
index 6e27fba..564d50c 100644
--- a/src/main/java/vavi/sound/sampled/opus/OpusFormatConversionProvider.java
+++ b/src/main/java/vavi/sound/sampled/opus/OpusFormatConversionProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 by Naohide Sano, All rights reserved.
+ * Copyright (c) 2011 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
diff --git a/src/main/java/vavi/sound/sampled/rococoa/Rococoa2PcmAudioInputStream.java b/src/main/java/vavi/sound/sampled/rococoa/Rococoa2PcmAudioInputStream.java
index 54e5932..de77a17 100644
--- a/src/main/java/vavi/sound/sampled/rococoa/Rococoa2PcmAudioInputStream.java
+++ b/src/main/java/vavi/sound/sampled/rococoa/Rococoa2PcmAudioInputStream.java
@@ -44,7 +44,7 @@ public Rococoa2PcmAudioInputStream(InputStream in, AudioFormat format, long leng
super(init(in), format, length);
}
- /** */
+ /** */
static InputStream init(InputStream in) {
AdvancedPipedInputStream source = new AdvancedPipedInputStream();
AdvancedPipedInputStream.OutputStreamEx sink = source.getOutputStream();
@@ -77,7 +77,7 @@ public void run() {
return source;
}
- /** */
+ /** */
static class TempFileInputEngine implements InputEngine {
InputStream in;
diff --git a/src/main/java/vavi/sound/sampled/rococoa/RococoaAudioFileReader.java b/src/main/java/vavi/sound/sampled/rococoa/RococoaAudioFileReader.java
index 7d607e0..8431a8a 100644
--- a/src/main/java/vavi/sound/sampled/rococoa/RococoaAudioFileReader.java
+++ b/src/main/java/vavi/sound/sampled/rococoa/RococoaAudioFileReader.java
@@ -12,14 +12,14 @@
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
-
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.spi.AudioFileReader;
+import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
+
/**
* RococoaAudioFileReader.
@@ -45,7 +45,7 @@ public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileEx
@Override
public AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
- return getAudioFileFormat(stream, AudioSystem.NOT_SPECIFIED);
+ return getAudioFileFormat(stream, NOT_SPECIFIED);
}
/**
@@ -62,8 +62,8 @@ public AudioFileFormat getAudioFileFormat(InputStream stream) throws Unsupported
protected AudioFileFormat getAudioFileFormat(InputStream bitStream, int mediaLength) throws UnsupportedAudioFileException, IOException {
// TODO determine rococoa is able to decode ot not
// TODO sampling rate, bits per sample, channels
- AudioFormat format = new AudioFormat(RcococaEncoding.ROCOCOA, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true);
- return new AudioFileFormat(RococoaFileFormatType.ROCOCOA, format, AudioSystem.NOT_SPECIFIED);
+ AudioFormat format = new AudioFormat(RcococaEncoding.ROCOCOA, NOT_SPECIFIED, NOT_SPECIFIED, NOT_SPECIFIED, NOT_SPECIFIED, NOT_SPECIFIED, true);
+ return new AudioFileFormat(RococoaFileFormatType.ROCOCOA, format, NOT_SPECIFIED);
}
@Override
@@ -90,7 +90,7 @@ public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFile
@Override
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException {
- return getAudioInputStream(stream, AudioSystem.NOT_SPECIFIED);
+ return getAudioInputStream(stream, NOT_SPECIFIED);
}
/**
diff --git a/src/main/java/vavi/sound/sampled/rococoa/RococoaClip.java b/src/main/java/vavi/sound/sampled/rococoa/RococoaClip.java
index 0566895..2e6af76 100644
--- a/src/main/java/vavi/sound/sampled/rococoa/RococoaClip.java
+++ b/src/main/java/vavi/sound/sampled/rococoa/RococoaClip.java
@@ -8,13 +8,14 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Level;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@@ -28,10 +29,11 @@
import javax.sound.sampled.LineUnavailableException;
import org.rococoa.ID;
-import vavi.util.Debug;
import vavix.rococoa.avfoundation.AVAudioFormat;
import vavix.rococoa.avfoundation.AVAudioPlayer;
+import static java.lang.System.getLogger;
+
/**
* RococoaClip.
@@ -41,6 +43,8 @@
*/
public class RococoaClip implements Clip {
+ private static final Logger logger = getLogger(RococoaClip.class.getName());
+
public static final javax.sound.sampled.DataLine.Info info =
new javax.sound.sampled.DataLine.Info(RococoaClip.class,
new AudioFormat(RcococaEncoding.ROCOCOA,
@@ -107,7 +111,7 @@ public void setValue(float newValue) {
// if no exception, commit to our new gain
linearGain = newLinearGain;
calcVolume();
-Debug.println("volume: " + leftGain);
+logger.log(Level.DEBUG, "volume: " + leftGain);
player.setVolume(leftGain);
}
@@ -218,7 +222,7 @@ public void flush() {
public void start() {
boolean r = player.play();
fireUpdate(new LineEvent(this, LineEvent.Type.START, 0));
-Debug.println("play: " + r);
+logger.log(Level.DEBUG, "play: " + r);
}
@Override
@@ -239,9 +243,8 @@ public boolean isActive() {
@Override
public AudioFormat getFormat() {
AVAudioFormat format = player.format();
-Debug.println(format + ", " + format.commonFormat());
+logger.log(Level.DEBUG, format + ", " + format.commonFormat());
return switch (format.commonFormat()) {
- default -> stream.getFormat();
case AVAudioFormat.PCMFormatFloat32 -> new AudioFormat(AudioFormat.Encoding.PCM_FLOAT,
(int) format.sampleRate(),
32,
@@ -270,6 +273,7 @@ public AudioFormat getFormat() {
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN);
+ default -> stream.getFormat();
};
}
@@ -294,7 +298,7 @@ public javax.sound.sampled.Line.Info getLineInfo() {
@Override
public void open() throws LineUnavailableException {
-Debug.println(Level.WARNING, "use #open(AudioInputStream)");
+logger.log(Level.WARNING, "use #open(AudioInputStream)");
}
@Override
@@ -403,7 +407,7 @@ public void open(AudioInputStream stream) throws LineUnavailableException, IOExc
}
});
fireUpdate(new LineEvent(this, LineEvent.Type.OPEN, 0));
-Debug.println("player: " + player);
+logger.log(Level.DEBUG, "player: " + player);
}
@Override
diff --git a/src/main/java/vavi/sound/sampled/rococoa/RococoaFileFormatType.java b/src/main/java/vavi/sound/sampled/rococoa/RococoaFileFormatType.java
index d9977ea..b998693 100644
--- a/src/main/java/vavi/sound/sampled/rococoa/RococoaFileFormatType.java
+++ b/src/main/java/vavi/sound/sampled/rococoa/RococoaFileFormatType.java
@@ -10,7 +10,7 @@
/**
- * FileFormatTypes used by the ROCOCOA audio decoder.
+ * FileFormatTypes used by the cocoa audio decoder.
*
* @author Naohide Sano (nsano)
* @version 0.00 050722 nsano initial version
@@ -18,17 +18,17 @@
public class RococoaFileFormatType extends AudioFileFormat.Type {
/**
- * Specifies an ROCOCOA file.
+ * Specifies a cocoa file.
*/
public static final AudioFileFormat.Type ROCOCOA = new RococoaFileFormatType("ROCOCOA", "caf");
/**
* Constructs a file type.
*
- * @param name the name of the Rococoa File Format.
+ * @param name the name of the cocoa File Format.
* @param extension the file extension for this Flac File Format.
*/
- public RococoaFileFormatType(String name, String extension) {
+ private RococoaFileFormatType(String name, String extension) {
super(name, extension);
}
}
diff --git a/src/main/java/vavi/sound/sampled/rococoa/RococoaFormatConversionProvider.java b/src/main/java/vavi/sound/sampled/rococoa/RococoaFormatConversionProvider.java
index 1633b39..45d3764 100644
--- a/src/main/java/vavi/sound/sampled/rococoa/RococoaFormatConversionProvider.java
+++ b/src/main/java/vavi/sound/sampled/rococoa/RococoaFormatConversionProvider.java
@@ -6,11 +6,13 @@
package vavi.sound.sampled.rococoa;
+import java.lang.System.Logger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.spi.FormatConversionProvider;
-import vavi.util.Debug;
+import static java.lang.System.Logger.Level.DEBUG;
+import static java.lang.System.getLogger;
/**
@@ -21,6 +23,8 @@
*/
public class RococoaFormatConversionProvider extends FormatConversionProvider {
+ private static final Logger logger = getLogger(RococoaFormatConversionProvider.class.getName());
+
@Override
public AudioFormat.Encoding[] getSourceEncodings() {
return new AudioFormat.Encoding[] {RcococaEncoding.ROCOCOA};
@@ -68,18 +72,18 @@ public AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding,
} else if (sourceFormat.getEncoding() instanceof RcococaEncoding && targetFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) {
return new Rococoa2PcmAudioInputStream(sourceStream, targetFormat, -1);
} else if (sourceFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED) && targetFormat.getEncoding() instanceof RcococaEncoding) {
-Debug.println("unable to convert " + sourceFormat + " to " + targetFormat);
+logger.log(DEBUG, "unable to convert " + sourceFormat + " to " + targetFormat);
throw new IllegalArgumentException("unable to convert " + sourceFormat + " to " + targetFormat);
} else {
-Debug.println("unable to convert " + sourceFormat + " to " + targetFormat);
+logger.log(DEBUG, "unable to convert " + sourceFormat + " to " + targetFormat);
throw new IllegalArgumentException("unable to convert " + sourceFormat + " to " + targetFormat);
}
} else {
-Debug.println("target format not found");
+logger.log(DEBUG, "target format not found");
throw new IllegalArgumentException("target format not found");
}
} else {
-Debug.println("conversion not supported");
+logger.log(DEBUG, "conversion not supported");
throw new IllegalArgumentException("conversion not supported");
}
}
@@ -96,18 +100,18 @@ public AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInput
targetFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) {
return new Rococoa2PcmAudioInputStream(sourceStream, targetFormat, -1);
} else if (sourceFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED) && targetFormat.getEncoding() instanceof RcococaEncoding) {
-Debug.println("unable to convert " + sourceFormat + " to " + targetFormat);
+logger.log(DEBUG, "unable to convert " + sourceFormat + " to " + targetFormat);
throw new IllegalArgumentException("unable to convert " + sourceFormat + " to " + targetFormat);
} else {
-Debug.println("unable to convert " + sourceFormat + " to " + targetFormat);
+logger.log(DEBUG, "unable to convert " + sourceFormat + " to " + targetFormat);
throw new IllegalArgumentException("unable to convert " + sourceFormat + " to " + targetFormat);
}
} else {
-Debug.println("target format not found");
+logger.log(DEBUG, "target format not found");
throw new IllegalArgumentException("target format not found");
}
} else {
-Debug.println("conversion not supported");
+logger.log(DEBUG, "conversion not supported");
throw new IllegalArgumentException("conversion not supported");
}
}
diff --git a/src/main/java/vavi/sound/sampled/rococoa/RococoaMixerProvider.java b/src/main/java/vavi/sound/sampled/rococoa/RococoaMixerProvider.java
index 4ae260a..8b9af1b 100644
--- a/src/main/java/vavi/sound/sampled/rococoa/RococoaMixerProvider.java
+++ b/src/main/java/vavi/sound/sampled/rococoa/RococoaMixerProvider.java
@@ -6,13 +6,14 @@
package vavi.sound.sampled.rococoa;
-import java.util.logging.Level;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Mixer.Info;
import javax.sound.sampled.spi.MixerProvider;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -23,6 +24,8 @@
*/
public class RococoaMixerProvider extends MixerProvider {
+ private static final Logger logger = getLogger(RococoaMixerProvider.class.getName());
+
@Override
public Info[] getMixerInfo() {
return new Info[] {RococoaMixer.mixerInfo};
@@ -31,11 +34,11 @@ public Info[] getMixerInfo() {
@Override
public Mixer getMixer(Info info) {
if (info == RococoaMixer.mixerInfo) {
-Debug.println(Level.FINE, "★1 info: " + info);
+logger.log(Level.DEBUG, "★1 info: " + info);
RococoaMixer mixer = new RococoaMixer();
return mixer;
} else {
-Debug.println(Level.FINE, "not suitable for this provider: " + info);
+logger.log(Level.DEBUG, "not suitable for this provider: " + info);
throw new IllegalArgumentException("info is not suitable for this provider");
}
}
diff --git a/src/main/java/vavi/sound/twinvq/LibAV.java b/src/main/java/vavi/sound/twinvq/LibAV.java
index 4ce94d2..5442f76 100644
--- a/src/main/java/vavi/sound/twinvq/LibAV.java
+++ b/src/main/java/vavi/sound/twinvq/LibAV.java
@@ -13,12 +13,8 @@
import java.util.Map;
import java.util.function.Function;
-import jdk.incubator.vector.FloatVector;
-import jdk.incubator.vector.VectorSpecies;
-import vavi.io.SeekableDataInputStream;
import vavi.sound.twinvq.TwinVQDec.TwinVQContext;
import vavi.sound.twinvq.VFQ.VqfContext;
-import vavi.util.Debug;
import static java.lang.System.getLogger;
@@ -156,24 +152,15 @@ public AVFloatDSPContext(int flags) {
* constraints: 32-byte aligned
* @param src0 first input vector
* constraints: 32-byte aligned
+ * @param src0P first source vector start index
* @param src1 second input vector
* constraints: 32-byte aligned
+ * @param src1P second source vector start index
* @param len number of elements in the input
* constraints: multiple of 16
*/
public void vector_fmul(float[] dst, int destP, float[] src0, int src0P, float[] src1, int src1P, int len) {
- VectorSpecies SPECIES = FloatVector.SPECIES_256;
- int upperBound = SPECIES.loopBound(len);
-
- for (int i = 0; i < upperBound; i += SPECIES.length()) {
- FloatVector v0 = FloatVector.fromArray(SPECIES, src0, src0P + i);
- FloatVector v1 = FloatVector.fromArray(SPECIES, src1, src1P + i);
- FloatVector result = v0.mul(v1);
- result.intoArray(dst, destP + i);
- }
-
- // Handle any remaining elements
- for (int i = upperBound; i < len; i++) {
+ for (int i = 0; i < len; i++) {
dst[destP + i] = src0[src0P + i] * src1[src1P + i];
}
}
@@ -187,38 +174,30 @@ public void vector_fmul(float[] dst, int destP, float[] src0, int src0P, float[]
* constraints: 16-byte aligned
* @param src0 first source vector
* constraints: 16-byte aligned
+ * @param src0P first source vector start index
* @param src1 second source vector
* constraints: 16-byte aligned
+ * @param src1P second source vector start index
* @param win half-window vector
* constraints: 16-byte aligned
* @param len length of vector
* constraints: multiple of 4
*/
public void vector_fmul_window(float[] dst, int dstP, float[] src0, int src0P, float[] src1, int src1P, float[] win, int len) {
- VectorSpecies SPECIES = FloatVector.SPECIES_128;
- int upperBound = SPECIES.loopBound(len);
-
- for (int i = 0; i < upperBound; i += SPECIES.length()) {
- FloatVector v_src0 = FloatVector.fromArray(SPECIES, src0, src0P + i);
- FloatVector v_win = FloatVector.fromArray(SPECIES, win, i);
-
- // Manually load reversed src1 and win vectors
- float[] src1Reversed = new float[SPECIES.length()];
- float[] winReversed = new float[SPECIES.length()];
- for (int j = 0; j < SPECIES.length(); j++) {
- src1Reversed[j] = src1[src1P + len - i - j - 1];
- winReversed[j] = win[len - i - j - 1];
- }
- FloatVector v_src1 = FloatVector.fromArray(SPECIES, src1Reversed, 0);
- FloatVector v_win_rev = FloatVector.fromArray(SPECIES, winReversed, 0);
-
- FloatVector result = v_src0.mul(v_win).add(v_src1.mul(v_win_rev));
- result.intoArray(dst, dstP + i);
+ int halfLen = len / 2;
+ int winP = 0; // Starting index for the window array
+
+ // Perform the vector multiply with window and accumulate
+ for (int i = 0; i < halfLen; i++) {
+ // Multiply src0[i] with win[i] and accumulate in the destination
+ float win0 = win[winP + i];
+ dst[dstP + i] = src0[src0P + i] * win0 + src1[src1P + i] * win[winP + len - 1 - i];
}
- // Handle any remaining elements
- for (int i = upperBound; i < len; i++) {
- dst[dstP + i] = src0[src0P + i] * win[i] + src1[src1P + len - i - 1] * win[len - i - 1];
+ for (int i = halfLen; i < len; i++) {
+ // Continue multiplying and accumulating for the second half
+ float win1 = win[winP + i];
+ dst[dstP + i] = src0[src0P + i] * win1 - src1[src1P + i] * win[winP + len - 1 - i];
}
}
@@ -226,36 +205,23 @@ public void vector_fmul_window(float[] dst, int dstP, float[] src0, int src0P, f
* Calculate the sum and difference of two vectors of floats.
*
* @param v1 first input vector, sum output, 16-byte aligned
+ * @param p1 first input vector start index
* @param v2 second input vector, difference output, 16-byte aligned
+ * @param p2 second input vector start index
* @param len length of vectors, multiple of 4
*/
public void butterflies_float(float[] v1, int p1, float[] v2, int p2, short len) {
- VectorSpecies SPECIES = FloatVector.SPECIES_128;
- int upperBound = SPECIES.loopBound(len);
-
- for (int i = 0; i < upperBound; i += SPECIES.length()) {
- FloatVector vec1 = FloatVector.fromArray(SPECIES, v1, p1 + i);
- FloatVector vec2 = FloatVector.fromArray(SPECIES, v2, p2 + i);
-
- FloatVector sum = vec1.add(vec2);
- FloatVector diff = vec1.sub(vec2);
-
- sum.intoArray(v1, p1 + i);
- diff.intoArray(v2, p2 + i);
- }
-
- // Handle any remaining elements
- for (int i = upperBound; i < len; i++) {
- float temp1 = v1[p1 + i];
- float temp2 = v2[p2 + i];
- v1[p1 + i] = temp1 + temp2;
- v2[p2 + i] = temp1 - temp2;
+ for (int i = 0; i < len; i++) {
+ float a = v1[p1 + i];
+ float b = v2[p2 + i];
+ v1[p1 + i] = a + b; // sum stored in v1
+ v2[p2 + i] = a - b; // difference stored in v2
}
}
}
static class AVTXContext {
- interface TXFunction extends TetraConsumer {}
+ interface TXFunction extends LibAV.TetraConsumer {}
}
static class AVFrame {
@@ -289,7 +255,7 @@ public AVPacket(int size) {
static void ff_init_ff_sine_windows(int index) {
float[] windows = new float[1 << index];
ff_sine_window_init(windows, 1 << index);
-Debug.println("index: " + index + ", windows: " + windows.length);
+logger.log(Level.DEBUG, "index: " + index + ", windows: " + windows.length);
ff_sine_windows.put(index, windows);
}
@@ -299,7 +265,7 @@ static void ff_sine_window_init(float[] window, int n) {
window[i] = (float) Math.sin((i + 0.5) * (Math.PI / (2.0 * n)));
}
- static int ff_get_buffer(AVCodecContext avctx, AVFrame frame, int flags) {
+ static int ff_get_buffer(LibAV.AVCodecContext avctx, AVFrame frame, int flags) {
int ret = 0;
if (frame.nb_samples * (long) avctx.ch_layout.nb_channels > avctx.max_samples) {
@@ -327,7 +293,7 @@ static int ff_get_buffer(AVCodecContext avctx, AVFrame frame, int flags) {
static int av_tx_init(AVTXContext[] ctx, AVTXContext.TXFunction[] tx, int index, int /*AVTXType*/ type,
int inv, int len, float[] scale, long flags) {
-Debug.println("type: " + type);
+logger.log(Level.DEBUG, "type: " + type);
scale[0] = 1f;
MDCT mdct = new MDCT(Float.SIZE, false, scale[0]);
tx[index] = (x, in, inp, out, op) -> mdct.imdctHalf(in, inp, out, op);
diff --git a/src/main/java/vavi/sound/twinvq/TwinVQ.java b/src/main/java/vavi/sound/twinvq/TwinVQ.java
index 34c0219..27f5a0f 100644
--- a/src/main/java/vavi/sound/twinvq/TwinVQ.java
+++ b/src/main/java/vavi/sound/twinvq/TwinVQ.java
@@ -36,7 +36,6 @@
import vavi.sound.twinvq.TwinVQDec.TwinVQFrameData;
import vavi.sound.twinvq.TwinVQDec.TwinVQFrameType;
import vavi.sound.twinvq.TwinVQDec.TwinVQModeTab;
-import vavi.util.Debug;
import static java.lang.System.getLogger;
import static vavi.sound.twinvq.LibAV.AVERROR_INVALIDDATA;
@@ -240,11 +239,11 @@ static void dequant(TwinVQContext tctx, byte[] cb_bits, float[] out,
int tab0 = tmp0 * cb_len; // cb0
int tab1 = tmp1 * cb_len; // cb1
-//Debug.printf("dq[%3d]: %d, %02x, %d, %02x, %d", i, tctx.bits_main_spec[0][ftype.ordinal()][bitstream_second_part], tmp0, tctx.bits_main_spec[1][ftype.ordinal()][bitstream_second_part], tmp1, bitstream_second_part);
-//Debug.println("bits: " + bits + ", tmp0: " + tmp0 + ", tmp1: " + tmp1 + ", cb_len: " + cb_len + ", tab0: " + tab0 + ", tab1: " + tab1 + ", cb0: " + cb0.length + ", cb1: " + cb1.length + ", cb1P: " + cb1P);
+//logger.log(Level.TRACE, "dq[%3d]: %d, %02x, %d, %02x, %d".formatted(i, tctx.bits_main_spec[0][ftype.ordinal()][bitstream_second_part], tmp0, tctx.bits_main_spec[1][ftype.ordinal()][bitstream_second_part], tmp1, bitstream_second_part));
+//logger.log(Level.TRACE, "bits: " + bits + ", tmp0: " + tmp0 + ", tmp1: " + tmp1 + ", cb_len: " + cb_len + ", tab0: " + tab0 + ", tab1: " + tab1 + ", cb0: " + cb0.length + ", cb1: " + cb1.length + ", cb1P: " + cb1P);
for (int j = 0; j < length; j++) {
-//System.err.printf("%d, %d, %d, %d%n", pos + j, tab0 + j, cb1P + tab1 + j, tctx.permut[ftype.ordinal()][pos + j] & 0xffff);
+//logger.log(Level.TRACE, "%d, %d, %d, %d".formatted(pos + j, tab0 + j, cb1P + tab1 + j, tctx.permut[ftype.ordinal()][pos + j] & 0xffff));
out[tctx.permut[ftype.ordinal()][pos + j] & 0xffff] = sign0 * cb0[tab0 + j] +
sign1 * cb1[cb1P + tab1 + j];
}
@@ -342,7 +341,7 @@ static void ff_sort_nearly_sorted_floats(float[] vals, int len) {
}
}
- /** */
+ /** */
static void dec_lpc_spectrum_inv(TwinVQContext tctx, float[] lsp, TwinVQFrameType ftype, float[] lpc) {
int size = tctx.mtab.size / tctx.mtab.fmode[ftype.ordinal()].sub;
@@ -364,12 +363,12 @@ static void dec_lpc_spectrum_inv(TwinVQContext tctx, float[] lsp, TwinVQFrameTyp
static final byte[] wtype_to_wsize = new byte[] {0, 0, 2, 2, 2, 1, 0, 1, 1};
- /** */
+ /** */
static void imdct_and_window(TwinVQContext tctx, TwinVQFrameType ftype,
int wtype, float[] in, int inP, float[] prev, int prev_bufP, int ch) {
AVTXContext tx = tctx.tx[ftype.ordinal()];
AVTXContext.TXFunction tx_fn = tctx.tx_fn[ftype.ordinal()];
-Debug.println("ftype: " + ftype + "(" + ftype.ordinal() + ")");
+logger.log(Level.DEBUG, "ftype: " + ftype + "(" + ftype.ordinal() + ")");
TwinVQModeTab mtab = tctx.mtab;
int bsize = mtab.size / mtab.fmode[ftype.ordinal()].sub;
int size = mtab.size;
@@ -683,7 +682,7 @@ static void construct_perm_table(TwinVQContext tctx, TwinVQFrameType ftype) {
size = tctx.avctx.ch_layout.nb_channels * mtab.fmode[ftype.ordinal()].sub;
block_size = mtab.size / mtab.fmode[ftype.ordinal()].sub;
}
-Debug.println("size: " + size + ", block_size: " + block_size);
+logger.log(Level.DEBUG, "size: " + size + ", block_size: " + block_size);
short[] bbfs = new short[bbf.capacity() / Short.BYTES];
permutate_in_line(bbfs, tctx.n_div[ftype.ordinal()], size,
@@ -756,7 +755,7 @@ static void init_bitstream_params(TwinVQContext tctx) {
tctx.length[i][0] = (byte) rounded_up;
tctx.length[i][1] = (byte) rounded_down;
tctx.length_change[i] = (byte) num_rounded_up;
-Debug.println("rounded_up: " + rounded_up + ", rounded_down: " + rounded_down + ", num_rounded_up: " + num_rounded_up);
+logger.log(Level.DEBUG, "rounded_up: " + rounded_up + ", rounded_down: " + rounded_down + ", num_rounded_up: " + num_rounded_up);
}
for (int frametype = TWINVQ_FT_SHORT.ordinal(); frametype <= TWINVQ_FT_PPC.ordinal(); frametype++)
diff --git a/src/main/java/vavi/sound/twinvq/TwinVQData.java b/src/main/java/vavi/sound/twinvq/TwinVQData.java
index f03dc91..41ab639 100644
--- a/src/main/java/vavi/sound/twinvq/TwinVQData.java
+++ b/src/main/java/vavi/sound/twinvq/TwinVQData.java
@@ -21,13 +21,14 @@
package vavi.sound.twinvq;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
-import java.util.logging.Level;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -51,6 +52,8 @@
*/
public class TwinVQData {
+ private static final Logger logger = getLogger(TwinVQData.class.getName());
+
static final short[] bark_tab_l08_512 = {
7, 8, 7, 8, 8, 8, 8, 8, 8, 9,
9, 10, 10, 11, 11, 12, 12, 14, 15, 16,
@@ -525,16 +528,7 @@ public class TwinVQData {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1,
};
- static final class tab {
-
- final int size;
- final byte[] tab;
-
- public tab(int size, byte[] tab) {
- this.size = size;
- this.tab = tab;
- }
- }
+ record tab(int size, byte[] tab) {}
static final tab[] tabs = {
new tab(0, null),
@@ -551,7 +545,7 @@ private static short[] initTable(String f) {
while (s.hasNextShort()) {
l.add(s.nextShort());
}
-Debug.println(Level.FINEST, f + ": " + l.size());
+logger.log(Level.TRACE, f + ": " + l.size());
return l.stream().collect(() -> ShortBuffer.allocate(l.size()), ShortBuffer::put, (left, right) -> {}).array();
}
}
diff --git a/src/main/java/vavi/sound/twinvq/TwinVQDec.java b/src/main/java/vavi/sound/twinvq/TwinVQDec.java
index 86ae82b..b94c7d7 100644
--- a/src/main/java/vavi/sound/twinvq/TwinVQDec.java
+++ b/src/main/java/vavi/sound/twinvq/TwinVQDec.java
@@ -30,7 +30,6 @@
import vavi.sound.twinvq.LibAV.HeptaConsumer;
import vavi.sound.twinvq.LibAV.TetraFunction;
import vavi.util.ByteUtil;
-import vavi.util.Debug;
import static java.lang.System.getLogger;
import static vavi.sound.twinvq.LibAV.AVERROR_INVALIDDATA;
@@ -429,8 +428,8 @@ private static int very_broken_op(int a, int b) {
x /= 400;
- int size = tabs[b / 5].size;
- byte[] rtab = tabs[b / 5].tab;
+ int size = tabs[b / 5].size();
+ byte[] rtab = tabs[b / 5].tab();
//System.err.printf("index: %d%n", size * ff_log2_c(2 * (x - 1) / size) + (x - 1) % size);
return x - rtab[size * ff_log2_c(2 * (x - 1) / size) + (x - 1) % size];
}
@@ -521,7 +520,7 @@ private static void read_cb_data(TwinVQContext tctx, GetBits gb, byte[] dst, Twi
dst[dstP++] = (byte) gb.get_bits(tctx.bits_main_spec[0][ftype.ordinal()][bs_second_part]);
dst[dstP++] = (byte) gb.get_bits(tctx.bits_main_spec[1][ftype.ordinal()][bs_second_part]);
-//Debug.printf("cb[%3d]: %d, %02x, %d, %02x, %d", i, tctx.bits_main_spec[0][ftype.ordinal()][bs_second_part], dst[dstP - 2], tctx.bits_main_spec[1][ftype.ordinal()][bs_second_part], dst[dstP - 1], bs_second_part);
+//logger.log(Level.TRACE, "cb[%3d]: %d, %02x, %d, %02x, %d".formatted(i, tctx.bits_main_spec[0][ftype.ordinal()][bs_second_part], dst[dstP - 2], tctx.bits_main_spec[1][ftype.ordinal()][bs_second_part], dst[dstP - 1], bs_second_part));
}
}
@@ -596,16 +595,16 @@ static int twinvq_decode_init(AVCodecContext avctx) {
return AVERROR_INVALIDDATA;
}
channels = ByteUtil.readBeInt(avctx.extradata) + 1;
-Debug.println("channels: " + channels);
+logger.log(Level.DEBUG, "channels: " + channels);
avctx.bit_rate = ByteUtil.readBeInt(avctx.extradata, 4) * 1000;
-Debug.println("bit_rate: " + avctx.bit_rate);
+logger.log(Level.DEBUG, "bit_rate: " + avctx.bit_rate);
isampf = ByteUtil.readBeInt(avctx.extradata, 8);
if (isampf < 8 || isampf > 44) {
logger.log(Level.ERROR, "Unsupported sample rate");
return AVERROR_INVALIDDATA;
}
-Debug.println("isampf: " + isampf);
+logger.log(Level.DEBUG, "isampf: " + isampf);
switch (isampf) {
case 44:
avctx.sample_rate = 44100;
@@ -630,13 +629,13 @@ static int twinvq_decode_init(AVCodecContext avctx) {
avctx.ch_layout.nb_channels = channels;
ibps = avctx.bit_rate / (1000 * channels);
-Debug.println("ibps: " + ibps);
+logger.log(Level.DEBUG, "ibps: " + ibps);
if (ibps < 8 || ibps > 48) {
logger.log(Level.ERROR, "Bad bitrate per channel value %d", ibps);
return AVERROR_INVALIDDATA;
}
-Debug.println("mtab: " + (isampf << 8) + ibps);
+logger.log(Level.DEBUG, "mtab: " + (isampf << 8) + ibps);
switch ((isampf << 8) + ibps) {
case (8 << 8) + 8:
tctx.mtab = mode_08_08;
diff --git a/src/main/java/vavi/sound/twinvq/VFQ.java b/src/main/java/vavi/sound/twinvq/VFQ.java
index 2e26bb7..14286c9 100644
--- a/src/main/java/vavi/sound/twinvq/VFQ.java
+++ b/src/main/java/vavi/sound/twinvq/VFQ.java
@@ -32,10 +32,8 @@
import vavi.sound.twinvq.LibAV.AVFormatContext;
import vavi.sound.twinvq.LibAV.AVInputFormat;
import vavi.sound.twinvq.LibAV.AVPacket;
-import vavi.sound.twinvq.LibAV.AVProbeData;
import vavi.sound.twinvq.LibAV.AVStream;
import vavi.util.ByteUtil;
-import vavi.util.Debug;
import vavi.util.StringUtil;
import static java.lang.System.getLogger;
@@ -157,7 +155,7 @@ static int vqf_read_header(AVFormatContext s) {
header_size -= 8;
-Debug.println("chunk: " + chunk_tag + ", " + len);
+logger.log(Level.DEBUG, "chunk: " + chunk_tag + ", " + len);
switch (chunk_tag) {
case TAG_COMM -> {
s.pb.readFully(comm_chunk, 0, 12);
@@ -243,7 +241,7 @@ static int vqf_read_header(AVFormatContext s) {
st.codecpar.extradata = new byte[12 + AV_INPUT_BUFFER_PADDING_SIZE];
st.codecpar.extradata_size = 12;
System.arraycopy(comm_chunk, 0, st.codecpar.extradata, 0, 12);
-Debug.println("extradata_size: " + st.codecpar.extradata_size + "\n" + StringUtil.getDump(st.codecpar.extradata));
+logger.log(Level.DEBUG, "extradata_size: " + st.codecpar.extradata_size + "\n" + StringUtil.getDump(st.codecpar.extradata));
// ff_metadata_conv_ctx(s, null, vqf_metadata_conv);
@@ -259,7 +257,7 @@ static AVPacket vqf_read_packet(AVFormatContext s) {
VqfContext c = s.priv_data;
int ret;
int size = (c.frame_bit_len - c.remaining_bits + 7) >> 3;
-Debug.println("size: " + size + ", blen: " + c.frame_bit_len + ", brem: " + c.remaining_bits + ", lfbits: " + (c.last_frame_bits & 0xff));
+logger.log(Level.DEBUG, "size: " + size + ", blen: " + c.frame_bit_len + ", brem: " + c.remaining_bits + ", lfbits: " + (c.last_frame_bits & 0xff));
AVPacket pkt = new AVPacket(size + 2);
diff --git a/src/main/java/vavi/sound/twinvq/obsolate/BStream.java b/src/main/java/vavi/sound/twinvq/obsolate/BStream.java
index c9889d8..fe1df5b 100644
--- a/src/main/java/vavi/sound/twinvq/obsolate/BStream.java
+++ b/src/main/java/vavi/sound/twinvq/obsolate/BStream.java
@@ -7,15 +7,17 @@
package vavi.sound.twinvq.obsolate;
import java.io.IOException;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.Arrays;
import vavi.sound.twinvq.obsolate.TwinVQ.BlockType;
-import vavi.sound.twinvq.obsolate.TwinVQ.Index;
-import vavi.sound.twinvq.obsolate.TwinVQ.HeaderInfo;
import vavi.sound.twinvq.obsolate.TwinVQ.ConfInfo;
import vavi.sound.twinvq.obsolate.TwinVQ.ConfInfoSubBlock;
-import vavi.util.Debug;
+import vavi.sound.twinvq.obsolate.TwinVQ.HeaderInfo;
+import vavi.sound.twinvq.obsolate.TwinVQ.Index;
+import static java.lang.System.getLogger;
import static vavi.sound.twinvq.obsolate.TwinVQ.asciiz;
import static vavi.sound.twinvq.obsolate.TwinVQ.twinVq;
@@ -28,6 +30,8 @@
*/
class BStream {
+ private static final Logger logger = getLogger(BStream.class.getName());
+
/**
* bits table for VQ
*/
@@ -54,7 +58,7 @@ static int getString(byte[] buf, int nbytes, BFile bfp) throws IOException {
for (ichar = 0; ichar < nbytes; ichar++) {
ibit = bfp.getBStream(c, 0, BFile.CHAR_BITS);
if (ibit < BFile.CHAR_BITS) {
-Debug.println("getString: bits underflow");
+logger.log(Level.DEBUG, "getString: bits underflow");
break;
}
buf[ichar] = (byte) c[0];
@@ -75,7 +79,7 @@ ChunkChunk loadTwinChunk(BFile bfp) throws IOException {
byte[] chunkID = new byte[TwinVQ.KEYWORD_BYTES + TwinVQ.VERSION_BYTES + 1];
getString(chunkID, TwinVQ.KEYWORD_BYTES + TwinVQ.VERSION_BYTES, bfp);
TVQ_VERSION = twinVq.TvqCheckVersion(asciiz(chunkID));
-Debug.println("chunkID: " + TVQ_VERSION);
+logger.log(Level.DEBUG, "chunkID: " + TVQ_VERSION);
if (TVQ_VERSION == TwinVQ.TVQ_UNKNOWN_VERSION) {
throw new IllegalArgumentException(String.format("Header reading error: Unknown version (%s).", TVQ_VERSION));
}
@@ -83,7 +87,7 @@ ChunkChunk loadTwinChunk(BFile bfp) throws IOException {
if (bfp.getBStream(chunkSize, 0, TwinVQ.ELEM_BYTES * BFile.CHAR_BITS) <= 0) {
throw new IllegalArgumentException("Header reading error: Failed to get header size.");
}
-Debug.println("chunkSize: " + chunkSize[0]);
+logger.log(Level.DEBUG, "chunkSize: " + chunkSize[0]);
byte[] chunkData = new byte[chunkSize[0] + 1];
if (getString(chunkData, chunkSize[0], bfp) < chunkSize[0]) {
@@ -126,7 +130,7 @@ int initBsReader(HeaderInfo setupInfo) {
TVQ_VERSION = twinVq.TvqCheckVersion(asciiz(setupInfo.id));
if (TVQ_VERSION == TwinVQ.TVQ_UNKNOWN_VERSION) {
-Debug.println("unsupported version: " + TVQ_VERSION);
+logger.log(Level.DEBUG, "unsupported version: " + TVQ_VERSION);
return 1;
}
@@ -325,7 +329,7 @@ int readBsFrame(Index index, BFile bfp) throws IOException {
iframe += 1;
-Debug.printf("bitcount: %d, numFixedBitsPerFrame: %d", bitcount, numFixedBitsPerFrame);
+logger.log(Level.DEBUG, "bitcount: %d, numFixedBitsPerFrame: %d".formatted( bitcount, numFixedBitsPerFrame));
return bitcount == numFixedBitsPerFrame ? 1 : 0;
}
diff --git a/src/main/java/vavi/sound/twinvq/obsolate/HeaderManager.java b/src/main/java/vavi/sound/twinvq/obsolate/HeaderManager.java
index fbf63ca..b8eb5c3 100644
--- a/src/main/java/vavi/sound/twinvq/obsolate/HeaderManager.java
+++ b/src/main/java/vavi/sound/twinvq/obsolate/HeaderManager.java
@@ -5,10 +5,12 @@
package vavi.sound.twinvq.obsolate;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.HashMap;
import java.util.Map;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -78,9 +80,9 @@ void init(ChunkChunk twinChunk) {
ChunkChunk scndChunk = (ChunkChunk) getPrimaryChunk("SCND");
PickUpSubChunks(secondaryChunkBank, scndChunk);
} catch (ChunkChunk.FailGetChunkException e) {
-// Debug.println("Fail!!");
+// logger.log(Level.DEBUG, "Fail!!"));
} catch (FailGetChunkException e) {
-// Debug.println("Fail getting SCND chnunk");
+// logger.log(Level.DEBUG, "Fail getting SCND chnunk"));
}
}
@@ -148,6 +150,9 @@ static class FailGetChunkException extends RuntimeException {
* can be obtained from header manager
*/
class UniStringInfo {
+
+ private static final Logger logger = getLogger(HeaderManager.class.getName());
+
public enum CharCode {
unknown_code(-1),
ISO_8859_1(0),
@@ -279,7 +284,7 @@ public final int getSecondaryCharCode() {
StringChunk scndChunk = new StringChunk(theManager.getSecondaryChunk(id));
putSecondaryInfo(scndChunk);
} catch (HeaderManager.FailGetChunkException e) {
-Debug.println(e);
+logger.log(Level.INFO, e.getMessage(), e);
} catch (NoCharCodeException e) {
throw new FailConstructionException();
}
diff --git a/src/main/java/vavi/sound/twinvq/obsolate/MyTwinVQ.java b/src/main/java/vavi/sound/twinvq/obsolate/MyTwinVQ.java
index daeaf5a..84c3f0b 100644
--- a/src/main/java/vavi/sound/twinvq/obsolate/MyTwinVQ.java
+++ b/src/main/java/vavi/sound/twinvq/obsolate/MyTwinVQ.java
@@ -6,7 +6,6 @@
package vavi.sound.twinvq.obsolate;
-
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
diff --git a/src/main/java/vavi/sound/twinvq/obsolate/TwinVQInputStream.java b/src/main/java/vavi/sound/twinvq/obsolate/TwinVQInputStream.java
index 0e94012..cf59fb2 100644
--- a/src/main/java/vavi/sound/twinvq/obsolate/TwinVQInputStream.java
+++ b/src/main/java/vavi/sound/twinvq/obsolate/TwinVQInputStream.java
@@ -13,10 +13,11 @@
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.ByteOrder;
-import vavi.util.Debug;
-
+import static java.lang.System.getLogger;
import static vavi.sound.twinvq.obsolate.TwinVQ.twinVq;
@@ -28,6 +29,8 @@
*/
public class TwinVQInputStream extends FilterInputStream {
+ private static final Logger logger = getLogger(TwinVQInputStream.class.getName());
+
/** byte order of the stream obtained with this class */
private final ByteOrder byteOrder;
@@ -56,11 +59,11 @@ public TwinVQInputStream(InputStream in,
super(new PipedInputStream());
this.byteOrder = byteOrder;
-Debug.println("byteOrder: " + this.byteOrder);
+logger.log(Level.DEBUG, "byteOrder: " + this.byteOrder);
-//Debug.println("samplesPerBlock: " + samplesPerBlock);
-//Debug.println("channels: " + channels);
-//Debug.println("blockSize: " + blockSize);
+//logger.log(Level.TRACE, "samplesPerBlock: " + samplesPerBlock);
+//logger.log(Level.TRACE, "channels: " + channels);
+//logger.log(Level.TRACE, "blockSize: " + blockSize);
//
@@ -90,7 +93,7 @@ public TwinVQInputStream(InputStream in,
}
int samplesThisBlock = samplesPerBlock;
-//Debug.println("samplesThisBlock: " + samplesThisBlock + ", " + l);
+//logger.log(Level.TRACE, "samplesThisBlock: " + samplesThisBlock + ", " + l);
TwinVQ.Index index = new TwinVQ.Index();
twinVq.TvqDecodeFrame(index , null);
@@ -104,16 +107,16 @@ public TwinVQInputStream(InputStream in,
}
}
done += samplesThisBlock;
-//Debug.println("done: " + done);
+//logger.log(Level.TRACE, "done: " + done);
}
} catch (IOException e) {
-Debug.printStackTrace(e);
+logger.log(Level.INFO, e.getMessage(), e);
} finally {
try {
os.flush();
os.close();
} catch (IOException e) {
-Debug.println(e);
+logger.log(Level.INFO, e.toString());
}
}
});
@@ -164,7 +167,7 @@ public int read(byte[] b, int off, int len) throws IOException {
}
}
} catch (IOException e) {
-e.printStackTrace(System.err);
+ logger.log(Level.INFO, e.getMessage(), e);
}
return i;
}
diff --git a/src/main/java/vavi/sound/twinvq/obsolate/TwinVQOutputStream.java b/src/main/java/vavi/sound/twinvq/obsolate/TwinVQOutputStream.java
index 5ab110c..697f552 100644
--- a/src/main/java/vavi/sound/twinvq/obsolate/TwinVQOutputStream.java
+++ b/src/main/java/vavi/sound/twinvq/obsolate/TwinVQOutputStream.java
@@ -11,11 +11,13 @@
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.ByteOrder;
import vavi.io.LittleEndianDataInputStream;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
import static vavi.sound.twinvq.obsolate.TwinVQ.twinVq;
@@ -27,6 +29,8 @@
*/
public class TwinVQOutputStream extends FilterOutputStream {
+ private static final Logger logger = getLogger(TwinVQOutputStream.class.getName());
+
/** */
private final ByteOrder byteOrder;
@@ -49,7 +53,7 @@ public TwinVQOutputStream(OutputStream out, ByteOrder byteOrder)
super(new ByteArrayOutputStream());
this.byteOrder = byteOrder;
-Debug.println("byteOrder: " + this.byteOrder);
+logger.log(Level.DEBUG, "byteOrder: " + this.byteOrder);
realOut = out;
}
@@ -63,7 +67,7 @@ public void close() throws IOException {
try {
LittleEndianDataInputStream ledis = new LittleEndianDataInputStream(new ByteArrayInputStream(((ByteArrayOutputStream) out).toByteArray()));
int length = ledis.available();
-Debug.println("length: " + length);
+logger.log(Level.DEBUG, "length: " + length);
byte[] adpcm = new byte[length / 4];
int[] pcm = new int[length / 2];
for (int i = 0; i < pcm.length; i++) {
@@ -77,13 +81,13 @@ public void close() throws IOException {
realOut.write(adpcm);
} catch (IOException e) {
-Debug.printStackTrace(e);
+logger.log(Level.INFO, e.getMessage(), e);
} finally {
try {
realOut.flush();
realOut.close();
} catch (IOException e) {
-Debug.println(e);
+logger.log(Level.INFO, e.toString());
}
}
diff --git a/src/main/java/vavi/sound/vsq/Block.java b/src/main/java/vavi/sound/vsq/Block.java
index 1274cda..92d0a8d 100644
--- a/src/main/java/vavi/sound/vsq/Block.java
+++ b/src/main/java/vavi/sound/vsq/Block.java
@@ -6,16 +6,18 @@
package vavi.sound.vsq;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.logging.Level;
-import vavi.util.Debug;
import vavi.util.StringUtil;
+import static java.lang.System.getLogger;
+
/**
* Block.
@@ -25,6 +27,8 @@
*/
public interface Block {
+ Logger logger = getLogger(Block.class.getName());
+
/** */
class Factory {
@@ -36,7 +40,7 @@ public static Block getBlock(String label, List params) {
try {
return (Block) methods.get(label).invoke(null, label, params);
} catch (Exception e) {
-Debug.printStackTrace(e);
+logger.log(Level.INFO, e.getMessage(), e);
throw new IllegalStateException(label, e);
}
} else {
@@ -45,7 +49,7 @@ public static Block getBlock(String label, List params) {
try {
return (Block) methods.get(wildcardLabel1).invoke(null, label, params);
} catch (Exception e) {
-Debug.printStackTrace(e);
+logger.log(Level.INFO, e.getMessage(), e);
throw new IllegalStateException(wildcardLabel1, e);
}
} else {
@@ -53,11 +57,11 @@ public static Block getBlock(String label, List params) {
try {
return (Block) methods.get("*BPList").invoke(null, label, params);
} catch (Exception e) {
-Debug.printStackTrace(e);
+logger.log(Level.INFO, e.getMessage(), e);
throw new IllegalStateException("*BPList", e);
}
} else {
-Debug.println(Level.SEVERE, "error block: " + label);
+logger.log(Level.ERROR, "error block: " + label);
throw new IllegalStateException("error block: " + label);
}
}
@@ -78,16 +82,16 @@ public static Block getBlock(String label, List params) {
//
for (Object o : props.keySet()) {
String key = (String) o;
- Debug.println("block class: " + props.getProperty(key));
+logger.log(Level.DEBUG, "block class: " + props.getProperty(key));
@SuppressWarnings("unchecked")
Class clazz = (Class) Class.forName(props.getProperty(key));
- Debug.println("block class: " + StringUtil.getClassName(clazz));
+logger.log(Level.DEBUG, "block class: " + StringUtil.getClassName(clazz));
Method method = clazz.getMethod("newInstance", String.class, List.class);
methods.put(key, method);
}
} catch (Exception e) {
-Debug.printStackTrace(e);
+logger.log(Level.INFO, e.getMessage(), e);
throw new IllegalStateException(e);
}
}
diff --git a/src/main/java/vavi/sound/vsq/VSQ.java b/src/main/java/vavi/sound/vsq/VSQ.java
index 3b7bf10..66d8d06 100644
--- a/src/main/java/vavi/sound/vsq/VSQ.java
+++ b/src/main/java/vavi/sound/vsq/VSQ.java
@@ -10,12 +10,13 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;
-
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiEvent;
@@ -26,7 +27,8 @@
import vavi.sound.vsq.block.Event;
import vavi.sound.vsq.block.EventList;
import vavi.sound.vsq.block.Handle;
-import vavi.util.Debug;
+
+import static java.lang.System.getLogger;
/**
@@ -38,6 +40,8 @@
*/
public class VSQ {
+ private static final Logger logger = getLogger(VSQ.class.getName());
+
/** */
private final List[] tracks;
@@ -53,10 +57,10 @@ public VSQ(Sequence sequence) throws IOException {
for (int i = 0; i < data.length; i++) {
tracks[i] = new ArrayList<>();
-//Debug.println("track:" + i + "\n" + data[i]);
+//logger.log(Level.TRACE, "track:" + i + "\n" + data[i]);
Reader reader = new StringReader(data[i]);
readBlocks(i, reader);
-Debug.println("track[" + i + "]: " + tracks[i].size());
+logger.log(Level.DEBUG, "track[" + i + "]: " + tracks[i].size());
}
}
@@ -87,9 +91,9 @@ public void convert1(Sequence sequence) throws InvalidMidiDataException {
EventList eventList = (EventList) findBlock(i, EventList.class);
for (EventList.Pair pair : eventList.getEvents()) {
- if (!"EOS".equals(pair.id)) {
- Event event = (Event) findEvent(i, pair.id);
- currentTicks = pair.tick;
+ if (!"EOS".equals(pair.id())) {
+ Event event = (Event) findEvent(i, pair.id());
+ currentTicks = pair.tick();
//
MidiEvent[] midiEvents = event.toMidiEvents(this);
@@ -116,7 +120,7 @@ private void readBlocks(int trackNumber, Reader reader) {
label = line.substring(1, line.length() - 1);
} else {
Block block = Block.Factory.getBlock(label, params);
-//Debug.println(ToStringBuilder.reflectionToString(block));
+//logger.log(Level.TRACE, ToStringBuilder.reflectionToString(block));
tracks[trackNumber].add(block);
label = line.substring(1, line.length() - 1);
params.clear();
@@ -166,7 +170,7 @@ public Block findHandle(int trackNumber, String id) {
*/
private static String[] getData(Sequence sequence) throws IOException {
Track[] tracks = sequence.getTracks();
-Debug.println("tracks: " + tracks.length);
+logger.log(Level.DEBUG, "tracks: " + tracks.length);
String[] results = new String[tracks.length - 1];
// for text, "DM:###:###..."
@@ -175,17 +179,17 @@ private static String[] getData(Sequence sequence) throws IOException {
for (int t = 0; t < tracks.length; t++) {
Track track = tracks[t];
if (t > 0) { // track 0 is master track
-Debug.println("events[" + t + "]: " + track.size());
+logger.log(Level.DEBUG, "events[" + t + "]: " + track.size());
for (int e = 0; e < track.size(); e++) {
MidiEvent event = track.get(e);
MidiMessage message = event.getMessage();
-//Debug.println("message: " + message);
+//logger.log(Level.TRACE, "message: " + message);
if (message instanceof MetaMessage meta) {
- //Debug.println(meta.getType());
+//logger.log(Level.TRACE, meta.getType());
switch (meta.getType()) {
case 1: // text event 127 bytes
byte[] data = meta.getData();
-//Debug.println(new String(data));
+//logger.log(Level.TRACE, new String(data));
if (data[0] == 'D' && data[1] == 'M') {
int p = 0;
do {
@@ -195,18 +199,18 @@ private static String[] getData(Sequence sequence) throws IOException {
p++;
} while (data[p] != ':');
p++;
-//Debug.println(new String(data).substring(p));
+//logger.log(Level.TRACE, new String(data).substring(p));
baos.write(data, p, data.length - p);
} else {
-Debug.println(new String(data, Charset.forName("MS932")));
+logger.log(Level.DEBUG, new String(data, Charset.forName("MS932")));
}
break;
case 3: // track name,
String trackName = new String(meta.getData());
-Debug.println("trackName[" + t + "]: " + trackName);
+logger.log(Level.DEBUG, "trackName[" + t + "]: " + trackName);
break;
default:
-Debug.println("unhandled meta: " + meta.getType());
+logger.log(Level.DEBUG, "unhandled meta: " + meta.getType());
break;
}
}
@@ -215,7 +219,7 @@ private static String[] getData(Sequence sequence) throws IOException {
}
}
-Debug.println(baos.toString("MS932"));
+logger.log(Level.DEBUG, baos.toString("MS932"));
return results;
}
diff --git a/src/main/java/vavi/sound/vsq/block/BPList.java b/src/main/java/vavi/sound/vsq/block/BPList.java
index cc77831..495a172 100644
--- a/src/main/java/vavi/sound/vsq/block/BPList.java
+++ b/src/main/java/vavi/sound/vsq/block/BPList.java
@@ -6,11 +6,11 @@
package vavi.sound.vsq.block;
+import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
import vavi.sound.vsq.Block;
-import vavi.util.Debug;
/**
@@ -48,9 +48,8 @@ public class BPList implements Block {
*/
String id;
- /** */
- public record Pair(long tick, int id) {
-
+ /** */
+ public record Pair(long tick, int id) {
}
/** */
@@ -60,7 +59,7 @@ public record Pair(long tick, int id) {
public static Block newInstance(String label, List params) {
BPList block = new BPList();
block.id = label;
-Debug.println("label: " + label);
+logger.log(Level.DEBUG, "label: " + label);
for (String param : params) {
String[] pair = param.split("=");
block.bps.add(new Pair(Long.parseLong(pair[0]), Integer.parseInt(pair[1])));
diff --git a/src/main/java/vavi/sound/vsq/block/Common.java b/src/main/java/vavi/sound/vsq/block/Common.java
index 363320a..7899bef 100644
--- a/src/main/java/vavi/sound/vsq/block/Common.java
+++ b/src/main/java/vavi/sound/vsq/block/Common.java
@@ -7,10 +7,10 @@
package vavi.sound.vsq.block;
import java.awt.Color;
+import java.lang.System.Logger.Level;
import java.util.List;
import vavi.sound.vsq.Block;
-import vavi.util.Debug;
/**
@@ -49,7 +49,7 @@ public static Block newInstance(String label, List params) {
}
case "DynamicsMode" -> block.dynamicsMode = Integer.parseInt(pair[1]);
case "PlayMode" -> block.playMode = Integer.parseInt(pair[1]);
- case null, default -> Debug.println("unhandled param: " + pair[0]);
+ case null, default -> logger.log(Level.DEBUG, "unhandled param: " + pair[0]);
}
}
return block;
diff --git a/src/main/java/vavi/sound/vsq/block/Event.java b/src/main/java/vavi/sound/vsq/block/Event.java
index f6db5b8..ca59042 100644
--- a/src/main/java/vavi/sound/vsq/block/Event.java
+++ b/src/main/java/vavi/sound/vsq/block/Event.java
@@ -6,8 +6,8 @@
package vavi.sound.vsq.block;
+import java.lang.System.Logger.Level;
import java.util.List;
-
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiEvent;
@@ -17,7 +17,6 @@
import vavi.sound.midi.MidiUtil;
import vavi.sound.vsq.Block;
import vavi.sound.vsq.VSQ;
-import vavi.util.Debug;
/**
@@ -88,7 +87,7 @@ public static Block newInstance(String label, List params) {
case "LyricHandle" -> block.lyricHandle = pair[1];
case "VibratoHandle" -> block.vibratoHandle = pair[1];
case "VibratoDelay" -> block.vibratoDelay = Integer.parseInt(pair[1]);
- case null, default -> Debug.println("unhandled param: " + pair[0]);
+ case null, default -> logger.log(Level.DEBUG, "unhandled param: " + pair[0]);
}
}
return block;
diff --git a/src/main/java/vavi/sound/vsq/block/EventList.java b/src/main/java/vavi/sound/vsq/block/EventList.java
index 2a2d899..6a11eed 100644
--- a/src/main/java/vavi/sound/vsq/block/EventList.java
+++ b/src/main/java/vavi/sound/vsq/block/EventList.java
@@ -21,14 +21,7 @@
public class EventList implements Block {
/** */
- public static class Pair {
- public final long tick;
- public final String id;
- public Pair(long tick, String id) {
- this.tick = tick;
- this.id = id;
- }
- }
+ public record Pair(long tick, String id) {}
/** */
private final List events = new ArrayList<>(); // 0=ID#0000
diff --git a/src/main/java/vavi/sound/vsq/block/Handle.java b/src/main/java/vavi/sound/vsq/block/Handle.java
index 2ee22fe..88533ad 100644
--- a/src/main/java/vavi/sound/vsq/block/Handle.java
+++ b/src/main/java/vavi/sound/vsq/block/Handle.java
@@ -6,10 +6,10 @@
package vavi.sound.vsq.block;
+import java.lang.System.Logger.Level;
import java.util.List;
import vavi.sound.vsq.Block;
-import vavi.util.Debug;
/**
@@ -88,14 +88,14 @@ public static Block newInstance(String label, List params) {
case "DepthBPY" -> block.depthBPY = pair[1];
case "RateBPX" -> block.rateBPX = pair[1];
case "RateBPY" -> block.rateBPY = pair[1];
- case null, default -> Debug.println("unhandled param: " + pair[0]);
+ case null, default -> logger.log(Level.DEBUG, "unhandled param: " + pair[0]);
}
}
return block;
}
public String getLyric() {
-//Debug.println("l0: " + l0.split(",")[0].replace("\"", ""));
+//logger.log(Level.TRACE, "l0: " + l0.split(",")[0].replace("\"", ""));
return l0.split(",")[0].replace("\"", "");
}
}
diff --git a/src/main/java/vavi/sound/vsq/block/Master.java b/src/main/java/vavi/sound/vsq/block/Master.java
index ecb12a6..1c32be9 100644
--- a/src/main/java/vavi/sound/vsq/block/Master.java
+++ b/src/main/java/vavi/sound/vsq/block/Master.java
@@ -6,10 +6,10 @@
package vavi.sound.vsq.block;
+import java.lang.System.Logger.Level;
import java.util.List;
import vavi.sound.vsq.Block;
-import vavi.util.Debug;
/**
@@ -31,7 +31,7 @@ public static Block newInstance(String label, List params) {
if ("PreMeasure".equals(pair[0])) {
block.preMeasure = Integer.parseInt(pair[1]);
} else {
-Debug.println("unhandled param: " + pair[0]);
+logger.log(Level.DEBUG, "unhandled param: " + pair[0]);
}
}
return block;
diff --git a/src/main/java/vavi/sound/vsq/block/Mixer.java b/src/main/java/vavi/sound/vsq/block/Mixer.java
index 46bdaff..c1add47 100644
--- a/src/main/java/vavi/sound/vsq/block/Mixer.java
+++ b/src/main/java/vavi/sound/vsq/block/Mixer.java
@@ -6,10 +6,10 @@
package vavi.sound.vsq.block;
+import java.lang.System.Logger.Level;
import java.util.List;
import vavi.sound.vsq.Block;
-import vavi.util.Debug;
/**
@@ -70,7 +70,7 @@ public static Block newInstance(String label, List params) {
} else if (pair[0].startsWith("Solo")) {
block.solos[Integer.parseInt(pair[0].substring(4))] = Integer.parseInt(pair[1]);
} else {
-Debug.println("unhandled param: " + pair[0]);
+logger.log(Level.DEBUG, "unhandled param: " + pair[0]);
}
}
return block;
diff --git a/src/main/java/vavix/rococoa/avfoundation/AUAudioUnit.java b/src/main/java/vavix/rococoa/avfoundation/AUAudioUnit.java
index c2f6fb6..28c0e6f 100644
--- a/src/main/java/vavix/rococoa/avfoundation/AUAudioUnit.java
+++ b/src/main/java/vavix/rococoa/avfoundation/AUAudioUnit.java
@@ -6,6 +6,9 @@
package vavix.rococoa.avfoundation;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+
import org.rococoa.ObjCClass;
import org.rococoa.ObjCObjectByReference;
import org.rococoa.RunOnMainThread;
@@ -15,7 +18,7 @@
import com.sun.jna.Callback;
import com.sun.jna.Pointer;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -26,6 +29,8 @@
*/
public abstract class AUAudioUnit extends NSObject {
+ private static final Logger logger = getLogger(AUAudioUnit.class.getName());
+
@SuppressWarnings("hiding")
private static final _Class CLASS = org.rococoa.Rococoa.createClass("AUAudioUnit", _Class.class);
@@ -43,9 +48,9 @@ void instantiateWithComponentDescription_options_completionHandler(AudioComponen
public static AUAudioUnit initWithComponentDescription(AudioComponentDescription desc) {
ObjCObjectByReference outError = new ObjCObjectByReference();
AUAudioUnit audioUnit = CLASS.alloc();
-Debug.println(audioUnit);
+logger.log(Level.DEBUG, audioUnit);
audioUnit = audioUnit.initWithComponentDescription_error(desc.byValue(), outError);
-Debug.println(audioUnit);
+logger.log(Level.DEBUG, audioUnit);
NSError error = outError.getValueAs(NSError.class);
if (error != null) {
throw new IllegalStateException(error.description());
diff --git a/src/main/java/vavix/rococoa/avfoundation/AVAudioUnit.java b/src/main/java/vavix/rococoa/avfoundation/AVAudioUnit.java
index 5365587..bd1a909 100644
--- a/src/main/java/vavix/rococoa/avfoundation/AVAudioUnit.java
+++ b/src/main/java/vavix/rococoa/avfoundation/AVAudioUnit.java
@@ -6,13 +6,15 @@
package vavix.rococoa.avfoundation;
+import java.lang.System.Logger;
import java.util.concurrent.CountDownLatch;
+import com.sun.jna.Callback;
+import com.sun.jna.Pointer;
import org.rococoa.ID;
import org.rococoa.ObjCClass;
-import com.sun.jna.Callback;
-import com.sun.jna.Pointer;
+import static java.lang.System.getLogger;
/**
@@ -23,6 +25,8 @@
*/
public abstract class AVAudioUnit extends AVAudioNode {
+ private static final Logger logger = getLogger(AVAudioUnit.class.getName());
+
private static final _Class CLASS = org.rococoa.Rococoa.createClass("AVAudioUnit", _Class.class);
public interface _Class extends ObjCClass {
@@ -49,7 +53,7 @@ class Wrapper { AVAudioUnit object; }
@SuppressWarnings("unused")
public void apply(ID audioUnit, ID error) {
// result.object = Rococoa.wrap(audioUnit, AVAudioUnit.class);
-//Debug.println(Rococoa.wrap(error, NSError.class));
+//logger.log(Level.TRACE, Rococoa.wrap(error, NSError.class));
// cdl.countDown();
}
};
diff --git a/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitComponentManager.java b/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitComponentManager.java
index 69d10f0..fdfe6ae 100644
--- a/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitComponentManager.java
+++ b/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitComponentManager.java
@@ -6,6 +6,8 @@
package vavix.rococoa.avfoundation;
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
@@ -13,7 +15,7 @@
import org.rococoa.cocoa.foundation.NSArray;
import org.rococoa.cocoa.foundation.NSObject;
-import vavi.util.Debug;
+import static java.lang.System.getLogger;
/**
@@ -24,6 +26,8 @@
*/
public abstract class AVAudioUnitComponentManager extends NSObject {
+ private static final Logger logger = getLogger(AVAudioUnitComponentManager.class.getName());
+
@SuppressWarnings("hiding")
private static final _Class CLASS = org.rococoa.Rococoa.createClass("AVAudioUnitComponentManager", _Class.class);
@@ -33,7 +37,7 @@ public interface _Class extends ObjCClass {
public static AVAudioUnitComponentManager sharedInstance() {
AVAudioUnitComponentManager manager = CLASS.sharedAudioUnitComponentManager();
-Debug.println(manager);
+logger.log(Level.DEBUG, manager);
return manager;
}
@@ -42,7 +46,7 @@ public static AVAudioUnitComponentManager sharedInstance() {
public List components(AudioComponentDescription desc) {
List result = new ArrayList<>();
NSArray components = componentsMatchingDescription(desc.byValue());
-Debug.println(components.count());
+logger.log(Level.DEBUG, components.count());
for (int i = 0; i < components.count(); i++) {
result.add(org.rococoa.Rococoa.cast(components.objectAtIndex(i), AVAudioUnitComponent.class));
}
diff --git a/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitMIDIInstrument.java b/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitMIDIInstrument.java
index d0e0909..edc46e6 100644
--- a/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitMIDIInstrument.java
+++ b/src/main/java/vavix/rococoa/avfoundation/AVAudioUnitMIDIInstrument.java
@@ -76,7 +76,7 @@ public void stopNote(int note, int channel) {
* (F0) and termination (F7) bytes.
*/
public void sendMIDISysExEvent(byte[] midiData) {
-//Debug.printf("sysex: %02X\n%s", midiData[0], StringUtil.getDump(midiData));
+//logger.log(Level.TRACE, "sysex: %02X\n%s".formatted(midiData[0], StringUtil.getDump(midiData)));
NSData data = NSData.CLASS.dataWithBytes_length(midiData, midiData.length);
sendMIDISysExEvent(data);
}
diff --git a/src/main/java/vavix/rococoa/avfoundation/AudioToolbox.java b/src/main/java/vavix/rococoa/avfoundation/AudioToolbox.java
index 686861d..ccacc45 100644
--- a/src/main/java/vavix/rococoa/avfoundation/AudioToolbox.java
+++ b/src/main/java/vavix/rococoa/avfoundation/AudioToolbox.java
@@ -6,11 +6,10 @@
package vavix.rococoa.avfoundation;
-import org.rococoa.Foundation;
-import org.rococoa.IDByReference;
-
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
+import org.rococoa.Foundation;
+import org.rococoa.IDByReference;
/**
@@ -82,7 +81,7 @@ static String AudioComponentName(Pointer inComponent) {
if (r != 0) {
throw new IllegalStateException(String.valueOf(r));
}
-//Debug.println(r + ", " + outName);
+//logger.log(Level.TRACE, r + ", " + outName);
return Foundation.toString(outName.getValue());
}
}
diff --git a/src/test/java/ClipTest.java b/src/test/java/ClipTest.java
index 59572a5..6a43004 100644
--- a/src/test/java/ClipTest.java
+++ b/src/test/java/ClipTest.java
@@ -49,7 +49,8 @@ static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
@Property(name = "clip.test")
String clipTest = "src/test/resources/test.flac";
@@ -61,21 +62,23 @@ void setup() throws Exception {
}
}
- @Test
- void test1() throws Exception {
- main(new String[] {clipTest});
- }
-
/**
* @param args 0: clip in
*/
public static void main(String[] args) throws Exception {
String inFile = args[0];
+ ClipTest app = new ClipTest();
+ app.setup();
+ app.test1();
+ }
- for (AudioFileFormat.Type type : AudioSystem.getAudioFileTypes()) {
- System.err.println(type);
- }
- Path file = Paths.get(inFile);
+ @Test
+ void test1() throws Exception {
+for (AudioFileFormat.Type type : AudioSystem.getAudioFileTypes()) {
+ System.err.println(type);
+}
+
+ Path file = Paths.get(clipTest);
Debug.println(file);
// URL clipURL = new URL(inFile);
diff --git a/src/test/java/LineTest.java b/src/test/java/LineTest.java
index 1fef95c..0bd8b4c 100644
--- a/src/test/java/LineTest.java
+++ b/src/test/java/LineTest.java
@@ -4,6 +4,8 @@
* Programmed by Naohide Sano
*/
+import java.nio.file.Files;
+import java.nio.file.Paths;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@@ -11,7 +13,13 @@
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
+
import static vavi.sound.SoundUtil.volume;
+import static vavix.util.DelayedWorker.later;
/**
@@ -20,14 +28,36 @@
* @author Naohide Sano (umjammer)
* @version 0.00 2012/06/11 umjammer initial version
*/
+@PropsEntity(url = "file:local.properties")
public class LineTest {
- 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")
+ double volume = 0.2;
+
+ static long time = System.getProperty("vavi.test", "").equals("ide") ? 1000 * 1000 : 10 * 1000;
+
+ @BeforeEach
+ void setup() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
/**
- * @param args
+ * @param args none
*/
public static void main(String[] args) throws Exception {
+ LineTest app = new LineTest();
+ app.setup();
+ app.test0();
+ }
+
+ @Test
+ void test0() throws Exception {
// microphone
AudioFormat targetFormat = new AudioFormat(44100, 16, 2, true, false);
DataLine.Info targetInfo = new DataLine.Info(TargetDataLine.class, targetFormat);
@@ -47,7 +77,7 @@ public static void main(String[] args) throws Exception {
speaker.start();
byte[] buf = new byte[speaker.getBufferSize()];
- while (true) {
+ while (!later(time).come()) {
int r = stream.read(buf);
if (r < 0) {
break;
diff --git a/src/test/java/LineTest2.java b/src/test/java/LineTest2.java
index bd7667e..185a05e 100644
--- a/src/test/java/LineTest2.java
+++ b/src/test/java/LineTest2.java
@@ -23,6 +23,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.junit.jupiter.params.ParameterizedTest;
@@ -57,7 +58,8 @@ static boolean localPropertiesExists() {
"vavi\\.sound\\.DebugInputStream#\\w+");
}
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
@Property(name = "line2.test")
String inFile = "src/test/resources/test.caf";
@@ -70,7 +72,7 @@ void setup() throws Exception {
}
/**
- * @param args
+ * @param args use local.properties
*/
public static void main(String[] args) throws Exception {
LineTest2 app = new LineTest2();
@@ -82,11 +84,11 @@ public static void main(String[] args) throws Exception {
System.err.println(type);
}
AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(new File(app.inFile).toURI().toURL());
- LineTest2.play(originalAudioInputStream);
+ app.play(originalAudioInputStream);
}
- /** */
- static void play(AudioInputStream originalAudioInputStream) throws Exception {
+ /** play the audio using line */
+ void play(AudioInputStream originalAudioInputStream) throws Exception {
AudioFormat originalAudioFormat = originalAudioInputStream.getFormat();
Debug.println(originalAudioFormat);
AudioFormat targetAudioFormat = new AudioFormat( // PCM
@@ -121,6 +123,7 @@ static void play(AudioInputStream originalAudioInputStream) throws Exception {
}
@ParameterizedTest
+ @DisplayName("test many types")
@ValueSource(strings = {
"src/test/resources/speex.ogg",
"src/test/resources/test.ogg",
@@ -144,6 +147,7 @@ void test(String file) throws Exception {
}
}
+ /** simulate jdk {@link AudioSystem#getAudioInputStream} method */
@SuppressWarnings({ "unchecked", "rawtypes", "restriction" })
static AudioInputStream dummy(InputStream stream) throws UnsupportedAudioFileException, IOException {
List providers = com.sun.media.sound.JDK13Services.getProviders(AudioFileReader.class);
@@ -170,6 +174,7 @@ static AudioInputStream dummy(InputStream stream) throws UnsupportedAudioFileExc
@Test
@Disabled("for just fix #7, not needed any more")
+ @DisplayName("for just fix #7")
void test2() throws Exception {
InputStream is = new BufferedInputStream(Files.newInputStream(Paths.get("src/test/resources/test.mp3")));
AudioInputStream audioInputStream = new MpegAudioFileReader().getAudioInputStream(is);
diff --git a/src/test/java/MidiTest.java b/src/test/java/MidiTest.java
index 9723046..78f9f48 100644
--- a/src/test/java/MidiTest.java
+++ b/src/test/java/MidiTest.java
@@ -56,7 +56,8 @@ static boolean localPropertiesExists() {
// System.setProperty("javax.sound.midi.Receiver", "#Rococoa MIDI Synthesizer");
}
- static final float volume = Float.parseFloat(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume.midi")
+ float volume = 0.2f;
@Property(name = "midi.test")
String filename;
diff --git a/src/test/java/MmlTest.java b/src/test/java/MmlTest.java
index fd0a136..a76d471 100644
--- a/src/test/java/MmlTest.java
+++ b/src/test/java/MmlTest.java
@@ -13,12 +13,15 @@
import jp.or.rim.kt.kemusiro.sound.FMGeneralInstrument;
import jp.or.rim.kt.kemusiro.sound.MMLPlayer;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import vavi.util.Debug;
import vavi.util.properties.annotation.Property;
import vavi.util.properties.annotation.PropsEntity;
+import static vavix.util.DelayedWorker.later;
+
/**
* MmlTest.
@@ -34,7 +37,11 @@ static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
- static final float volume = Float.parseFloat(System.getProperty("vavi.test.volume", "0.2"));
+ static boolean onIde = System.getProperty("vavi.test", "").equals("ide");
+ static long time = onIde ? 1000 * 1000 : 10 * 1000;
+
+ @Property(name = "vavi.test.volume")
+ float volume = 0.2f;
@Property(name = "mml")
String mml = "src/test/resources/mml/BADINERIE.mml";
@@ -45,9 +52,22 @@ void setup() throws Exception {
PropsEntity.Util.bind(this);
}
}
+
@Test
+ @DisplayName("play")
void test1() throws Exception {
- main(new String[] {mml});
+ CountDownLatch cdl = new CountDownLatch(1);
+ MMLPlayer p = new MMLPlayer(e -> {
+ if (e.getType() == LineEvent.Type.STOP) cdl.countDown();
+ });
+ p.setVolume(volume);
+ p.setMML(new String[] {String.join("", Files.readAllLines(Paths.get(mml)))});
+ p.start();
+ if (onIde) later(time, cdl::countDown);
+ cdl.await();
+Debug.println("here");
+ p.stop();
+Thread.getAllStackTraces().keySet().forEach(System.err::println);
}
private static void usage() {
@@ -74,21 +94,12 @@ public static void main(String[] args) throws Exception {
} else {
FMGeneralInstrument.readParameterByResource();
}
- CountDownLatch cdl = new CountDownLatch(1);
- MMLPlayer p = new MMLPlayer(e -> {
- if (e.getType() == LineEvent.Type.STOP) cdl.countDown();
- });
- String[] mmls = new String[args.length];
- int i = 0;
+
+ MmlTest app = new MmlTest();
+ app.setup();
for (String arg : args) {
- mmls[i++] = String.join("", Files.readAllLines(Paths.get(arg)));
+ app.mml = arg;
+ app.test1();
}
- p.setVolume(volume);
- p.setMML(mmls);
- p.start();
- cdl.await();
-Debug.println("here");
- p.stop();
-Thread.getAllStackTraces().keySet().forEach(System.err::println);
}
}
\ No newline at end of file
diff --git a/src/test/java/PlayG721Adpcm.java b/src/test/java/PlayG721Adpcm.java
index 5172904..f774a5e 100644
--- a/src/test/java/PlayG721Adpcm.java
+++ b/src/test/java/PlayG721Adpcm.java
@@ -9,14 +9,18 @@
import java.nio.ByteOrder;
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.LineEvent;
import javax.sound.sampled.SourceDataLine;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import vavi.sound.adpcm.ccitt.G721InputStream;
+import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static vavi.sound.SoundUtil.volume;
@@ -27,21 +31,43 @@
* @author Naohide Sano (nsano)
* @version 0.00 030714 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
public class PlayG721Adpcm {
- 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")
+ double volume = 0.2;
+
+ String g721 = "src/test/resources/test.g721";
+
+ int sampleRate = 16000;
+
+ @BeforeEach
+ void setup() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
/**
* usage: java PlayG721Adpcm g721_file [sampleRate]
*/
public static void main(String[] args) throws Exception {
-
- int sampleRate = 16000;
+ PlayG721Adpcm app = new PlayG721Adpcm();
+ app.setup();
+ app.g721 = args[0];
if (args.length == 2) {
- sampleRate = Integer.parseInt(args[1]);
-System.err.println("sampleRate: " + sampleRate);
+ app.sampleRate = Integer.parseInt(args[1]);
+System.err.println("sampleRate: " + app.sampleRate);
}
+ app.test0();
+ }
+ @Test
+ void test0() throws Exception {
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
AudioFormat format = new AudioFormat(
@@ -52,10 +78,10 @@ public static void main(String[] args) throws Exception {
2,
sampleRate,
byteOrder.equals(ByteOrder.BIG_ENDIAN));
-System.err.println(format);
+Debug.println(format);
- InputStream is = new G721InputStream(new BufferedInputStream(Files.newInputStream(Paths.get(args[0]))), byteOrder);
-// OutputStream os = new BufferedOutputStream(new FileOutputStream(args[1]));
+ InputStream is = new G721InputStream(new BufferedInputStream(Files.newInputStream(Paths.get(g721))), byteOrder);
+//OutputStream os = new BufferedOutputStream(new FileOutputStream(args[1]));
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
@@ -69,17 +95,17 @@ public static void main(String[] args) throws Exception {
line.start();
byte[] buf = new byte[1024];
int l;
-// System.err.println("before: " + is.available());
+//Debug.println("before: " + is.available());
while (is.available() > 0) {
l = is.read(buf, 0, 1024);
line.write(buf, 0, l);
-// System.err.println(l + ", " + is.available());
-// os.write(buf, 0, l);
+//Debug.println(l + ", " + is.available());
+//os.write(buf, 0, l);
}
line.drain();
line.stop();
line.close();
-// os.close();
+//os.close();
is.close();
}
}
diff --git a/src/test/java/vavi/sound/ilbc/IlbcTest.java b/src/test/java/vavi/sound/ilbc/IlbcTest.java
index bf3b45f..13f809a 100644
--- a/src/test/java/vavi/sound/ilbc/IlbcTest.java
+++ b/src/test/java/vavi/sound/ilbc/IlbcTest.java
@@ -55,7 +55,8 @@ void setup() throws Exception {
}
}
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
// ----
diff --git a/src/test/java/vavi/sound/ldcelp/LdCelpTest.java b/src/test/java/vavi/sound/ldcelp/LdCelpTest.java
index 58f5548..24ae54d 100644
--- a/src/test/java/vavi/sound/ldcelp/LdCelpTest.java
+++ b/src/test/java/vavi/sound/ldcelp/LdCelpTest.java
@@ -61,7 +61,8 @@ void setup() throws Exception {
}
}
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
String outFile = "tmp/ldcelp-vavi-out.pcm";
String correctFile = "src/test/resources/ldcelp/sample-expected.pcm";
diff --git a/src/test/java/vavi/sound/midi/jsyn/JSynSynthesizerTest.java b/src/test/java/vavi/sound/midi/jsyn/JSynSynthesizerTest.java
index 2c8c668..b7d2cf3 100644
--- a/src/test/java/vavi/sound/midi/jsyn/JSynSynthesizerTest.java
+++ b/src/test/java/vavi/sound/midi/jsyn/JSynSynthesizerTest.java
@@ -50,7 +50,8 @@ static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
- static float volume = (float) Double.parseDouble(System.getProperty("vavi.test.volume.midi", "0.2"));
+ @Property(name = "vavi.test.volume.midi")
+ float volume = 0.2f;
@Property(name = "jsyn.test")
String jsynTest = "src/test/resources/test.mid";
diff --git a/src/test/java/vavi/sound/midi/mocha/MochaMidiDeviceProvider.java b/src/test/java/vavi/sound/midi/mocha/MochaMidiDeviceProvider.java
index 115b813..a7e8740 100644
--- a/src/test/java/vavi/sound/midi/mocha/MochaMidiDeviceProvider.java
+++ b/src/test/java/vavi/sound/midi/mocha/MochaMidiDeviceProvider.java
@@ -22,7 +22,7 @@
*/
public class MochaMidiDeviceProvider extends MidiDeviceProvider {
- /** */
+ /** */
public final static int MANUFACTURER_ID = 0x5e;
/** */
diff --git a/src/test/java/vavi/sound/midi/mocha/MochaSynthesizerTest.java b/src/test/java/vavi/sound/midi/mocha/MochaSynthesizerTest.java
index 5d1c6e2..7cd1e54 100644
--- a/src/test/java/vavi/sound/midi/mocha/MochaSynthesizerTest.java
+++ b/src/test/java/vavi/sound/midi/mocha/MochaSynthesizerTest.java
@@ -48,7 +48,8 @@ static boolean localPropertiesExists() {
@Property(name = "mocha.test")
String mochaTest = "src/test/resources/test.mid";
- static float volume = (float) Double.parseDouble(System.getProperty("vavi.test.volume.midi", "0.2"));
+ @Property(name = "vavi.test.volume.midi")
+ float volume = 0.2f;
@BeforeEach
void setup() throws Exception {
diff --git a/src/test/java/vavi/sound/midi/opl3/Opl3SynthesizerTest.java b/src/test/java/vavi/sound/midi/opl3/Opl3SynthesizerTest.java
index e86f885..e2901c4 100644
--- a/src/test/java/vavi/sound/midi/opl3/Opl3SynthesizerTest.java
+++ b/src/test/java/vavi/sound/midi/opl3/Opl3SynthesizerTest.java
@@ -55,7 +55,8 @@ static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
- static float volume = (float) Double.parseDouble(System.getProperty("vavi.test.volume.midi", "0.2"));
+ @Property(name = "vavi.test.volume.midi")
+ float volume = 0.2f;
@Property(name = "opl3.test")
String opl3test = "src/test/resources/test.mid";
diff --git a/src/test/java/vavi/sound/midi/rococoa/RococoaSynthesizerTest.java b/src/test/java/vavi/sound/midi/rococoa/RococoaSynthesizerTest.java
index 4a1b89b..0dbbb60 100644
--- a/src/test/java/vavi/sound/midi/rococoa/RococoaSynthesizerTest.java
+++ b/src/test/java/vavi/sound/midi/rococoa/RococoaSynthesizerTest.java
@@ -74,7 +74,8 @@ static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
- static float volume = (float) Double.parseDouble(System.getProperty("vavi.test.volume.midi", "0.2"));
+ @Property(name = "vavi.test.volume.midi")
+ float volume = 0.2f;
@Property(name = "rococoa.test")
String rococoaTest = "src/test/resources/test.mid";
diff --git a/src/test/java/vavi/sound/pcm/equalizing/sse/EqualizerTest.java b/src/test/java/vavi/sound/pcm/equalizing/sse/EqualizerTest.java
index 6b92d87..fbe0085 100644
--- a/src/test/java/vavi/sound/pcm/equalizing/sse/EqualizerTest.java
+++ b/src/test/java/vavi/sound/pcm/equalizing/sse/EqualizerTest.java
@@ -7,6 +7,8 @@
package vavi.sound.pcm.equalizing.sse;
import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Properties;
import javax.sound.sampled.AudioFormat;
@@ -19,6 +21,8 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import vavix.util.Checksum;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -32,19 +36,26 @@
* @version 0.00 060417 nsano initial version
*/
@Disabled("not implemented yet")
+@PropsEntity(url = "file:local.properties")
class EqualizerTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
+ @Property(name = "equalizer.in.wav")
String inFile;
String outFile = "tmp/out.vavi.wav";
String correctFile = "src/test/java/resources/vavi/sound/pcm/equalizing/out.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
@BeforeEach
void setUp() throws Exception {
- Properties props = new Properties();
- props.load(EqualizerTest.class.getResourceAsStream("local.properties"));
- inFile = props.getProperty("equalizer.in.wav");
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
}
@Test
diff --git a/src/test/java/vavi/sound/pcm/equalizing/sse/Test2.java b/src/test/java/vavi/sound/pcm/equalizing/sse/Test2.java
index c427353..9773790 100644
--- a/src/test/java/vavi/sound/pcm/equalizing/sse/Test2.java
+++ b/src/test/java/vavi/sound/pcm/equalizing/sse/Test2.java
@@ -13,10 +13,11 @@
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@@ -31,7 +32,10 @@
import javax.swing.event.MouseInputAdapter;
import javax.swing.event.MouseInputListener;
+import org.junit.jupiter.api.BeforeEach;
import vavi.sound.pcm.equalizing.sse.Equalizer.Parameter;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static vavi.sound.SoundUtil.volume;
@@ -42,21 +46,31 @@
* @author Naohide Sano (nsano)
* @version 0.00 060419 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
public class Test2 {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
String inFile;
String outFile = "tmp/out.vavi.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
/** */
public static void main(String[] args) throws Exception {
System.setOut(new PrintStream("NUL")); // shut fuckin' j-ogg's mouth
- new Test2();
+ Test2 app = new Test2();
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(app);
+ }
+ app.exec();
}
/** */
- Test2() throws Exception {
+ void exec() throws Exception {
Properties props = new Properties();
props.load(EqualizerTest.class.getResourceAsStream("/vavi/sound/pcm/equalizing/sse/local.properties"));
inFile = props.getProperty("equalizer.in.wav");
diff --git a/src/test/java/vavi/sound/pcm/resampling/laoe/ResamplerTest.java b/src/test/java/vavi/sound/pcm/resampling/laoe/ResamplerTest.java
index cd24980..26cc509 100644
--- a/src/test/java/vavi/sound/pcm/resampling/laoe/ResamplerTest.java
+++ b/src/test/java/vavi/sound/pcm/resampling/laoe/ResamplerTest.java
@@ -14,6 +14,7 @@
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.logging.Level;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
@@ -23,10 +24,14 @@
import javax.sound.sampled.SourceDataLine;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import vavi.util.ByteUtil;
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static vavi.sound.SoundUtil.volume;
@@ -38,12 +43,25 @@
* @author Naohide Sano (nsano)
* @version 0.00 060125 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
class ResamplerTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
static final String inFile = "src/test/resources/test.wav";
static final String outFile = "tmp/out.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
+ @BeforeEach
+ void setupEach() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
@BeforeAll
static void setup() throws IOException {
@@ -51,6 +69,7 @@ static void setup() throws IOException {
}
@Test
+ @DisplayName("direct")
void test1() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -127,6 +146,7 @@ void test1() throws Exception {
}
@Test
+ @DisplayName("via filer input stream")
void test2() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -168,7 +188,7 @@ void test2() throws Exception {
if (l < 0)
break;
line.write(buf, 0, l);
-Debug.println("line.write: " + l);
+Debug.println(Level.FINER, "line.write: " + l);
}
line.drain();
line.stop();
diff --git a/src/test/java/vavi/sound/pcm/resampling/rohm/ResamplerTest.java b/src/test/java/vavi/sound/pcm/resampling/rohm/ResamplerTest.java
index f7bdc43..71f6560 100644
--- a/src/test/java/vavi/sound/pcm/resampling/rohm/ResamplerTest.java
+++ b/src/test/java/vavi/sound/pcm/resampling/rohm/ResamplerTest.java
@@ -11,6 +11,9 @@
import java.io.File;
import java.io.InputStream;
import java.nio.ByteOrder;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.logging.Level;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
@@ -19,10 +22,14 @@
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import vavi.util.ByteUtil;
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static vavi.sound.SoundUtil.volume;
@@ -34,14 +41,28 @@
* @author Naohide Sano (nsano)
* @version 0.00 060125 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
class ResamplerTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
static final String inFile = "src/test/resources/test.wav";
static final String outFile = "tmp/out.wav";
- static float volume = Float.parseFloat(System.getProperty("vavi.test.volume", "0.2f"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
+ @BeforeEach
+ void setupEach() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
@Test
+ @DisplayName("direct")
void test1() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -118,6 +139,7 @@ void test1() throws Exception {
}
@Test
+ @DisplayName("via filer input stream")
void test2() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -159,7 +181,7 @@ void test2() throws Exception {
if (l < 0)
break;
line.write(buf, 0, l);
-Debug.println("line.write: " + l);
+Debug.println(Level.FINER, "line.write: " + l);
}
line.drain();
line.stop();
diff --git a/src/test/java/vavi/sound/pcm/resampling/sox/PerfectResamplerTest.java b/src/test/java/vavi/sound/pcm/resampling/sox/PerfectResamplerTest.java
index f175a44..ea34e3a 100644
--- a/src/test/java/vavi/sound/pcm/resampling/sox/PerfectResamplerTest.java
+++ b/src/test/java/vavi/sound/pcm/resampling/sox/PerfectResamplerTest.java
@@ -11,6 +11,8 @@
import java.io.File;
import java.io.InputStream;
import java.nio.ByteOrder;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
@@ -19,11 +21,15 @@
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import vavi.util.ByteUtil;
import vavi.util.Debug;
import vavi.util.StringUtil;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static vavi.sound.SoundUtil.volume;
@@ -36,14 +42,28 @@
* @version 0.00 081029 nsano initial version
* @see "rate.c"
*/
+@PropsEntity(url = "file:local.properties")
class PerfectResamplerTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
static String inFile = "src/test/resources/test.wav";
static String outFile = "tmp/out.vavi.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
+ @BeforeEach
+ void setupEach() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
@Test
+ @DisplayName("direct")
void test1() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
diff --git a/src/test/java/vavi/sound/pcm/resampling/sox/PolyphaseTest.java b/src/test/java/vavi/sound/pcm/resampling/sox/PolyphaseTest.java
index 8adda29..635db59 100644
--- a/src/test/java/vavi/sound/pcm/resampling/sox/PolyphaseTest.java
+++ b/src/test/java/vavi/sound/pcm/resampling/sox/PolyphaseTest.java
@@ -25,12 +25,16 @@
import javax.sound.sampled.SourceDataLine;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import vavi.util.ByteUtil;
import vavi.util.Debug;
import vavi.util.StringUtil;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static vavi.sound.SoundUtil.volume;
@@ -42,20 +46,34 @@
* @author Naohide Sano (nsano)
* @version 0.00 060203 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
public class PolyphaseTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
static String inFile = "src/test/resources/test.wav";
static String outFile = "tmp/out.vavi.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
@BeforeAll
static void setup() throws IOException {
Files.createDirectories(Paths.get("tmp"));
}
+ @BeforeEach
+ void setupEach() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
+
@Test
@Disabled
+ @DisplayName("multiple assigning separated by comma")
void test0() {
int i = 1, j = 2;
assertEquals(1, i);
@@ -262,7 +280,7 @@ public void test3() throws Exception {
if (l < 0)
break;
line.write(buf, 0, l);
-Debug.println(Level.FINE, "line.write: " + l);
+Debug.println(Level.FINER, "line.write: " + l);
}
line.drain();
line.stop();
@@ -273,6 +291,7 @@ public void test3() throws Exception {
@Test
@Disabled
+ @DisplayName("via spi")
public void test4() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -308,7 +327,7 @@ public void test4() throws Exception {
if (r < 0)
break;
line.write(buf, 0, r);
-//Debug.println("line: " + r);
+//Debug.println(Level.FINER, "line: " + r);
}
line.drain();
line.stop();
diff --git a/src/test/java/vavi/sound/pcm/resampling/sox/ResamplerTest.java b/src/test/java/vavi/sound/pcm/resampling/sox/ResamplerTest.java
index 382d41f..7fe553b 100644
--- a/src/test/java/vavi/sound/pcm/resampling/sox/ResamplerTest.java
+++ b/src/test/java/vavi/sound/pcm/resampling/sox/ResamplerTest.java
@@ -25,11 +25,15 @@
import javax.sound.sampled.SourceDataLine;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import vavi.util.ByteUtil;
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static vavi.sound.SoundUtil.volume;
@@ -41,20 +45,34 @@
* @author Naohide Sano (nsano)
* @version 0.00 060203 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
public class ResamplerTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
static String inFile = "src/test/resources/test.wav";
static String outFile = "tmp/out.vavi.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
@BeforeAll
static void setup() throws IOException {
Files.createDirectories(Paths.get("tmp"));
}
+ @BeforeEach
+ void setupEach() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
+
@Test
@Disabled
+ @DisplayName("direct")
public void test1() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -145,6 +163,7 @@ public void test1() throws Exception {
// noisy
@Test
@Disabled
+ @DisplayName("via filer input stream")
public void test2() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -186,7 +205,7 @@ public void test2() throws Exception {
if (l < 0)
break;
line.write(buf, 0, l);
-Debug.println(Level.FINE, "line.write: " + l);
+Debug.println(Level.FINER, "line.write: " + l);
}
line.drain();
line.stop();
@@ -196,6 +215,7 @@ public void test2() throws Exception {
}
@Test
+ @DisplayName("via filer input stream, monaural")
public void test3() throws Exception {
AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File(inFile));
AudioFormat format = sourceAis.getFormat();
@@ -204,7 +224,7 @@ public void test3() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// to monaural
int[] samples = new int[sourceAis.available() / format.getFrameSize()];
- Debug.println("samples: " + samples.length + ", frameSize: " + format.getFrameSize());
+Debug.println("samples: " + samples.length + ", frameSize: " + format.getFrameSize());
byte [] sample = new byte[format.getFrameSize()];
for (int i = 0; i < samples.length; i++) {
int r = sourceAis.read(sample);
@@ -243,7 +263,7 @@ public void test3() throws Exception {
if (l < 0)
break;
line.write(buf, 0, l);
-Debug.println(Level.FINE, "line.write: " + l);
+Debug.println(Level.FINER, "line.write: " + l);
}
line.drain();
line.stop();
diff --git a/src/test/java/vavi/sound/sampled/ilbc/IlbcFormatConversionProviderTest.java b/src/test/java/vavi/sound/sampled/ilbc/IlbcFormatConversionProviderTest.java
index f02f3d2..6115e10 100644
--- a/src/test/java/vavi/sound/sampled/ilbc/IlbcFormatConversionProviderTest.java
+++ b/src/test/java/vavi/sound/sampled/ilbc/IlbcFormatConversionProviderTest.java
@@ -17,6 +17,7 @@
import javax.sound.sampled.LineEvent.Type;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import vavi.util.Debug;
@@ -27,6 +28,12 @@
import static vavi.sound.SoundUtil.volume;
+/**
+ * IlbcFormatConversionProviderTest.
+ *
+ * @author Naohide Sano (nsano)
+ * @version 0.00 240905 nsano initial version
+ */
@PropsEntity(url = "file:local.properties")
class IlbcFormatConversionProviderTest {
@@ -37,6 +44,9 @@ static boolean localPropertiesExists() {
@Property(name = "ilbc")
String ilbc = "src/test/resources/ilbc/sample-30.ilbc";
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
@BeforeEach
void setup() throws Exception {
if (localPropertiesExists()) {
@@ -44,9 +54,8 @@ void setup() throws Exception {
}
}
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
-
@Test
+ @DisplayName("via spi clip")
@EnabledIfSystemProperty(named = "vavi.test", matches = "ide")
void test1() throws Exception {
Path in = Path.of(ilbc);
@@ -61,7 +70,7 @@ void test1() throws Exception {
8000,
false);
- AudioFormat linFormat = new AudioFormat(
+ AudioFormat lineFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
8000,
16,
@@ -69,13 +78,13 @@ void test1() throws Exception {
2,
8000,
false);
-Debug.println(linFormat);
+Debug.println(lineFormat);
var ais = new AudioInputStream(Files.newInputStream(in), inFormat, NOT_SPECIFIED);
Clip clip = AudioSystem.getClip();
CountDownLatch cdl = new CountDownLatch(1);
clip.addLineListener(e -> { Debug.println(e.getType()); if (e.getType().equals(Type.STOP)) cdl.countDown(); });
- clip.open(AudioSystem.getAudioInputStream(linFormat, ais));
+ clip.open(AudioSystem.getAudioInputStream(lineFormat, ais));
volume(clip, volume);
clip.start();
cdl.await();
diff --git a/src/test/java/vavi/sound/sampled/ldclep/LdCelpFormatConversionProviderTest.java b/src/test/java/vavi/sound/sampled/ldclep/LdCelpFormatConversionProviderTest.java
index fda0550..c91f893 100644
--- a/src/test/java/vavi/sound/sampled/ldclep/LdCelpFormatConversionProviderTest.java
+++ b/src/test/java/vavi/sound/sampled/ldclep/LdCelpFormatConversionProviderTest.java
@@ -17,6 +17,7 @@
import javax.sound.sampled.LineEvent.Type;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import vavi.util.Debug;
@@ -27,6 +28,12 @@
import static vavi.sound.SoundUtil.volume;
+/**
+ * LdCelpFormatConversionProviderTest.
+ *
+ * @author Naohide Sano (nsano)
+ * @version 0.00 240905 nsano initial version
+ */
@PropsEntity(url = "file:local.properties")
class LdCelpFormatConversionProviderTest {
@@ -37,6 +44,9 @@ static boolean localPropertiesExists() {
@Property(name = "g728")
String g728 = "src/test/resources/ldcelp/sample.g728";
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
@BeforeEach
void setup() throws Exception {
if (localPropertiesExists()) {
@@ -44,9 +54,8 @@ void setup() throws Exception {
}
}
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
-
@Test
+ @DisplayName("via spi clip")
@EnabledIfSystemProperty(named = "vavi.test", matches = "ide")
void test1() throws Exception {
Path in = Path.of(g728);
@@ -61,7 +70,7 @@ void test1() throws Exception {
16000,
false);
- AudioFormat linFormat = new AudioFormat(
+ AudioFormat lineFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
16000,
16,
@@ -69,13 +78,13 @@ void test1() throws Exception {
2,
16000,
false);
-Debug.println(linFormat);
+Debug.println(lineFormat);
var ais = new AudioInputStream(Files.newInputStream(in), inFormat, NOT_SPECIFIED);
Clip clip = AudioSystem.getClip();
CountDownLatch cdl = new CountDownLatch(1);
clip.addLineListener(e -> { Debug.println(e.getType()); if (e.getType().equals(Type.STOP)) cdl.countDown(); });
- clip.open(AudioSystem.getAudioInputStream(linFormat, ais));
+ clip.open(AudioSystem.getAudioInputStream(lineFormat, ais));
volume(clip, volume);
clip.start();
cdl.await();
diff --git a/src/test/java/vavi/sound/sampled/opl3/Opl3AudioFileReaderTest.java b/src/test/java/vavi/sound/sampled/opl3/Opl3AudioFileReaderTest.java
index 73ae1ed..6ff80b6 100644
--- a/src/test/java/vavi/sound/sampled/opl3/Opl3AudioFileReaderTest.java
+++ b/src/test/java/vavi/sound/sampled/opl3/Opl3AudioFileReaderTest.java
@@ -7,11 +7,12 @@
package vavi.sound.sampled.opl3;
import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;
-
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@@ -22,12 +23,14 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static vavi.sound.SoundUtil.volume;
import static vavix.util.DelayedWorker.later;
@@ -39,15 +42,31 @@
* @author Naohide Sano (umjammer)
* @version 0.00 2022/02/12 umjammer initial version
*/
+@PropsEntity(url = "file:local.properties")
class Opl3AudioFileReaderTest {
- static long time = System.getProperty("vavi.test", "").equals("ide") ? 1000 * 1000 : 10 * 1000;
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
+ static boolean onIde = System.getProperty("vavi.test", "").equals("ide");
+ static long time = onIde ? 1000 * 1000 : 10 * 1000;
@BeforeAll
static void setup() {
+ // enable opl3 midi player
System.setProperty("vavi.sound.opl3.MidiFile", "true");
+ }
+
+ @BeforeEach
+ void setupEach() throws IOException {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+
Debug.println("volume: " + volume);
}
@@ -94,17 +113,17 @@ void test0(String filename) throws Exception {
});
clip.open(audioInputStream);
try {
- volume(clip, volume);
+ volume(clip, volume);
} catch (Exception e) {
Debug.println("volume: " + e);
}
clip.start();
-if (!System.getProperty("vavi.test", "").equals("ide")) {
+if (!onIde) {
Thread.sleep(time);
clip.stop();
Debug.println("not on ide");
} else {
- countDownLatch.await();
+ countDownLatch.await();
}
clip.close();
}
@@ -123,7 +142,7 @@ void test0(String filename) throws Exception {
void test1(String filename) throws Exception {
Debug.println("------------------------------------------ " + filename + " ------------------------------------------------");
Path path = Paths.get(Opl3AudioFileReaderTest.class.getResource(filename).toURI());
- AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(Files.newInputStream(path)));
+ AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(Opl3AudioFileReaderTest.class.getResourceAsStream(filename)));
AudioFormat originalAudioFormat = originalAudioInputStream.getFormat();
Debug.println(originalAudioFormat);
AudioFormat targetAudioFormat = new AudioFormat(
@@ -152,7 +171,7 @@ void test1(String filename) throws Exception {
Debug.println("volume: " + e);
}
clip.start();
-if (!System.getProperty("vavi.test", "").equals("ide")) {
+if (!onIde) {
Thread.sleep(time);
clip.stop();
Debug.println("not on ide");
@@ -190,9 +209,9 @@ void test3(String flag) throws Exception {
volume(line, volume);
- byte[] buf = new byte[1024];
+ byte[] buf = new byte[line.getBufferSize()];
while (!later(time).come()) {
- int r = audioInputStream.read(buf, 0, 1024);
+ int r = audioInputStream.read(buf, 0, buf.length);
if (r < 0) {
break;
}
@@ -205,18 +224,19 @@ void test3(String flag) throws Exception {
@ParameterizedTest
@ValueSource(strings = {
-// "/opl3/dro_v2.dro",
-// "/opl3/samurai.dro",
-// "/opl3/ice_thnk.sci",
-// "/opl3/michaeld.cmf",
-// "/opl3/mi2.laa",
+ "/opl3/ice_thnk.sci",
+ "/opl3/dro_v2.dro",
+ "/opl3/samurai.dro",
+ "/opl3/michaeld.cmf",
+ "/opl3/mi2.laa",
"/opl3/2.cmf",
})
@DisplayName("spi, stream")
void test4(String filename) throws Exception {
Debug.println("------------------------------------------ " + filename + " ------------------------------------------------");
Path path = Paths.get(Opl3AudioFileReaderTest.class.getResource(filename).toURI());
- AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(Files.newInputStream(path)));
+ InputStream is = new BufferedInputStream(Files.newInputStream(path));
+ AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(is);
AudioFormat originalAudioFormat = originalAudioInputStream.getFormat();
Debug.println(originalAudioFormat);
AudioFormat targetAudioFormat = new AudioFormat(
@@ -235,9 +255,9 @@ void test4(String filename) throws Exception {
volume(line, volume);
- byte[] buf = new byte[1024];
+ byte[] buf = new byte[line.getBufferSize()];
while (!later(time).come()) {
- int r = audioInputStream.read(buf, 0, 1024);
+ int r = audioInputStream.read(buf, 0, buf.length);
if (r < 0) {
break;
}
diff --git a/src/test/java/vavi/sound/sampled/opus/OpusAudioPlayer.java b/src/test/java/vavi/sound/sampled/opus/OpusAudioPlayer.java
index 81fe26c..8e02994 100644
--- a/src/test/java/vavi/sound/sampled/opus/OpusAudioPlayer.java
+++ b/src/test/java/vavi/sound/sampled/opus/OpusAudioPlayer.java
@@ -59,7 +59,7 @@ public OpusAudioPlayer(Path audioFile) throws IOException {
private byte[] decode(byte[] packetData) throws OpusException {
int decodedSamples = decoder.decode(packetData, 0, packetData.length, decodeBuffer.array(), 0, BUFFER_SIZE, false);
if (decodedSamples < 0) {
- System.err.println("Decode error: " + decodedSamples);
+Debug.println("Decode error: " + decodedSamples);
decodeBuffer.clear();
return null;
}
diff --git a/src/test/java/vavi/sound/sampled/opus/OpusFormatConversionProviderTest.java b/src/test/java/vavi/sound/sampled/opus/OpusFormatConversionProviderTest.java
index b9f72cf..3eb236d 100644
--- a/src/test/java/vavi/sound/sampled/opus/OpusFormatConversionProviderTest.java
+++ b/src/test/java/vavi/sound/sampled/opus/OpusFormatConversionProviderTest.java
@@ -20,9 +20,12 @@
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -37,11 +40,24 @@
* @author Naohide Sano (umjammer)
* @version 0.00 2022/02/20 umjammer initial version
*/
+@PropsEntity(url = "file:local.properties")
class OpusFormatConversionProviderTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
static final String inFile = "/test.opus";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
+
+ @BeforeEach
+ void setup() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
@Test
@DisplayName("directly")
diff --git a/src/test/java/vavi/sound/sampled/opus/OpusTest.java b/src/test/java/vavi/sound/sampled/opus/OpusTest.java
index b4f65e6..72dc520 100644
--- a/src/test/java/vavi/sound/sampled/opus/OpusTest.java
+++ b/src/test/java/vavi/sound/sampled/opus/OpusTest.java
@@ -69,11 +69,11 @@ public static void main(String[] args) throws Exception {
file.close();
long end = System.currentTimeMillis();
- System.err.println(in + " -> " + out);
- System.err.println("Time was " + (end - start) + "ms");
+System.err.println(in + " -> " + out);
+System.err.println("Time was " + (end - start) + "ms");
is.close();
os.close();
- System.err.println("Done!");
+System.err.println("Done!");
}
static final String inFile = "src/test/resources/opus.raw";
@@ -104,11 +104,11 @@ public void test() throws Exception {
int bytesRead = fileIn.read(inBuf, 0, inBuf.length);
short[] pcm = bytesToShorts(inBuf, 0, bytesRead);
int bytesEncoded = encoder.encode(pcm, 0, packetSamples, dataPacket, 0, 1275);
-// System.out.println(bytesEncoded + " bytes encoded");
+//System.out.println(bytesEncoded + " bytes encoded");
@SuppressWarnings("unused")
int samplesDecoded = decoder.decode(dataPacket, 0, bytesEncoded, pcm, 0, packetSamples, false);
-// System.out.println(samplesDecoded + " samples decoded");
+//System.out.println(samplesDecoded + " samples decoded");
byte[] bytesOut = shortsToBytes(pcm);
fileOut.write(bytesOut, 0, bytesOut.length);
}
diff --git a/src/test/java/vavi/sound/sampled/resampling/SampleRateConversionProviderTest.java b/src/test/java/vavi/sound/sampled/resampling/SampleRateConversionProviderTest.java
index 2355e4c..ca962bb 100644
--- a/src/test/java/vavi/sound/sampled/resampling/SampleRateConversionProviderTest.java
+++ b/src/test/java/vavi/sound/sampled/resampling/SampleRateConversionProviderTest.java
@@ -20,10 +20,13 @@
import javax.sound.sampled.SourceDataLine;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import vavi.sound.sampled.MonauralInputFilter;
import vavi.util.Debug;
+import vavi.util.properties.annotation.Property;
+import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -36,22 +39,35 @@
* @author Naohide Sano (nsano)
* @version 0.00 060726 nsano initial version
*/
+@PropsEntity(url = "file:local.properties")
public class SampleRateConversionProviderTest {
+ static boolean localPropertiesExists() {
+ return Files.exists(Paths.get("local.properties"));
+ }
+
String inFile = "src/test/resources/test.wav";
String outFile = "tmp/out.wav";
- static double volume = Double.parseDouble(System.getProperty("vavi.test.volume", "0.2"));
+ @Property(name = "vavi.test.volume")
+ double volume = 0.2;
@BeforeAll
static void setup() throws IOException {
Files.createDirectories(Paths.get("tmp"));
}
+ @BeforeEach
+ void setupEach() throws Exception {
+ if (localPropertiesExists()) {
+ PropsEntity.Util.bind(this);
+ }
+ }
+
/**
*
*
→ mono requires tritonus_remaining_###.jar
- *
In eclipse, is the plugin working according to the jar ranking???
+ *
on eclipse, is the plugin working according to the jar ranking???
*