@@ -48,14 +48,15 @@ public class SoundModem implements Transport, Runnable {
48
48
private boolean _isRunning = true ;
49
49
50
50
private final ByteBuffer _sampleBuffer ;
51
- private final boolean _isLoopback = true ;
51
+ private final boolean _isLoopback = false ;
52
52
53
53
private final long _fskModem ;
54
54
55
55
public SoundModem (Context context ) {
56
56
_context = context ;
57
57
_sharedPreferences = PreferenceManager .getDefaultSharedPreferences (_context );
58
58
59
+ boolean disableRx = _sharedPreferences .getBoolean (PreferenceKeys .PORTS_SOUND_MODEM_DISABLE_RX , false );
59
60
String type = _sharedPreferences .getString (PreferenceKeys .PORTS_SOUND_MODEM_TYPE , "1200" );
60
61
_name = "SoundModem" + type ;
61
62
if (type .equals ("300" )) {
@@ -71,17 +72,18 @@ public SoundModem(Context context) {
71
72
_samplesPerSymbol = Codec2 .fskSamplesPerSymbol (_fskModem );
72
73
_bitBuffer = ByteBuffer .allocate (100 * _recordBitBuffer .length );
73
74
74
- constructSystemAudioDevices ();
75
+ constructSystemAudioDevices (disableRx );
75
76
76
77
if (_isLoopback )
77
78
_sampleBuffer = ByteBuffer .allocate (100000 );
78
79
else
79
80
_sampleBuffer = ByteBuffer .allocate (0 );
80
81
81
- new Thread (this ).start ();
82
+ if (!disableRx )
83
+ new Thread (this ).start ();
82
84
}
83
85
84
- private void constructSystemAudioDevices () {
86
+ private void constructSystemAudioDevices (boolean disableRx ) {
85
87
int audioRecorderMinBufferSize = AudioRecord .getMinBufferSize (
86
88
SAMPLE_RATE ,
87
89
AudioFormat .CHANNEL_IN_MONO ,
@@ -99,7 +101,8 @@ private void constructSystemAudioDevices() {
99
101
SAMPLE_RATE ,
100
102
AudioFormat .CHANNEL_OUT_MONO ,
101
103
AudioFormat .ENCODING_PCM_16BIT );
102
- _systemAudioRecorder .startRecording ();
104
+ if (!disableRx )
105
+ _systemAudioRecorder .startRecording ();
103
106
104
107
int usage = AudioAttributes .USAGE_MEDIA ;
105
108
_systemAudioPlayer = new AudioTrack .Builder ()
@@ -131,7 +134,7 @@ public int read(byte[] data) throws IOException {
131
134
_bitBuffer .flip ();
132
135
int len = _bitBuffer .remaining ();
133
136
_bitBuffer .get (data , 0 , len );
134
- Log .v (TAG , "read user: " + DebugTools .byteBitsToFlatString (data ));
137
+ // Log.v(TAG, "read user: " + DebugTools.byteBitsToFlatString(data));
135
138
_bitBuffer .compact ();
136
139
return len ;
137
140
}
@@ -141,23 +144,23 @@ public int read(byte[] data) throws IOException {
141
144
142
145
@ Override
143
146
public int write (byte [] srcDataBytesAsBits ) throws IOException {
144
- Log .v (TAG , "write " + DebugTools .byteBitsToFlatString (srcDataBytesAsBits ));
147
+ // Log.v(TAG, "write " + DebugTools.byteBitsToFlatString(srcDataBytesAsBits));
145
148
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));
148
151
149
152
int j = 0 ;
150
153
for (int i = 0 ; i < dataBytesAsBits .length ; i ++, j ++) {
151
154
if (j >= _playbackBitBuffer .length ) {
152
155
Codec2 .fskModulate (_fskModem , _playbackAudioBuffer , _playbackBitBuffer );
153
- Log .v (TAG , "write samples: " + DebugTools .shortsToHex (_playbackAudioBuffer ));
156
+ // Log.v(TAG, "write samples: " + DebugTools.shortsToHex(_playbackAudioBuffer));
154
157
if (_isLoopback ) {
155
158
synchronized (_sampleBuffer ) {
156
159
for (short sample : _playbackAudioBuffer ) {
157
160
_sampleBuffer .putShort (sample );
158
161
}
159
162
}
160
- Log .v (TAG , "pos: " + _sampleBuffer .position () / 2 );
163
+ // Log.v(TAG, "pos: " + _sampleBuffer.position() / 2);
161
164
} else {
162
165
_systemAudioPlayer .write (_playbackAudioBuffer , 0 , _playbackAudioBuffer .length );
163
166
}
@@ -213,7 +216,7 @@ public void run() {
213
216
}
214
217
//Log.i(TAG, String.format("%04x", _recordAudioBuffer[0]));
215
218
_sampleBuffer .compact ();
216
- Log .v (TAG , "read samples: " + DebugTools .shortsToHex (_recordAudioBuffer ));
219
+ // Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
217
220
} else {
218
221
continue ;
219
222
}
@@ -223,14 +226,14 @@ public void run() {
223
226
if (readCnt != nin ) {
224
227
Log .e (TAG , "" + readCnt + " != " + nin );
225
228
}
226
- Log .v (TAG , "read samples: " + DebugTools .shortsToHex (_recordAudioBuffer ));
229
+ // Log.v(TAG, "read samples: " + DebugTools.shortsToHex(_recordAudioBuffer));
227
230
}
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))));
229
232
//Log.v(TAG, readCnt + " " + _recordAudioBuffer.length + " " + Codec2.fskNin(_fskModem));
230
233
Codec2 .fskDemodulate (_fskModem , _recordAudioBuffer , _recordBitBuffer );
231
234
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)));
234
237
synchronized (_bitBuffer ) {
235
238
try {
236
239
_bitBuffer .put (BitTools .convertFromNRZI (_recordBitBuffer , prevBit ));
0 commit comments