Skip to content

Commit 37b6b70

Browse files
committed
Fix error with null sample handling in audiofilters.Distortion.
1 parent 1008dd5 commit 37b6b70

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

shared-module/audiofilters/Distortion.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,21 @@ audioio_get_buffer_result_t audiofilters_distortion_get_buffer(audiofilters_dist
256256
}
257257
}
258258

259-
// If we have a sample, filter it
260-
if (self->sample != NULL) {
259+
if (self->sample == NULL) {
260+
if (self->samples_signed) {
261+
memset(word_buffer, 0, length * (self->bits_per_sample / 8));
262+
} else {
263+
// For unsigned samples set to the middle which is "quiet"
264+
if (MP_LIKELY(self->bits_per_sample == 16)) {
265+
memset(word_buffer, 32768, length * (self->bits_per_sample / 8));
266+
} else {
267+
memset(hword_buffer, 128, length * (self->bits_per_sample / 8));
268+
}
269+
}
270+
271+
length = 0;
272+
} else {
273+
// we have a sample to play and apply effect
261274
// Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining
262275
uint32_t n = MIN(self->sample_buffer_length, length);
263276

0 commit comments

Comments
 (0)