Skip to content

Commit a419d5d

Browse files
committed
apparently i forgot to compile in support for the other bitrates
1 parent d20580e commit a419d5d

File tree

5 files changed

+53
-58
lines changed

5 files changed

+53
-58
lines changed

app/src/main/java/com/atakmap/android/meshtastic/MeshtasticDropDownReceiver.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,16 @@ protected MeshtasticDropDownReceiver(final MapView mapView, final Context contex
220220
};
221221
mapView.addOnKeyListener(keyListener);
222222

223-
// Codec2 Recorder/Playback - get mode from preferences
224-
int codec2Mode = Integer.parseInt(prefs.getString("plugin_meshtastic_codec2_mode", "8"));
225-
c2 = Codec2.create(codec2Mode);
223+
// Codec2 Recorder/Playback - hardcoded to 700C for compatibility
224+
// NOTE: All devices must use the same codec mode for audio to work properly
225+
c2 = Codec2.create(Codec2.CODEC2_MODE_700C);
226+
if (c2 == 0) {
227+
Log.e(TAG, "Failed to create Codec2 with mode 700C");
228+
}
226229
c2FrameSize = Codec2.getBitsSize(c2);
227230
samplesBufSize = Codec2.getSamplesPerFrame(c2);
228231
recorderBuf = new short[samplesBufSize];
232+
Log.d(TAG, "Codec2 initialized with mode 700C, frame size: " + c2FrameSize + ", samples: " + samplesBufSize);
229233
}
230234

231235
private final Queue<byte[]> recordingQueue = new ConcurrentLinkedQueue<>();
@@ -657,13 +661,15 @@ public void reinitializeCodec() {
657661
}
658662
}
659663

660-
// Create new codec with current preference
661-
int codec2Mode = Integer.parseInt(prefs.getString("plugin_meshtastic_codec2_mode", "8"));
662-
c2 = Codec2.create(codec2Mode);
664+
// Create new codec - hardcoded to 700C for compatibility
665+
c2 = Codec2.create(Codec2.CODEC2_MODE_700C);
666+
if (c2 == 0) {
667+
Log.e(TAG, "Failed to create Codec2 with mode 700C");
668+
}
663669
c2FrameSize = Codec2.getBitsSize(c2);
664670
samplesBufSize = Codec2.getSamplesPerFrame(c2);
665671
recorderBuf = new short[samplesBufSize];
666-
Log.d(TAG, "Codec2 reinitialized with mode: " + codec2Mode);
672+
Log.d(TAG, "Codec2 reinitialized with mode 700C, frame size: " + c2FrameSize + ", samples: " + samplesBufSize);
667673
}
668674

669675
@Override

app/src/main/java/com/atakmap/android/meshtastic/MeshtasticMapComponent.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
461461
editor.putString("constantReportingRateUnreliable", rate);
462462
editor.putString("constantReportingRateReliable", rate);
463463
editor.apply();
464-
} else if (FileSystemUtils.isEquals(key, "plugin_meshtastic_codec2_mode")) {
465-
// Reinitialize codec when mode changes
466-
Log.d(TAG, "Codec2 mode changed, reinitializing codec");
467-
if (mr != null) {
468-
mr.reinitializeCodec();
469-
}
470-
if (ddr != null) {
471-
ddr.reinitializeCodec();
472-
}
473464
}
474465

475466
if (Constants.PREF_PLUGIN_EXTERNAL_GPS.equals(key)) {

app/src/main/java/com/atakmap/android/meshtastic/MeshtasticReceiver.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ public MeshtasticReceiver(MeshtasticExternalGPS meshtasticExternalGPS) {
148148
.setOngoing(false)
149149
.setContentIntent(appIntent);
150150

151-
// codec2 recorder/playback - get mode from preferences
152-
int codec2Mode = Integer.parseInt(prefs.getString("plugin_meshtastic_codec2_mode", "8"));
153-
this.c2 = Codec2.create(codec2Mode);
151+
// codec2 recorder/playback - hardcoded to 700C for compatibility
152+
// NOTE: All devices must use the same codec mode for audio to work properly
153+
this.c2 = Codec2.create(Codec2.CODEC2_MODE_700C);
154+
if (c2 == 0) {
155+
Log.e(TAG, "Failed to create Codec2 with mode 700C");
156+
}
154157
this.samplesBufSize = Codec2.getSamplesPerFrame(c2);
158+
Log.d(TAG, "Codec2 initialized with mode 700C, samples per frame: " + samplesBufSize);
155159
}
156160

157161
@Override
@@ -552,12 +556,12 @@ public short[] append(short[] a, short[] b) {
552556
return result;
553557
}
554558

555-
public static List<byte[]> extractChunks(byte[] byteArray) {
556-
int chunkSize = 4;
559+
public static List<byte[]> extractChunks(byte[] byteArray, int chunkSize) {
557560
List<byte[]> chunks = new ArrayList<>();
558561

559562
for (int i = 0; i < byteArray.length; i += chunkSize) {
560-
byte[] chunk = Arrays.copyOfRange(byteArray, i, i + chunkSize);
563+
int endIndex = Math.min(i + chunkSize, byteArray.length);
564+
byte[] chunk = Arrays.copyOfRange(byteArray, i, endIndex);
561565
chunks.add(chunk);
562566
}
563567

@@ -667,14 +671,20 @@ protected void receive(Intent intent) {
667671
if (audioPermissionGranted && (raw[0] & 0xFF) == 0xC2) {
668672
Log.d(TAG, "Received codec2 frame");
669673

670-
// skip 0xC2 from data and split into frames of size c2FrameSize, and decode/play
671-
List<byte[]> frames = extractChunks(slice(raw, 1, raw.length));
672-
Log.d(TAG, "Frames: " + frames.size());
674+
// skip 0xC2 from data and split into frames
675+
// 700C mode uses 8 bytes per frame
676+
int frameSize = Codec2.getBitsSize(c2);
677+
List<byte[]> frames = extractChunks(slice(raw, 1, raw.length), frameSize);
678+
Log.d(TAG, "Frames: " + frames.size() + ", frame size: " + frameSize);
673679

674680
for (byte[] frame : frames) {
675-
playbackBuf = new short[samplesBufSize];
676-
Codec2.decode(c2, playbackBuf, frame);
677-
playAudio(playbackBuf);
681+
if (frame.length == frameSize) {
682+
playbackBuf = new short[samplesBufSize];
683+
Codec2.decode(c2, playbackBuf, frame);
684+
playAudio(playbackBuf);
685+
} else {
686+
Log.w(TAG, "Skipping incomplete frame of size " + frame.length);
687+
}
678688
}
679689

680690
return;
@@ -1446,11 +1456,13 @@ public void reinitializeCodec() {
14461456
}
14471457
}
14481458

1449-
// Create new codec with current preference
1450-
int codec2Mode = Integer.parseInt(prefs.getString("plugin_meshtastic_codec2_mode", "8"));
1451-
this.c2 = Codec2.create(codec2Mode);
1459+
// Create new codec - hardcoded to 700C for compatibility
1460+
this.c2 = Codec2.create(Codec2.CODEC2_MODE_700C);
1461+
if (c2 == 0) {
1462+
Log.e(TAG, "Failed to create Codec2 with mode 700C");
1463+
}
14521464
this.samplesBufSize = Codec2.getSamplesPerFrame(c2);
1453-
Log.d(TAG, "Codec2 reinitialized with mode: " + codec2Mode);
1465+
Log.d(TAG, "Codec2 reinitialized with mode 700C, samples per frame: " + samplesBufSize);
14541466
}
14551467

14561468
/**

app/src/main/res/values/arrays.xml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,21 @@
1717
<item>1800</item>
1818
</string-array>
1919
<string-array name="codec2_modes">
20-
<item>3200 bps</item>
21-
<item>2400 bps</item>
22-
<item>1600 bps</item>
23-
<item>1400 bps</item>
24-
<item>1300 bps</item>
25-
<item>1200 bps</item>
26-
<item>700 bps</item>
20+
<item>700C bps (Recommended)</item>
2721
<item>700B bps</item>
28-
<item>700C bps (Default)</item>
29-
<item>WB (Wideband)</item>
22+
<item>700 bps</item>
23+
<item>1200 bps</item>
24+
<item>1300 bps</item>
25+
<item>1400 bps</item>
26+
<item>1600 bps</item>
3027
</string-array>
3128
<string-array name="codec2_mode_values">
32-
<item>0</item>
33-
<item>1</item>
34-
<item>2</item>
35-
<item>3</item>
36-
<item>4</item>
37-
<item>5</item>
38-
<item>6</item>
39-
<item>7</item>
4029
<item>8</item>
41-
<item>9</item>
30+
<item>7</item>
31+
<item>6</item>
32+
<item>5</item>
33+
<item>4</item>
34+
<item>3</item>
35+
<item>2</item>
4236
</string-array>
4337
</resources>

app/src/main/res/xml/preferences.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@
6565
android:summary="If enabled, TTS will be used on Meshtastic text messages"
6666
android:dialogTitle="Use Text to Speech for incoming messages"
6767
android:defaultValue="false"/>
68-
<com.atakmap.android.gui.PanListPreference
69-
android:key="plugin_meshtastic_codec2_mode"
70-
android:title="Codec2 Voice Mode"
71-
android:summary="Select voice codec quality (lower bps = lower quality but better range)"
72-
android:dialogTitle="Codec2 Voice Mode"
73-
android:entries="@array/codec2_modes"
74-
android:entryValues="@array/codec2_mode_values"
75-
android:defaultValue="8"/>
7668
<com.atakmap.android.gui.PanEditTextPreference
7769
android:key="plugin_meshtastic_ptt"
7870
android:title="PTT KeyCode"

0 commit comments

Comments
 (0)