kopia lustrzana https://github.com/sh123/codec2_talkie
Add ability to pass gain
rodzic
cd15dcf3bc
commit
96e5b534a9
|
@ -39,9 +39,11 @@ public class Freedv implements Protocol {
|
|||
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
int mode = SettingsWrapper.getFreeDvSoundModemModulation(sharedPreferences);
|
||||
Log.i(TAG, "Using freedv mode " + AudioTools.getFreedvModeAsText(sharedPreferences));
|
||||
int gain = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_GAIN, "10000"));
|
||||
|
||||
_freedv = Codec2.freedvCreate(mode);
|
||||
Log.i(TAG, "Using freedv mode " + AudioTools.getFreedvModeAsText(sharedPreferences) + " gain " + gain);
|
||||
|
||||
_freedv = Codec2.freedvCreate(mode, gain);
|
||||
_modemTxBuffer = new short[Codec2.freedvGetNomModemSamples(_freedv)];
|
||||
_speechRxBuffer = new short[Codec2.freedvGetMaxSpeechSamples(_freedv)];
|
||||
}
|
||||
|
@ -77,12 +79,15 @@ public class Freedv implements Protocol {
|
|||
short[] buf = new short[nin];
|
||||
int bytesRead = _transport.read(buf);
|
||||
if (bytesRead == nin) {
|
||||
//Log.i(TAG, "read " + bytesRead);
|
||||
long cntRead = Codec2.freedvRx(_freedv, _speechRxBuffer, buf);
|
||||
if (cntRead > 0) {
|
||||
//Log.i(TAG, "receive " + cntRead);
|
||||
Log.i(TAG, "receive " + cntRead);
|
||||
_parentProtocolCallback.onReceivePcmAudio(null, null, -1, Arrays.copyOf(_speechRxBuffer, (int) cntRead));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
//Log.w(TAG, bytesRead + "!=" + nin);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import androidx.preference.PreferenceManager;
|
|||
import com.radio.codec2talkie.rigctl.RigCtl;
|
||||
import com.radio.codec2talkie.rigctl.RigCtlFactory;
|
||||
import com.radio.codec2talkie.settings.PreferenceKeys;
|
||||
import com.radio.codec2talkie.tools.DebugTools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.BufferOverflowException;
|
||||
|
@ -129,10 +130,10 @@ public class SoundModem implements Transport, Runnable {
|
|||
public int read(short[] audioSamples) throws IOException {
|
||||
synchronized (_recordAudioBuffer) {
|
||||
if (_recordAudioBuffer.position() >= audioSamples.length) {
|
||||
//Log.i(TAG, "read " + _recordAudioBuffer.position());
|
||||
_recordAudioBuffer.flip();
|
||||
_recordAudioBuffer.get(audioSamples);
|
||||
_recordAudioBuffer.compact();
|
||||
//Log.i(TAG, "read " + _recordAudioBuffer.position() + " " +audioSamples.length + " " + DebugTools.shortsToHex(audioSamples));
|
||||
return audioSamples.length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
|
|||
struct freedv *freeDv;
|
||||
short *speechSamples;
|
||||
short *modemSamples;
|
||||
int gain;
|
||||
};
|
||||
|
||||
static Context *getContext(jlong jp) {
|
||||
|
@ -97,10 +98,11 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
|
|||
return reinterpret_cast<jlong>(conFsk);
|
||||
}
|
||||
|
||||
static jlong freedvCreate(JNIEnv *env, jclass clazz, int mode) {
|
||||
static jlong freedvCreate(JNIEnv *env, jclass clazz, int mode, int gain) {
|
||||
struct ContextFreedv *conFreedv;
|
||||
conFreedv = (struct ContextFreedv *) malloc(sizeof(struct ContextFreedv));
|
||||
conFreedv->freeDv = freedv_open(mode);
|
||||
conFreedv->gain = gain;
|
||||
conFreedv->speechSamples = static_cast<short *>(malloc(
|
||||
freedv_get_n_max_speech_samples(conFreedv->freeDv) * sizeof(short)));
|
||||
conFreedv->modemSamples = static_cast<short *>(malloc(
|
||||
|
@ -270,6 +272,7 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
|
|||
ContextFreedv *conFreedv = getContextFreedv(n);
|
||||
int nin = freedv_nin(conFreedv->freeDv);
|
||||
env->GetShortArrayRegion(inputModemSamples, 0, nin, conFreedv->speechSamples);
|
||||
//int cntRead = freedv_shortrx(conFreedv->freeDv, conFreedv->modemSamples, conFreedv->speechSamples, conFreedv->gain);
|
||||
int cntRead = freedv_rx(conFreedv->freeDv, conFreedv->modemSamples, conFreedv->speechSamples);
|
||||
env->SetShortArrayRegion(outputSpeechSamples, 0, nin, conFreedv->modemSamples);
|
||||
return cntRead;
|
||||
|
@ -295,7 +298,7 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
|
|||
{"fskSamplesPerSymbol", "(J)I", (void *) fskSamplesPerSymbol},
|
||||
{"fskNin", "(J)I", (void *) fskNin},
|
||||
// freedv
|
||||
{"freedvCreate", "(I)J", (void *)freedvCreate},
|
||||
{"freedvCreate", "(II)J", (void *)freedvCreate},
|
||||
{"freedvDestroy", "(J)I", (void *)freedvDestroy},
|
||||
{"freedvGetMaxSpeechSamples", "(J)I", (void *)freedvGetMaxSpeechSamples},
|
||||
{"freedvGetMaxModemSamples", "(J)I", (void *)freedvGetMaxModemSamples},
|
||||
|
|
|
@ -57,7 +57,7 @@ public class Codec2 {
|
|||
public native static long fskDemodulate(long conFsk, short[] inputSamples, byte[] outputBits);
|
||||
|
||||
// freedv
|
||||
public native static long freedvCreate(int mode);
|
||||
public native static long freedvCreate(int mode, int gain);
|
||||
public native static int freedvDestroy(long conFreedv);
|
||||
|
||||
public native static int freedvGetMaxSpeechSamples(long conFreedv);
|
||||
|
|
Ładowanie…
Reference in New Issue