kopia lustrzana https://github.com/sh123/codec2_talkie
rodzic
320f1dc152
commit
964352e81e
|
@ -111,7 +111,7 @@ public class Hdlc implements Protocol {
|
|||
int packetCrc = ((int)packetBytes[packetBytes.length - 2] & 0xff) | (((int)packetBytes[packetBytes.length - 1] & 0xff) << 8);
|
||||
//Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc);
|
||||
if (calculatedCrc == packetCrc) {
|
||||
Log.v(TAG, DebugTools.byteBitsToString(packetBits));
|
||||
//Log.v(TAG, DebugTools.byteBitsToString(packetBits));
|
||||
Log.i(TAG, "RX: " + DebugTools.bytesToHex(packetBytes));
|
||||
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, contentBytes);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public class Hdlc implements Protocol {
|
|||
buffer.flip();
|
||||
byte[] data = new byte[buffer.remaining()];
|
||||
buffer.get(data);
|
||||
Log.i(TAG, "TX: " + DebugTools.bytesToHex(data));
|
||||
//Log.i(TAG, "TX: " + DebugTools.bytesToHex(data));
|
||||
|
||||
byte[] dataBytesAsBits = BitTools.convertToHDLCBitArray(data, true);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ public final class PreferenceKeys {
|
|||
|
||||
public static String PORTS_SOUND_MODEM_TYPE = "ports_sound_modem_type";
|
||||
public static String PORTS_SOUND_MODEM_PREAMBLE = "ports_sound_modem_preamble";
|
||||
public static String PORTS_SOUND_MODEM_DISABLE_RX = "ports_sound_modem_disable_rx";
|
||||
|
||||
public static String CODEC2_MODE = "codec2_mode";
|
||||
public static String CODEC2_RECORDING_ENABLED = "codec2_recording_enabled";
|
||||
|
|
|
@ -48,7 +48,7 @@ public class SoundModem implements Transport, Runnable {
|
|||
private boolean _isRunning = true;
|
||||
|
||||
private final ByteBuffer _sampleBuffer;
|
||||
private final boolean _isLoopback = true;
|
||||
private final boolean _isLoopback = false;
|
||||
|
||||
private final long _fskModem;
|
||||
|
||||
|
@ -56,6 +56,7 @@ public class SoundModem implements Transport, Runnable {
|
|||
_context = context;
|
||||
_sharedPreferences = PreferenceManager.getDefaultSharedPreferences(_context);
|
||||
|
||||
boolean disableRx = _sharedPreferences.getBoolean(PreferenceKeys.PORTS_SOUND_MODEM_DISABLE_RX, false);
|
||||
String type = _sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_TYPE, "1200");
|
||||
_name = "SoundModem" + type;
|
||||
if (type.equals("300")) {
|
||||
|
@ -71,17 +72,18 @@ public class SoundModem implements Transport, Runnable {
|
|||
_samplesPerSymbol = Codec2.fskSamplesPerSymbol(_fskModem);
|
||||
_bitBuffer = ByteBuffer.allocate(100 * _recordBitBuffer.length);
|
||||
|
||||
constructSystemAudioDevices();
|
||||
constructSystemAudioDevices(disableRx);
|
||||
|
||||
if (_isLoopback)
|
||||
_sampleBuffer = ByteBuffer.allocate(100000);
|
||||
else
|
||||
_sampleBuffer = ByteBuffer.allocate(0);
|
||||
|
||||
new Thread(this).start();
|
||||
if (!disableRx)
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
private void constructSystemAudioDevices() {
|
||||
private void constructSystemAudioDevices(boolean disableRx) {
|
||||
int audioRecorderMinBufferSize = AudioRecord.getMinBufferSize(
|
||||
SAMPLE_RATE,
|
||||
AudioFormat.CHANNEL_IN_MONO,
|
||||
|
@ -99,7 +101,8 @@ public class SoundModem implements Transport, Runnable {
|
|||
SAMPLE_RATE,
|
||||
AudioFormat.CHANNEL_OUT_MONO,
|
||||
AudioFormat.ENCODING_PCM_16BIT);
|
||||
_systemAudioRecorder.startRecording();
|
||||
if (!disableRx)
|
||||
_systemAudioRecorder.startRecording();
|
||||
|
||||
int usage = AudioAttributes.USAGE_MEDIA;
|
||||
_systemAudioPlayer = new AudioTrack.Builder()
|
||||
|
@ -131,7 +134,7 @@ public class SoundModem implements Transport, Runnable {
|
|||
_bitBuffer.flip();
|
||||
int len = _bitBuffer.remaining();
|
||||
_bitBuffer.get(data, 0, len);
|
||||
Log.v(TAG, "read user: " + DebugTools.byteBitsToFlatString(data));
|
||||
//Log.v(TAG, "read user: " + DebugTools.byteBitsToFlatString(data));
|
||||
_bitBuffer.compact();
|
||||
return len;
|
||||
}
|
||||
|
@ -141,23 +144,23 @@ public class SoundModem implements Transport, Runnable {
|
|||
|
||||
@Override
|
||||
public int write(byte[] srcDataBytesAsBits) throws IOException {
|
||||
Log.v(TAG, "write " + DebugTools.byteBitsToFlatString(srcDataBytesAsBits));
|
||||
//Log.v(TAG, "write " + DebugTools.byteBitsToFlatString(srcDataBytesAsBits));
|
||||
byte[] dataBytesAsBits = BitTools.convertToNRZI(srcDataBytesAsBits);
|
||||
Log.v(TAG, "write NRZ " + DebugTools.byteBitsToFlatString(dataBytesAsBits));
|
||||
Log.v(TAG, "write NRZ " + DebugTools.byteBitsToString(dataBytesAsBits));
|
||||
//Log.v(TAG, "write NRZ " + DebugTools.byteBitsToFlatString(dataBytesAsBits));
|
||||
//Log.v(TAG, "write NRZ " + DebugTools.byteBitsToString(dataBytesAsBits));
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < dataBytesAsBits.length; i++, j++) {
|
||||
if (j >= _playbackBitBuffer.length) {
|
||||
Codec2.fskModulate(_fskModem, _playbackAudioBuffer, _playbackBitBuffer);
|
||||
Log.v(TAG, "write samples: " + DebugTools.shortsToHex(_playbackAudioBuffer));
|
||||
//Log.v(TAG, "write samples: " + DebugTools.shortsToHex(_playbackAudioBuffer));
|
||||
if (_isLoopback) {
|
||||
synchronized (_sampleBuffer) {
|
||||
for (short sample : _playbackAudioBuffer) {
|
||||
_sampleBuffer.putShort(sample);
|
||||
}
|
||||
}
|
||||
Log.v(TAG, "pos: " + _sampleBuffer.position() / 2);
|
||||
//Log.v(TAG, "pos: " + _sampleBuffer.position() / 2);
|
||||
} else {
|
||||
_systemAudioPlayer.write(_playbackAudioBuffer, 0, _playbackAudioBuffer.length);
|
||||
}
|
||||
|
@ -213,7 +216,7 @@ public class SoundModem implements Transport, Runnable {
|
|||
}
|
||||
//Log.i(TAG, String.format("%04x", _recordAudioBuffer[0]));
|
||||
_sampleBuffer.compact();
|
||||
Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
|
||||
//Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -223,14 +226,14 @@ public class SoundModem implements Transport, Runnable {
|
|||
if (readCnt != nin) {
|
||||
Log.e(TAG, "" + readCnt + " != " + nin);
|
||||
}
|
||||
Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
|
||||
//Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
|
||||
}
|
||||
Log.v(TAG, "read audio power: " + AudioTools.getSampleLevelDb(Arrays.copyOf(_recordAudioBuffer, Codec2.fskNin(_fskModem))));
|
||||
//Log.v(TAG, "read audio power: " + AudioTools.getSampleLevelDb(Arrays.copyOf(_recordAudioBuffer, Codec2.fskNin(_fskModem))));
|
||||
//Log.v(TAG, readCnt + " " + _recordAudioBuffer.length + " " + Codec2.fskNin(_fskModem));
|
||||
Codec2.fskDemodulate(_fskModem, _recordAudioBuffer, _recordBitBuffer);
|
||||
|
||||
Log.v(TAG, "read NRZ " + DebugTools.byteBitsToFlatString(_recordBitBuffer));
|
||||
Log.v(TAG, "read " + DebugTools.byteBitsToFlatString(BitTools.convertFromNRZI(_recordBitBuffer, prevBit)));
|
||||
//Log.v(TAG, "read NRZ " + DebugTools.byteBitsToFlatString(_recordBitBuffer));
|
||||
//Log.v(TAG, "read " + DebugTools.byteBitsToFlatString(BitTools.convertFromNRZI(_recordBitBuffer, prevBit)));
|
||||
synchronized (_bitBuffer) {
|
||||
try {
|
||||
_bitBuffer.put(BitTools.convertFromNRZI(_recordBitBuffer, prevBit));
|
||||
|
|
|
@ -300,4 +300,6 @@
|
|||
<string name="ports_sound_modem_control_title">Sound modem settings</string>
|
||||
<string name="ports_sound_modem_control_settings">Set sound modem settings, such as bit rate</string>
|
||||
<string name="ports_type_title">TNC transport type</string>
|
||||
<string name="ports_sound_modem_disable_rx_title">Disable receive</string>
|
||||
<string name="ports_sound_modem_disable_rx_summary">Run modem in transmit only mode, receive is disabled to save CPU cycles</string>
|
||||
</resources>
|
|
@ -22,5 +22,12 @@
|
|||
app:defaultValue="200">
|
||||
</EditTextPreference>
|
||||
|
||||
<SwitchPreference
|
||||
app:key="ports_sound_modem_disable_rx"
|
||||
app:title="@string/ports_sound_modem_disable_rx_title"
|
||||
app:summary="@string/ports_sound_modem_disable_rx_summary"
|
||||
app:defaultValue="false">
|
||||
</SwitchPreference>
|
||||
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
Ładowanie…
Reference in New Issue