Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error with NULL sample handling in audiofilters.Filter. #9787

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion shared-module/audiodelays/Echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
20 changes: 18 additions & 2 deletions shared-module/audiofilters/Filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,24 @@ 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)) {
uint16_t *uword_buffer = (uint16_t *)word_buffer;
while (length--) {
*uword_buffer++ = 32768;
}
} 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);

Expand Down