Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.19 #18

Merged
merged 8 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
build:

runs-on: macos-latest
runs-on: macos-13

steps:
- name: Checkout repository
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ A. yes you can, follow those steps
* on macos m2 ultra 1st pass is in a blink of an eye
* ~~`ima`, `ms` adpcm: wav reader~~
* ~~`tritonus:tritonus-remaining:org.tritonus.sampled.file.WaveAudioFileReader`~~
* use service provider for mfi, smaf sequencer
* service loader instead of vavi.properties

---
<sub>images by <a href="https://www.silhouette-illust.com/illust/49312">melody</a>, <a href="https://www.silhouette-illust.com/illust/257">cellphone</a></sub>
<sub>images by <a href="https://www.silhouette-illust.com/illust/49312">melody</a>, <a href="https://www.silhouette-illust.com/illust/257">cellphone</a></sub>
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-sound</artifactId>
<version>1.0.18</version>
<version>1.0.19</version>

<name>Vavi Sound API</name>
<url>https://github.com/umjammer/vavi-sound</url>
Expand Down Expand Up @@ -75,7 +75,7 @@ TODO
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.1.0</version>
<version>1.2.1</version>
<executions>
<execution>
<id>read-properties</id>
Expand Down Expand Up @@ -164,9 +164,9 @@ TODO
<configuration>
<argLine>
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
-Dvavi.test.dev.null=${dev.null}
-Dvavi.test.volume=${vavi.test.volume}
-Dvavi.test.volume.midi=${vavi.test.volume.midi}
-Dvavi.test.dev.null=@{dev.null}
-Dvavi.test.volume=@{vavi.test.volume}
-Dvavi.test.volume.midi=@{vavi.test.volume.midi}
-Dvavi.test.version=${project.version}
</argLine>
<trimStackTrace>false</trimStackTrace>
Expand Down Expand Up @@ -202,7 +202,7 @@ TODO
<dependency>
<groupId>com.github.umjammer</groupId> <!-- vavi / com.github.umjammer -->
<artifactId>vavi-commons</artifactId>
<version>1.1.12</version>
<version>1.1.13</version>
</dependency>
<dependency>
<groupId>com.github.umjammer</groupId>
Expand All @@ -223,7 +223,7 @@ TODO
<dependency>
<groupId>vavi</groupId>
<artifactId>vavi-sound-nda</artifactId>
<version>1.0.13</version>
<version>1.0.14</version>
<exclusions>
<exclusion>
<groupId>com.github.umjammer</groupId>
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ packages
* `vavi.sound.adpcm.ma`
* `vavi.sound.adpcm.vox`

着声に使用される ADPCM コーデックを取り扱うパッケージ群です。
Java の標準 IO ({@link java.io.InputStream}/{@link java.io.OutputStream}) として実装されているため
取り扱いが容易でストリーミングも楽に行えます。
A group of packages that handle the ADPCM codec used for voice ringtone.
Because it is implemented as Java standard IO ({@link java.io.InputStream}/{@link java.io.OutputStream})
Easy to handle and stream easily.

### 2. MFi library

Expand All @@ -37,10 +37,10 @@ packages
* `vavi.sound.mfi.vavi`
* :

着メロライブラリの核となる部分です。MFi のファイル構造を取り扱い、MIDI 構造に変換する事が出来ます。
また MIDI から MFi への変換も可能です。基本的に {@link javax.sound.midi} パッケージと同じ構造をとっています。
機種依存データを扱うパッケージとして {@link vavi.sound.mfi.vavi.mitsubishi D社} と
{@link vavi.sound.mfi.vavi.nec N社} がサンプル実装されています。
This is the core part of the ringtone library. It can handle MFi file structures and convert them to MIDI structures.
It is also possible to convert from MIDI to MFi. It basically has the same structure as the {@link javax.sound.midi} package.
{@link vavi.sound.mfi.vavi.mitsubishi Company D} as a package that handles model-dependent data
{@link vavi.sound.mfi.vavi.nec Company N} has been implemented as a sample.

### 3. `javax.sound.midi.spi` implementation

Expand All @@ -49,10 +49,10 @@ packages
* `vavi.sound.midi`
* `vavi.sound.midi.mfi`

`javax.sound.midi.spi` の一実装として機能させるためのパッケージです。
This is a package to function as an implementation of `javax.sound.midi.spi`.
[SPI](http://java.sun.com/j2se/1.5.0/ja/docs/ja/guide/sound/programmer_guide/chapter1.html#111901)
仕様に従い登録すれば midi の一ファイル形式として MFi ファイルを
再生する事が可能になります。
If you register according to the specifications, you can use MFi files as a midi file format.
It will be possible to play it.

## How to

Expand Down
28 changes: 16 additions & 12 deletions src/main/java/vavi/sound/adpcm/AdpcmInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.nio.ByteOrder;

import javax.sound.sampled.AudioFormat;

import vavi.io.BitInputStream;
import vavi.io.BitOutputStream;
import vavi.util.Debug;

import static java.lang.System.getLogger;


/**
Expand All @@ -30,14 +32,16 @@
*/
public abstract class AdpcmInputStream extends FilterInputStream {

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

/** PCM format that #read() returns */
protected AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
protected final AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;

/** PCM byte order that #read() returns */
protected ByteOrder byteOrder;
protected final ByteOrder byteOrder;

/** decoder */
protected Codec decoder;
protected final Codec decoder;

/** */
protected abstract Codec getCodec();
Expand All @@ -52,13 +56,13 @@ public AdpcmInputStream(InputStream in, ByteOrder byteOrder, int bits, ByteOrder
super(new BitInputStream(in, bits, bitOrder));
this.byteOrder = byteOrder;
this.decoder = getCodec();
//Debug.println(this.in);
//logger.log(Level.DEBUG, this.in);
}

/** ADPCM (4bit) length */
@Override
public int available() throws IOException {
//Debug.println("0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0)));
//logger.log(Level.DEBUG, "0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0)));
// TODO "* 2" calc should be in bits?
return (in.available() * 2) + (rest ? 1 : 0);
}
Expand All @@ -73,26 +77,26 @@ public int available() throws IOException {
*/
@Override
public int read() throws IOException {
//Debug.println(in);
//logger.log(Level.DEBUG, in);
if (!rest) {
int adpcm = in.read();
//System.err.println("0: " + StringUtil.toHex2(adpcm));
//logger.log(Level.DEBUG, "0: " + StringUtil.toHex2(adpcm));
if (adpcm == -1) {
return -1;
}

current = decoder.decode(adpcm);

rest = true;
//System.err.println("1: " + StringUtil.toHex2(current & 0xff));
//logger.log(Level.DEBUG, "1: " + StringUtil.toHex2(current & 0xff));
if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) {
return (current & 0xff00) >> 8;
} else {
return current & 0xff;
}
} else {
rest = false;
//System.err.println("2: " + StringUtil.toHex2((current & 0xff00) >> 8));
//logger.log(Level.DEBUG, "2: " + StringUtil.toHex2((current & 0xff00) >> 8));
if (ByteOrder.BIG_ENDIAN.equals(byteOrder)) {
return current & 0xff;
} else {
Expand Down Expand Up @@ -130,7 +134,7 @@ public int read(byte[] b, int off, int len) throws IOException {
}
}
} catch (IOException e) {
Debug.printStackTrace(e);
logger.log(Level.ERROR, e.getMessage(), e);
}
return i;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/vavi/sound/adpcm/AdpcmOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
public abstract class AdpcmOutputStream extends FilterOutputStream {

/** PCM format for #write(int) */
protected AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
protected final AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;

/** PCM byte order for #write(int) */
protected ByteOrder byteOrder;
protected final ByteOrder byteOrder;

/** encoder */
protected Codec encoder;
protected final Codec encoder;

/** */
protected abstract Codec getCodec();
Expand All @@ -48,7 +48,7 @@ public AdpcmOutputStream(OutputStream out, ByteOrder byteOrder, int bits, ByteOr
super(new BitOutputStream(out, bits, bitOrder));
this.byteOrder = byteOrder;
this.encoder = getCodec();
//Debug.println(this.out);
//logger.log(Level.DEBUG, this.out);
}

/** remaining or not (having PCM L or H at least one side) */
Expand All @@ -74,7 +74,7 @@ public void write(int b) throws IOException {
current -= 0x10000;
}
}
//System.err.println("current: " + StringUtil.toHex4(current));
//logger.log(Level.DEBUG, "current: " + StringUtil.toHex4(current));
out.write(encoder.encode(current)); // BitOutputStream write 4bit

flushed = true;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/vavi/sound/adpcm/ccitt/G711.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
abstract class G711 implements Codec {

/** */
protected State state = new State();
protected final State state = new State();

/** */
protected AudioFormat.Encoding encoding = AudioFormat.Encoding.PCM_SIGNED;
Expand Down Expand Up @@ -346,16 +346,16 @@ protected int reconstruct(boolean sign, int dqln, int y) {
int dql = dqln + (y >> 2); // ADDA

if (dql < 0) {
// System.err.println("1: " + (sign ? -0x8000 : 0));
// logger.log(Level.DEBUG, "1: " + (sign ? -0x8000 : 0));
return sign ? -0x8000 : 0;
} else { // ANTILOG
// Integer part of log
int dex = (dql >> 7) & 15;
int dqt = 128 + (dql & 127);
// Reconstructed difference signal sample
int dq = (dqt << 7) >> (14 - dex);
// System.err.println("2: " + sign + ", " + dqln + ", " + y);
// System.err.println("-: " + (sign ? dq - 0x8000 : dq) + ", " + (dq - 0x8000) + ", " + dq);
// logger.log(Level.DEBUG, "2: " + sign + ", " + dqln + ", " + y);
// logger.log(Level.DEBUG, "-: " + (sign ? dq - 0x8000 : dq) + ", " + (dq - 0x8000) + ", " + dq);
return sign ? dq - 0x8000 : dq;
}
}
Expand All @@ -380,11 +380,11 @@ protected int quantize(int d, int y, int[] table, int size) {
//
// Magnitude of 'd'
int dqm = Math.abs(d);
// System.err.println("d:\t" + d);
// System.err.println("dqm:\t" + dqm);
// logger.log(Level.DEBUG, "d:\t" + d);
// logger.log(Level.DEBUG, "dqm:\t" + dqm);
// Integer part of base 2 log of 'd'
int exp = State.quan(dqm >> 1);
// System.err.println("exp:\t" + exp);
// logger.log(Level.DEBUG, "exp:\t" + exp);
// Fractional part of base 2 log
int mant = ((dqm << 7) >> exp) & 0x7f; // Fractional portion.
// Log of magnitude of 'd'
Expand Down Expand Up @@ -509,7 +509,7 @@ protected int adjustUlawTandem(int sr, int se, int y, int i, int sign, int[] qta
}
}

//-------------------------------------------------------------------------
// ----

/** */
public abstract int getEncodingBits();
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/vavi/sound/adpcm/ccitt/G721.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public int encode(int sl) {
} else if (AudioFormat.Encoding.ULAW.equals(encoding)) {
sl = ulaw2linear(sl) >> 2;
} else if (AudioFormat.Encoding.PCM_SIGNED.equals(encoding)) {
//System.err.println("---- " + ccc + " ----");
//logger.log(Level.DEBUG, "---- " + ccc + " ----");
//ccc++;
//System.err.println("sl:B:\t" + sl);
//logger.log(Level.DEBUG, "sl:B:\t" + sl);
sl >>= 2; // 14-bit dynamic range
//System.err.println("sl:A:\t" + sl);
//logger.log(Level.DEBUG, "sl:A:\t" + sl);
} else {
throw new IllegalArgumentException(encoding.toString());
}
Expand All @@ -109,8 +109,8 @@ public int encode(int sl) {
int sez = sezi >> 1;
int se = (sezi + state.getPolePredictor()) >> 1; // estimated signal

//System.err.println("sl:\t" + sl);
//System.err.println("se:\t" + se);
//logger.log(Level.DEBUG, "sl:\t" + sl);
//logger.log(Level.DEBUG, "se:\t" + se);
// SUBTA
int d = sl - se; // estimation difference

Expand Down Expand Up @@ -153,12 +153,12 @@ public int decode(int i) {
int sei = sezi + state.getPolePredictor();
int se = sei >> 1; // se = estimated signal

//System.err.println("---- (" + (ccc++) + ")");
//System.err.println("i:\t" + StringUtil.toHex2(i));
//System.err.println("sezi:\t" + sezi);
//System.err.println("sez:\t" + sez);
//System.err.println("sei:\t" + sei);
//System.err.println("se:\t" + se);
//logger.log(Level.DEBUG, "---- (" + (ccc++) + ")");
//logger.log(Level.DEBUG, "i:\t" + StringUtil.toHex2(i));
//logger.log(Level.DEBUG, "sezi:\t" + sezi);
//logger.log(Level.DEBUG, "sez:\t" + sez);
//logger.log(Level.DEBUG, "sei:\t" + sei);
//logger.log(Level.DEBUG, "se:\t" + se);

// MIX
int y = state.getStepSize(); // dynamic quantizer step size
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vavi/sound/adpcm/ccitt/G723_16.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class G723_16 extends G711 {
/**
* Comes from quantizer decision level tables (Table 7/G.726)
*/
private static int[] qtab_723_16 = { 261 };
private static final int[] qtab_723_16 = { 261 };

/**
* Encodes a linear PCM, A-law or u-law input sample and returns its 2-bit
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vavi/sound/adpcm/ccitt/G723_16InputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ protected Codec getCodec() {
public G723_16InputStream(InputStream in, ByteOrder byteOrder) {
super(in, byteOrder, 2, ByteOrder.LITTLE_ENDIAN);
((G723_16) decoder).setEncoding(encoding);
//Debug.println(this.in);
//logger.log(Level.DEBUG, this.in);
}

/** ADPCM (4bit) length */
@Override
public int available() throws IOException {
//Debug.println("0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0)));
//logger.log(Level.DEBUG, "0: " + in.available() + ", " + ((in.available() * 2) + (rest ? 1 : 0)));
return (in.available() * 4) + (rest ? 1 : 0); // TODO check * 4 ???
}
}
8 changes: 4 additions & 4 deletions src/main/java/vavi/sound/adpcm/ccitt/G723_24.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class G723_24 extends G711 {
* Maps G.723_24 code word to reconstructed scale factor normalized log
* magnitude values.
*/
private static int[] _dqlntab = {
private static final int[] _dqlntab = {
-2048, 135, 273, 373, 373, 273, 135, -2048
};

/** Maps G.723_24 code word to log of scale factor multiplier. */
private static int[] _witab = {
private static final int[] _witab = {
-128, 960, 4384, 18624, 18624, 4384, 960, -128
};

Expand All @@ -59,12 +59,12 @@ class G723_24 extends G711 {
* term averages are computed and then compared to give an indication
* how stationary (steady state) the signal is.
*/
private static int[] _fitab = {
private static final int[] _fitab = {
0, 0x200, 0x400, 0xE00, 0xE00, 0x400, 0x200, 0
};

/** */
private static int[] qtab_723_24 = { 8, 218, 331 };
private static final int[] qtab_723_24 = { 8, 218, 331 };

/**
* Encodes a linear PCM, A-law or u-law input sample and returns its 3-bit
Expand Down
Loading