From 97df24ac529753f1e69fcd7c04621a42b83e9b67 Mon Sep 17 00:00:00 2001 From: Chad Gauthier Date: Tue, 11 Jun 2024 01:37:59 -0500 Subject: [PATCH] idk --- src/main/main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/main.cpp b/src/main/main.cpp index 30b6269..263f7eb 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -198,8 +198,12 @@ void queue_samples(int16_t* audio_data, size_t sample_count) { // swap buffer to correct for the address XOR caused by endianness handling. convert_and_swap_channels(audio_data, sample_count, swap_buffer); - // TODO handle cases where a chunk is smaller than the duplicated frame count. - assert(sample_count > duplicated_input_frames * input_channels); + // Handle cases where a chunk is smaller than the duplicated frame count. + if (sample_count <= duplicated_input_frames * input_channels) { + // Pad the chunk with silence. + memset(swap_buffer.data() + sample_count, 0, (duplicated_input_frames * input_channels - sample_count) * sizeof(float)); + sample_count = duplicated_input_frames * input_channels; + } // Copy the last converted samples into the duplicated sample buffer to reuse in resampling the next queued chunk. copy_last_samples(swap_buffer, sample_count, duplicated_sample_buffer);