kopia lustrzana https://github.com/sh123/codec2_talkie
OPUS fixes
rodzic
800af35e8f
commit
4b8321e425
|
@ -2,6 +2,7 @@ package com.radio.codec2talkie.protocol;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
@ -9,6 +10,7 @@ import androidx.preference.PreferenceManager;
|
|||
import com.radio.codec2talkie.protocol.message.TextMessage;
|
||||
import com.radio.codec2talkie.protocol.position.Position;
|
||||
import com.radio.codec2talkie.settings.PreferenceKeys;
|
||||
import com.radio.codec2talkie.tools.DebugTools;
|
||||
import com.radio.codec2talkie.transport.Transport;
|
||||
import com.radio.opus.Opus;
|
||||
|
||||
|
@ -24,7 +26,7 @@ public class AudioOpus implements Protocol {
|
|||
|
||||
private int _pcmFrameSize;
|
||||
|
||||
private char[] _recordAudioEncodedBuffer;
|
||||
private byte[] _recordAudioEncodedBuffer;
|
||||
private short[] _playbackAudioBuffer;
|
||||
|
||||
private ProtocolCallback _parentProtocolCallback;
|
||||
|
@ -51,7 +53,7 @@ public class AudioOpus implements Protocol {
|
|||
_audioBufferSize = 10*_pcmFrameSize;
|
||||
|
||||
_playbackAudioBuffer = new short[_audioBufferSize];
|
||||
_recordAudioEncodedBuffer = new char[superFrameSize];
|
||||
_recordAudioEncodedBuffer = new byte[superFrameSize];
|
||||
|
||||
_opusCon = Opus.create(SAMPLE_RATE, 1, Opus.OPUS_APPLICATION_VOIP, bitRate, complexity);
|
||||
if (_opusCon == 0) {
|
||||
|
@ -78,6 +80,7 @@ public class AudioOpus implements Protocol {
|
|||
@Override
|
||||
public void sendPcmAudio(String src, String dst, short[] pcmFrame) throws IOException {
|
||||
_parentProtocolCallback.onTransmitPcmAudio(src, dst, pcmFrame);
|
||||
Log.v(TAG, DebugTools.shortsToHex(pcmFrame));
|
||||
int encodedBytesCnt = Opus.encode(_opusCon, pcmFrame, _pcmFrameSize, _recordAudioEncodedBuffer);
|
||||
if (encodedBytesCnt == 0) {
|
||||
Log.w(TAG, "Nothing was encoded");
|
||||
|
@ -128,6 +131,7 @@ public class AudioOpus implements Protocol {
|
|||
short [] decodedSamples = new short[decodedSamplesCnt];
|
||||
if (decodedSamplesCnt > 0) {
|
||||
System.arraycopy(_playbackAudioBuffer, 0, decodedSamples, 0, decodedSamplesCnt);
|
||||
Log.v(TAG, DebugTools.shortsToHex(decodedSamples));
|
||||
} else {
|
||||
Log.e(TAG, "Decode error: " + decodedSamplesCnt);
|
||||
_parentProtocolCallback.onProtocolRxError();
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace Java_com_radio_opus_Opus {
|
|||
return samples;
|
||||
}
|
||||
|
||||
static jint encode(JNIEnv *env, jclass clazz, jlong n, jshortArray in, jint frames, jcharArray out)
|
||||
static jint encode(JNIEnv *env, jclass clazz, jlong n, jshortArray in, jint frames, jbyteArray out)
|
||||
{
|
||||
Context *con = getContext(n);
|
||||
OpusEncoder *encoder = con->encoder;
|
||||
|
@ -83,12 +83,12 @@ namespace Java_com_radio_opus_Opus {
|
|||
jint outputArraySize = env->GetArrayLength(out);
|
||||
|
||||
jshort* audioSignal = env->GetShortArrayElements(in, 0);
|
||||
jchar* encodedSignal = env->GetCharArrayElements(out, 0);
|
||||
jbyte* encodedSignal = env->GetByteArrayElements(out, 0);
|
||||
|
||||
int dataArraySize = opus_encode(encoder, audioSignal, frames, (unsigned char *)encodedSignal, outputArraySize);
|
||||
|
||||
env->ReleaseShortArrayElements(in, audioSignal, JNI_ABORT);
|
||||
env->ReleaseCharArrayElements(out, encodedSignal, 0);
|
||||
env->ReleaseByteArrayElements(out, encodedSignal, 0);
|
||||
|
||||
return dataArraySize;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ namespace Java_com_radio_opus_Opus {
|
|||
{"create", "(IIIII)J", (void *) create },
|
||||
{"destroy", "(J)I", (void *) destroy },
|
||||
{"decode", "(J[B[SI)I", (void *) decode },
|
||||
{"encode", "(J[SI[C)I", (void *) encode }
|
||||
{"encode", "(J[SI[B)I", (void *) encode }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -40,5 +40,5 @@ public class Opus {
|
|||
public native static int destroy(long con);
|
||||
|
||||
public native static int decode(long con, byte[] in, short[] out, int frames);
|
||||
public native static int encode(long con, short[] in, int frames, char[] out);
|
||||
public native static int encode(long con, short[] in, int frames, byte[] out);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue