diff options
author | Andrew Comminos <andrew@comminos.com> | 2015-11-13 07:41:22 +0300 |
---|---|---|
committer | Andrew Comminos <andrew@comminos.com> | 2015-11-13 07:41:22 +0300 |
commit | b0ae7d0d97ab6caf4644557d060badfa125f5e3b (patch) | |
tree | 1cd0b949fbc54736da3bf6d5123bd1217f844284 /src/main/java/com/morlunk | |
parent | 72e332183d09c0445e13ebe43c21cc6d51d3a444 (diff) |
Move CELT version fetching to static helper function.
Diffstat (limited to 'src/main/java/com/morlunk')
4 files changed, 29 insertions, 29 deletions
diff --git a/src/main/java/com/morlunk/jumble/Constants.java b/src/main/java/com/morlunk/jumble/Constants.java index 51a1af1..74242ff 100644 --- a/src/main/java/com/morlunk/jumble/Constants.java +++ b/src/main/java/com/morlunk/jumble/Constants.java @@ -17,35 +17,10 @@ package com.morlunk.jumble; -import com.googlecode.javacpp.IntPointer; -import com.googlecode.javacpp.Pointer; -import com.morlunk.jumble.audio.javacpp.CELT11; -import com.morlunk.jumble.audio.javacpp.CELT7; -import com.morlunk.jumble.protocol.AudioHandler; - +/** + * @deprecated Constant values should be associated with the class in which they are used. + */ public class Constants { - /** Set dynamically by JNI calls. */ - public static int CELT_11_VERSION ; - /** Set dynamically by JNI calls. */ - public static int CELT_7_VERSION; - - static { - // Load CELT bitstream versions from JNI. - Pointer celt11Mode = CELT11.celt_mode_create(AudioHandler.SAMPLE_RATE, AudioHandler.FRAME_SIZE, null); - Pointer celt7Mode = CELT7.celt_mode_create(AudioHandler.SAMPLE_RATE, AudioHandler.FRAME_SIZE, null); - - IntPointer celt11Version = new IntPointer(); - IntPointer celt7Version = new IntPointer(); - - CELT11.celt_mode_info(celt11Mode, CELT11.CELT_GET_BITSTREAM_VERSION, celt11Version); - CELT7.celt_mode_info(celt7Mode, CELT7.CELT_GET_BITSTREAM_VERSION, celt7Version); - CELT11.celt_mode_destroy(celt11Mode); - CELT7.celt_mode_destroy(celt7Mode); - - CELT_11_VERSION = celt11Version.get(); - CELT_7_VERSION = celt7Version.get(); - } - public static final int PROTOCOL_MAJOR = 1; public static final int PROTOCOL_MINOR = 2; public static final int PROTOCOL_PATCH = 5; diff --git a/src/main/java/com/morlunk/jumble/JumbleService.java b/src/main/java/com/morlunk/jumble/JumbleService.java index e9fd0c1..4c501e1 100644 --- a/src/main/java/com/morlunk/jumble/JumbleService.java +++ b/src/main/java/com/morlunk/jumble/JumbleService.java @@ -35,6 +35,7 @@ import android.util.Log; import com.morlunk.jumble.audio.AudioOutput; import com.morlunk.jumble.audio.BluetoothScoReceiver; +import com.morlunk.jumble.audio.javacpp.CELT7; import com.morlunk.jumble.exception.AudioException; import com.morlunk.jumble.exception.NotConnectedException; import com.morlunk.jumble.exception.NotSynchronizedException; @@ -303,7 +304,7 @@ public class JumbleService extends Service implements IJumbleService, JumbleConn final Mumble.Authenticate.Builder auth = Mumble.Authenticate.newBuilder(); auth.setUsername(mServer.getUsername()); auth.setPassword(mServer.getPassword()); - auth.addCeltVersions(Constants.CELT_7_VERSION); + auth.addCeltVersions(CELT7.getBitstreamVersion()); // FIXME: resolve issues with CELT 11 robot voices. // auth.addCeltVersions(Constants.CELT_11_VERSION); auth.setOpus(mUseOpus); diff --git a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java index 47c2cf8..b8e4ee4 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT11.java @@ -24,6 +24,7 @@ import com.googlecode.javacpp.annotation.Cast; import com.googlecode.javacpp.annotation.Platform; import com.morlunk.jumble.audio.IDecoder; import com.morlunk.jumble.exception.NativeAudioException; +import com.morlunk.jumble.protocol.AudioHandler; import java.nio.ByteBuffer; @@ -56,6 +57,17 @@ public class CELT11 { public static native int celt_encode(@Cast("CELTEncoder*") Pointer state, @Cast("const short*") short[] pcm, int frameSize, @Cast("unsigned char*") byte[] compressed, int maxCompressedBytes); public static native void celt_encoder_destroy(@Cast("CELTEncoder*") Pointer state); + /** + * @return an integer describing the CELT bitstream version. + */ + public static int getBitstreamVersion() { + IntPointer versionPtr = new IntPointer(); + Pointer modePtr = celt_mode_create(AudioHandler.SAMPLE_RATE, AudioHandler.FRAME_SIZE, null); + celt_mode_info(modePtr, CELT_GET_BITSTREAM_VERSION, versionPtr); + celt_mode_destroy(modePtr); + return versionPtr.get(); + } + public static class CELT11Decoder implements IDecoder { private Pointer mState; diff --git a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java index d51692a..bff4bed 100644 --- a/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java +++ b/src/main/java/com/morlunk/jumble/audio/javacpp/CELT7.java @@ -24,6 +24,7 @@ import com.googlecode.javacpp.annotation.Cast; import com.googlecode.javacpp.annotation.Platform; import com.morlunk.jumble.audio.IDecoder; import com.morlunk.jumble.exception.NativeAudioException; +import com.morlunk.jumble.protocol.AudioHandler; import java.nio.ByteBuffer; @@ -56,6 +57,17 @@ public class CELT7 { public static native int celt_encode(@Cast("CELTEncoder *") Pointer state, @Cast("const short *") short[] pcm, @Cast("short *") short[] optionalSynthesis, @Cast("unsigned char *") byte[] compressed, int nbCompressedBytes); public static native void celt_encoder_destroy(@Cast("CELTEncoder *") Pointer state); + /** + * @return an integer describing the CELT bitstream version. + */ + public static int getBitstreamVersion() { + IntPointer versionPtr = new IntPointer(); + Pointer modePtr = celt_mode_create(AudioHandler.SAMPLE_RATE, AudioHandler.FRAME_SIZE, null); + celt_mode_info(modePtr, CELT_GET_BITSTREAM_VERSION, versionPtr); + celt_mode_destroy(modePtr); + return versionPtr.get(); + } + public static class CELT7Decoder implements IDecoder { private Pointer mMode; |