Commit 5b11d5a3 authored by Max Kellermann's avatar Max Kellermann

pcm_utils: always round up resampling buffer size

libsamplerate produces cracks in the sound output when the destination buffer is too small. This is the case when pcm_convert_size() rounds down. Use ceil(x) instead of floor(0.5+x) there to prevent a buffer overrun.
parent 0128a9e9
...@@ -461,7 +461,7 @@ size_t pcm_convert_size(const struct audio_format *inFormat, size_t src_size, ...@@ -461,7 +461,7 @@ size_t pcm_convert_size(const struct audio_format *inFormat, size_t src_size,
assert((src_size % audio_format_frame_size(inFormat)) == 0); assert((src_size % audio_format_frame_size(inFormat)) == 0);
dest_size /= audio_format_frame_size(inFormat); dest_size /= audio_format_frame_size(inFormat);
dest_size = floor(0.5 + (double)dest_size * ratio); dest_size = ceil((double)dest_size * ratio);
dest_size *= audio_format_frame_size(outFormat); dest_size *= audio_format_frame_size(outFormat);
return dest_size; return dest_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment