diff --git a/codec2talkie/src/main/java/com/radio/codec2talkie/transport/SoundModem.java b/codec2talkie/src/main/java/com/radio/codec2talkie/transport/SoundModem.java index cff7e1a..7c00b3c 100644 --- a/codec2talkie/src/main/java/com/radio/codec2talkie/transport/SoundModem.java +++ b/codec2talkie/src/main/java/com/radio/codec2talkie/transport/SoundModem.java @@ -22,7 +22,7 @@ public class SoundModem implements Transport { private static final String TAG = SoundModem.class.getSimpleName(); - private static final int AUDIO_SAMPLE_SIZE = 48000; + private static final int AUDIO_SAMPLE_SIZE = 24000; private final String _name; @@ -79,7 +79,7 @@ public class SoundModem implements Transport { _systemAudioPlayer = new AudioTrack.Builder() .setAudioAttributes(new AudioAttributes.Builder() .setUsage(usage) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH) .build()) .setAudioFormat(new AudioFormat.Builder() .setEncoding(AudioFormat.ENCODING_PCM_16BIT) @@ -103,27 +103,35 @@ public class SoundModem implements Transport { public static byte[] toHdlcByteBitArray(byte[] data, boolean shouldBitStuff) { StringBuilder s = new StringBuilder(); + StringBuilder s2 = new StringBuilder(); ByteBuffer bitBuffer = ByteBuffer.allocate(512*8); int cntOnes = 0; for (int i = 0; i < 8 * data.length; i++) { - int b = data[i / 8]; - if ((b & (1 << (i % 8))) > 0) { + int b = ((int)data[i / 8]) & 0xff; + if ((b & (1 << (7 - (i % 8)))) > 0) { bitBuffer.put((byte)1); - s.append(1); + s.append('1'); if (shouldBitStuff) cntOnes += 1; } else { bitBuffer.put((byte)0); s.append(0); + cntOnes = 0; } if (shouldBitStuff && cntOnes == 5) { bitBuffer.put((byte)0); - s.append(0); + s.append('0'); cntOnes = 0; } + if (i % 8 == 3) s.append(':'); + if (i % 8 == 7) { + s.append(' '); + s2.append(String.format("%02x ", b)); + } } + Log.i(TAG, s2.toString()); Log.i(TAG, s.toString()); bitBuffer.flip(); diff --git a/libcodec2-android/src/main/cpp/Codec2JNI.cpp b/libcodec2-android/src/main/cpp/Codec2JNI.cpp index bcd829a..10061cf 100644 --- a/libcodec2-android/src/main/cpp/Codec2JNI.cpp +++ b/libcodec2-android/src/main/cpp/Codec2JNI.cpp @@ -60,7 +60,7 @@ namespace Java_com_ustadmobile_codec2_Codec2 { struct ContextFsk *conFsk; conFsk = (struct ContextFsk *) malloc(sizeof(struct ContextFsk)); struct FSK *fsk; - fsk = fsk_create(sampleFrequency, symbolRate, MODE_2FSK, toneFreq, toneSpacing); + fsk = fsk_create_hbr(sampleFrequency, symbolRate, MODE_2FSK, sampleFrequency/symbolRate, FSK_DEFAULT_NSYM, toneFreq, toneSpacing); conFsk->fsk = fsk; conFsk->Nbits = fsk->Nbits;