Skip to content

Commit 964352e

Browse files
committed
Add option to disable sound modem receive
1 parent 320f1dc commit 964352e

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Hdlc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public boolean receive() throws IOException {
111111
int packetCrc = ((int)packetBytes[packetBytes.length - 2] & 0xff) | (((int)packetBytes[packetBytes.length - 1] & 0xff) << 8);
112112
//Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc);
113113
if (calculatedCrc == packetCrc) {
114-
Log.v(TAG, DebugTools.byteBitsToString(packetBits));
114+
//Log.v(TAG, DebugTools.byteBitsToString(packetBits));
115115
Log.i(TAG, "RX: " + DebugTools.bytesToHex(packetBytes));
116116
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, contentBytes);
117117
}
@@ -163,7 +163,7 @@ public byte[] hdlcEncode(byte[] dataSrc) {
163163
buffer.flip();
164164
byte[] data = new byte[buffer.remaining()];
165165
buffer.get(data);
166-
Log.i(TAG, "TX: " + DebugTools.bytesToHex(data));
166+
//Log.i(TAG, "TX: " + DebugTools.bytesToHex(data));
167167

168168
byte[] dataBytesAsBits = BitTools.convertToHDLCBitArray(data, true);
169169

codec2talkie/src/main/java/com/radio/codec2talkie/settings/PreferenceKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public final class PreferenceKeys {
1919

2020
public static String PORTS_SOUND_MODEM_TYPE = "ports_sound_modem_type";
2121
public static String PORTS_SOUND_MODEM_PREAMBLE = "ports_sound_modem_preamble";
22+
public static String PORTS_SOUND_MODEM_DISABLE_RX = "ports_sound_modem_disable_rx";
2223

2324
public static String CODEC2_MODE = "codec2_mode";
2425
public static String CODEC2_RECORDING_ENABLED = "codec2_recording_enabled";

codec2talkie/src/main/java/com/radio/codec2talkie/transport/SoundModem.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ public class SoundModem implements Transport, Runnable {
4848
private boolean _isRunning = true;
4949

5050
private final ByteBuffer _sampleBuffer;
51-
private final boolean _isLoopback = true;
51+
private final boolean _isLoopback = false;
5252

5353
private final long _fskModem;
5454

5555
public SoundModem(Context context) {
5656
_context = context;
5757
_sharedPreferences = PreferenceManager.getDefaultSharedPreferences(_context);
5858

59+
boolean disableRx = _sharedPreferences.getBoolean(PreferenceKeys.PORTS_SOUND_MODEM_DISABLE_RX, false);
5960
String type = _sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_TYPE, "1200");
6061
_name = "SoundModem" + type;
6162
if (type.equals("300")) {
@@ -71,17 +72,18 @@ public SoundModem(Context context) {
7172
_samplesPerSymbol = Codec2.fskSamplesPerSymbol(_fskModem);
7273
_bitBuffer = ByteBuffer.allocate(100 * _recordBitBuffer.length);
7374

74-
constructSystemAudioDevices();
75+
constructSystemAudioDevices(disableRx);
7576

7677
if (_isLoopback)
7778
_sampleBuffer = ByteBuffer.allocate(100000);
7879
else
7980
_sampleBuffer = ByteBuffer.allocate(0);
8081

81-
new Thread(this).start();
82+
if (!disableRx)
83+
new Thread(this).start();
8284
}
8385

84-
private void constructSystemAudioDevices() {
86+
private void constructSystemAudioDevices(boolean disableRx) {
8587
int audioRecorderMinBufferSize = AudioRecord.getMinBufferSize(
8688
SAMPLE_RATE,
8789
AudioFormat.CHANNEL_IN_MONO,
@@ -99,7 +101,8 @@ private void constructSystemAudioDevices() {
99101
SAMPLE_RATE,
100102
AudioFormat.CHANNEL_OUT_MONO,
101103
AudioFormat.ENCODING_PCM_16BIT);
102-
_systemAudioRecorder.startRecording();
104+
if (!disableRx)
105+
_systemAudioRecorder.startRecording();
103106

104107
int usage = AudioAttributes.USAGE_MEDIA;
105108
_systemAudioPlayer = new AudioTrack.Builder()
@@ -131,7 +134,7 @@ public int read(byte[] data) throws IOException {
131134
_bitBuffer.flip();
132135
int len = _bitBuffer.remaining();
133136
_bitBuffer.get(data, 0, len);
134-
Log.v(TAG, "read user: " + DebugTools.byteBitsToFlatString(data));
137+
//Log.v(TAG, "read user: " + DebugTools.byteBitsToFlatString(data));
135138
_bitBuffer.compact();
136139
return len;
137140
}
@@ -141,23 +144,23 @@ public int read(byte[] data) throws IOException {
141144

142145
@Override
143146
public int write(byte[] srcDataBytesAsBits) throws IOException {
144-
Log.v(TAG, "write " + DebugTools.byteBitsToFlatString(srcDataBytesAsBits));
147+
//Log.v(TAG, "write " + DebugTools.byteBitsToFlatString(srcDataBytesAsBits));
145148
byte[] dataBytesAsBits = BitTools.convertToNRZI(srcDataBytesAsBits);
146-
Log.v(TAG, "write NRZ " + DebugTools.byteBitsToFlatString(dataBytesAsBits));
147-
Log.v(TAG, "write NRZ " + DebugTools.byteBitsToString(dataBytesAsBits));
149+
//Log.v(TAG, "write NRZ " + DebugTools.byteBitsToFlatString(dataBytesAsBits));
150+
//Log.v(TAG, "write NRZ " + DebugTools.byteBitsToString(dataBytesAsBits));
148151

149152
int j = 0;
150153
for (int i = 0; i < dataBytesAsBits.length; i++, j++) {
151154
if (j >= _playbackBitBuffer.length) {
152155
Codec2.fskModulate(_fskModem, _playbackAudioBuffer, _playbackBitBuffer);
153-
Log.v(TAG, "write samples: " + DebugTools.shortsToHex(_playbackAudioBuffer));
156+
//Log.v(TAG, "write samples: " + DebugTools.shortsToHex(_playbackAudioBuffer));
154157
if (_isLoopback) {
155158
synchronized (_sampleBuffer) {
156159
for (short sample : _playbackAudioBuffer) {
157160
_sampleBuffer.putShort(sample);
158161
}
159162
}
160-
Log.v(TAG, "pos: " + _sampleBuffer.position() / 2);
163+
//Log.v(TAG, "pos: " + _sampleBuffer.position() / 2);
161164
} else {
162165
_systemAudioPlayer.write(_playbackAudioBuffer, 0, _playbackAudioBuffer.length);
163166
}
@@ -213,7 +216,7 @@ public void run() {
213216
}
214217
//Log.i(TAG, String.format("%04x", _recordAudioBuffer[0]));
215218
_sampleBuffer.compact();
216-
Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
219+
//Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
217220
} else {
218221
continue;
219222
}
@@ -223,14 +226,14 @@ public void run() {
223226
if (readCnt != nin) {
224227
Log.e(TAG, "" + readCnt + " != " + nin);
225228
}
226-
Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
229+
//Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
227230
}
228-
Log.v(TAG, "read audio power: " + AudioTools.getSampleLevelDb(Arrays.copyOf(_recordAudioBuffer, Codec2.fskNin(_fskModem))));
231+
//Log.v(TAG, "read audio power: " + AudioTools.getSampleLevelDb(Arrays.copyOf(_recordAudioBuffer, Codec2.fskNin(_fskModem))));
229232
//Log.v(TAG, readCnt + " " + _recordAudioBuffer.length + " " + Codec2.fskNin(_fskModem));
230233
Codec2.fskDemodulate(_fskModem, _recordAudioBuffer, _recordBitBuffer);
231234

232-
Log.v(TAG, "read NRZ " + DebugTools.byteBitsToFlatString(_recordBitBuffer));
233-
Log.v(TAG, "read " + DebugTools.byteBitsToFlatString(BitTools.convertFromNRZI(_recordBitBuffer, prevBit)));
235+
//Log.v(TAG, "read NRZ " + DebugTools.byteBitsToFlatString(_recordBitBuffer));
236+
//Log.v(TAG, "read " + DebugTools.byteBitsToFlatString(BitTools.convertFromNRZI(_recordBitBuffer, prevBit)));
234237
synchronized (_bitBuffer) {
235238
try {
236239
_bitBuffer.put(BitTools.convertFromNRZI(_recordBitBuffer, prevBit));

codec2talkie/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,6 @@
300300
<string name="ports_sound_modem_control_title">Sound modem settings</string>
301301
<string name="ports_sound_modem_control_settings">Set sound modem settings, such as bit rate</string>
302302
<string name="ports_type_title">TNC transport type</string>
303+
<string name="ports_sound_modem_disable_rx_title">Disable receive</string>
304+
<string name="ports_sound_modem_disable_rx_summary">Run modem in transmit only mode, receive is disabled to save CPU cycles</string>
303305
</resources>

codec2talkie/src/main/res/xml/preferences_sound_modem.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,12 @@
2222
app:defaultValue="200">
2323
</EditTextPreference>
2424

25+
<SwitchPreference
26+
app:key="ports_sound_modem_disable_rx"
27+
app:title="@string/ports_sound_modem_disable_rx_title"
28+
app:summary="@string/ports_sound_modem_disable_rx_summary"
29+
app:defaultValue="false">
30+
</SwitchPreference>
31+
2532
</PreferenceCategory>
2633
</PreferenceScreen>

0 commit comments

Comments
 (0)