if we get different frames than our own transmission setup, decode and play them anyway

This commit is contained in:
Thomas Göttgens 2022-12-11 23:12:00 +01:00
parent 44a33ed463
commit ab6a5a5e07

View File

@ -47,7 +47,7 @@ int Sine1KHz_index = 0;
void run_codec2(void* parameter)
{
// 4 bytes of header in each frame Kennung hex c0 de c2 plus the bitrate
// 4 bytes of header in each frame hex c0 de c2 plus the bitrate
memcpy(audioModule->tx_encode_frame,&audioModule->tx_header,sizeof(audioModule->tx_header));
while (true) {
@ -76,13 +76,29 @@ void run_codec2(void* parameter)
}
}
if (audioModule->radio_state == RadioState::rx) {
//Make a cycle to get each codec2 frame from the received frame
for (int i = 0; i < audioModule->rx_encode_frame_index; i += audioModule->encode_codec_size)
{
//Decode the codec2 frame
codec2_decode(audioModule->codec2, audioModule->output_buffer, audioModule->rx_encode_frame + i);
size_t bytesOut = 0;
i2s_write(I2S_PORT, &audioModule->output_buffer, audioModule->adc_buffer_size, &bytesOut, pdMS_TO_TICKS(500));
size_t bytesOut = 0;
if (memcmp(audioModule->rx_encode_frame, &audioModule->tx_header, sizeof(audioModule->tx_header)) == 0) {
// Make a cycle to get each codec2 frame from the received frame
for (int i = 4; i < audioModule->rx_encode_frame_index; i += audioModule->encode_codec_size)
{
//Decode the codec2 frame
codec2_decode(audioModule->codec2, audioModule->output_buffer, audioModule->rx_encode_frame + i);
i2s_write(I2S_PORT, &audioModule->output_buffer, audioModule->adc_buffer_size, &bytesOut, pdMS_TO_TICKS(500));
}
} else {
// if the buffer header does not match our own codec, make a temp decoding setup.
CODEC2* tmp_codec2 = codec2_create(audioModule->rx_encode_frame[3]);
codec2_set_lpc_post_filter(tmp_codec2, 1, 0, 0.8, 0.2);
int tmp_encode_codec_size = (codec2_bits_per_frame(tmp_codec2) + 7) / 8;
int tmp_adc_buffer_size = codec2_samples_per_frame(tmp_codec2);
// Make a cycle to get each codec2 frame from the received frame
for (int i = 4; i < audioModule->rx_encode_frame_index; i += tmp_encode_codec_size)
{
//Decode the codec2 frame
codec2_decode(tmp_codec2, audioModule->output_buffer, audioModule->rx_encode_frame + i);
i2s_write(I2S_PORT, &audioModule->output_buffer, tmp_adc_buffer_size, &bytesOut, pdMS_TO_TICKS(500));
}
codec2_destroy(tmp_codec2);
}
}
}