Progress on freedv

aprs
sh123 2022-08-10 22:46:43 +03:00
rodzic b475ace400
commit 635320987b
2 zmienionych plików z 31 dodań i 13 usunięć

Wyświetl plik

@ -5,66 +5,84 @@ import android.content.Context;
import com.radio.codec2talkie.protocol.message.TextMessage;
import com.radio.codec2talkie.protocol.position.Position;
import com.radio.codec2talkie.transport.Transport;
import com.ustadmobile.codec2.Codec2;
import java.io.IOException;
import java.util.Arrays;
public class Freedv implements Protocol {
private final int _freedvMode;
private final Protocol _childProtocol;
private ProtocolCallback _parentProtocolCallback;
private Transport _transport;
private long _freedv;
private short[] _modemTxBuffer;
private short[] _speechRxBuffer;
private short[] _modemRxBuffer;
public Freedv(Protocol childProtocol, int freedvMode) {
_childProtocol = childProtocol;
_freedvMode = freedvMode;
}
@Override
public void initialize(Transport transport, Context context, ProtocolCallback protocolCallback) throws IOException {
_parentProtocolCallback = protocolCallback;
public void initialize(Transport transport, Context context, ProtocolCallback parentProtocolCallback) throws IOException {
_transport = transport;
_parentProtocolCallback = parentProtocolCallback;
_childProtocol.initialize(transport, context, _parentProtocolCallback);
_freedv = Codec2.freedvCreate(_freedvMode);
_modemTxBuffer = new short[Codec2.freedvGetNomModemSamples(_freedv)];
_modemRxBuffer = new short[Codec2.freedvGetMaxModemSamples(_freedv)];
_speechRxBuffer = new short[Codec2.freedvGetMaxSpeechSamples(_freedv)];
}
@Override
public int getPcmAudioBufferSize() {
return 0;
return Codec2.freedvGetNSpeechSamples(_freedv);
}
@Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException {
Codec2.freedvTx(_freedv, _modemTxBuffer, pcmFrame);
// _transport.write(_modemTxBuffer);
}
@Override
public void sendCompressedAudio(String src, String dst, int codec, byte[] frame) throws IOException {
}
@Override
public void sendTextMessage(TextMessage textMessage) throws IOException {
}
@Override
public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
}
@Override
public boolean receive() throws IOException {
// int bytesRead = _transport.read(_modemRxBuffer);
long cntRead = Codec2.freedvRx(_freedv, _speechRxBuffer, _modemRxBuffer);
if (cntRead > 0) {
_parentProtocolCallback.onReceivePcmAudio(null, null, -1, Arrays.copyOf(_modemRxBuffer, (int) cntRead));
}
return false;
}
@Override
public void sendPosition(Position position) throws IOException {
}
@Override
public void flush() throws IOException {
}
@Override
public void close() {
Codec2.freedvDestroy(_freedv);
}
}

Wyświetl plik

@ -269,9 +269,9 @@ namespace Java_com_ustadmobile_codec2_Codec2 {
ContextFreedv *conFreedv = getContextFreedv(n);
int nin = freedv_nin(conFreedv->freeDv);
env->GetShortArrayRegion(inputModemSamples, 0, nin, conFreedv->speechSamples);
freedv_rx(conFreedv->freeDv, conFreedv->modemSamples, conFreedv->speechSamples);
int cntRead = freedv_rx(conFreedv->freeDv, conFreedv->modemSamples, conFreedv->speechSamples);
env->SetShortArrayRegion(outputSpeechSamples, 0, nin, conFreedv->modemSamples);
return nin;
return cntRead;
}
static JNINativeMethod method_table[] = {