From 63c3e394d3efa37fa43723da1f7e922ca8080933 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 18:30:19 -0600 Subject: [PATCH 1/2] Fix error with NULL sample handling in `audiofilters.Filter`. --- shared-module/audiofilters/Filter.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 86edb6cb0418..47032fd46dfe 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -240,8 +240,21 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o } } - // If we have a sample, filter it - if (self->sample != NULL) { + if (self->sample == NULL) { + if (self->samples_signed) { + memset(word_buffer, 0, length * (self->bits_per_sample / 8)); + } else { + // For unsigned samples set to the middle which is "quiet" + if (MP_LIKELY(self->bits_per_sample == 16)) { + memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + } else { + memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); + } + } + + length = 0; + } else { + // we have a sample to play and filter // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining uint32_t n = MIN(self->sample_buffer_length, length); From 0aab00d7e571e3d2b882cf7da240d1bdcb4b4f1e Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 5 Nov 2024 08:41:23 -0600 Subject: [PATCH 2/2] Fix 16-bit unsigned integer silence within audio effects. --- shared-module/audiodelays/Echo.c | 5 ++++- shared-module/audiofilters/Filter.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 3f45162cb5e9..a0c34c6540d8 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -342,7 +342,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } else { // For unsigned samples set to the middle which is "quiet" if (MP_LIKELY(self->bits_per_sample == 16)) { - memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + uint16_t *uword_buffer = (uint16_t *)word_buffer; + while (length--) { + *uword_buffer++ = 32768; + } } else { memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); } diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 47032fd46dfe..d7ee30e8ea66 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -246,7 +246,10 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o } else { // For unsigned samples set to the middle which is "quiet" if (MP_LIKELY(self->bits_per_sample == 16)) { - memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + uint16_t *uword_buffer = (uint16_t *)word_buffer; + while (length--) { + *uword_buffer++ = 32768; + } } else { memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); }