Skip to content

Commit 7e4b99a

Browse files
committed
Vocoder Fix
Based upon some LLM analysis, Claude did the following: Summary # Issue Verdict Action 1 Uninitialized error_history_sqrt Real bug (High) Fixed: initialized to 0.0 2 Uninitialized samples_buf Real bug (High) Fixed: added memset to zero buffer 3 uint16_t* type mismatch Real bug (Medium) Fixed: changed to int16_t* 4 uint32_t to int16_t truncation Low risk, defensive Fixed: added & 0xFFFF mask 5 Missing default in fr_type switch Real (Medium) Fixed: initialized fr_type = FT_4V_0 6 crc12 returns 0 on overflow Not practical Skipped — not an audio issue 7 msg_len uninitialized for 0x01/0x21 False positive — b1b2 is always 0 for those opcodes Added defensive init to 0 anyway 8 Loop variable shadowing Not a bug Skipped — cosmetic only The two highest-impact fixes for audio quality are Issue 1 (spike detection was comparing against garbage, making error tracking unreliable) and Issue 2 (stack garbage was being pushed directly to the audio output when frames had high error rates, producing pops/noise instead of silence).
1 parent 6c00945 commit 7e4b99a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

lib/op25_repeater/lib/p25p1_fdma.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ namespace gr {
873873
}
874874
double error_history_avg = error_history_total / error_history_len;
875875

876-
double error_history_sqrt;
876+
double error_history_sqrt = 0.0;
877877
for (int j=0; j<error_history_len; j++){
878878
error_history_sqrt += pow((error_history[j] - error_history_avg), 2);
879879
}
@@ -906,7 +906,7 @@ namespace gr {
906906
int16_t frame_vector[8];
907907

908908
for (int i=0; i < 8; i++) { // Ugh. For compatibility convert imbe params from uint32_t to int16_t
909-
frame_vector[i] = u[i];
909+
frame_vector[i] = u[i] & 0xFFFF;
910910
}
911911
frame_vector[7] >>= 1;
912912
vocoder.imbe_decode(frame_vector, snd);

lib/op25_repeater/lib/p25p2_tdma.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ void p25p2_tdma::decode_mac_msg(const uint8_t byte_buf[], const unsigned int len
394394
{
395395
std::string s;
396396
std::string pdu;
397-
uint8_t b1b2, mco, op, mfid, msg_ptr, msg_len, len_remaining;
397+
uint8_t b1b2, mco, op, mfid, msg_ptr, msg_len = 0, len_remaining;
398398
uint16_t colorcd;
399399

400400
colorcd = nac;
@@ -696,6 +696,7 @@ int p25p2_tdma::handle_acch_frame(const uint8_t dibits[], bool fast, bool is_lcc
696696
void p25p2_tdma::handle_voice_frame(const uint8_t dibits[], int slot, int voice_subframe)
697697
{
698698
int16_t samples_buf[IMBE_SAMPLES_PER_FRAME];
699+
memset(samples_buf, 0, sizeof(samples_buf));
699700
packed_codeword p_cw;
700701
bool audio_valid = !encrypted();
701702
int u[4];
@@ -704,7 +705,7 @@ void p25p2_tdma::handle_voice_frame(const uint8_t dibits[], int slot, int voice_
704705
int16_t snd;
705706
int K;
706707
int rc = -1;
707-
frame_type fr_type;
708+
frame_type fr_type = FT_4V_0;
708709

709710
// Deinterleave and figure out frame type:
710711
errs = vf.process_vcw(&errs_mp, dibits, b, u);

lib/op25_repeater/lib/vocoder_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ vocoder_impl::general_work_decode (int noutput_items,
118118

119119
consume_each (ninput_items[0]);
120120

121-
uint16_t *out = reinterpret_cast<uint16_t*>(output_items[0]);
121+
int16_t *out = reinterpret_cast<int16_t*>(output_items[0]);
122122
const int n = std::min(static_cast<int>(output_queue_decode.size()), noutput_items);
123123
if(0 < n) {
124124
copy(output_queue_decode.begin(), output_queue_decode.begin() + n, out);

0 commit comments

Comments
 (0)