diff options
author | Max Kellermann <max@duempel.org> | 2014-11-10 22:52:17 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-11-10 22:52:17 +0100 |
commit | 8d036c4b7c3a09bd55bdc86a4fb7b5d525a805c2 (patch) | |
tree | 595d3bff8ed82184fd81eac062c676e6355f3a7b /src/pcm | |
parent | 8ff0d99092acfe8e80eba9709c2e93727f9e47b9 (diff) | |
download | mpd-8d036c4b7c3a09bd55bdc86a4fb7b5d525a805c2.tar.gz mpd-8d036c4b7c3a09bd55bdc86a4fb7b5d525a805c2.tar.xz mpd-8d036c4b7c3a09bd55bdc86a4fb7b5d525a805c2.zip |
pcm/SoxrResampler: round output buffer size up
The old formula calculates the output buffer size with "regular"
rounding (to the nearest integer), however sometimes, that is
insufficient and the last sample cannot be resampled. This causes
audible distortions. By changing the formula to consider the worst
case (always round up), this problem is eliminated.
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/SoxrResampler.cxx | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/pcm/SoxrResampler.cxx b/src/pcm/SoxrResampler.cxx index 56b9760d5..b9d6fc099 100644 --- a/src/pcm/SoxrResampler.cxx +++ b/src/pcm/SoxrResampler.cxx @@ -147,7 +147,8 @@ SoxrPcmResampler::Resample(ConstBuffer<void> src, Error &error) const size_t n_frames = src.size / frame_size; - const size_t o_frames = size_t(n_frames * ratio + 0.5); + /* always round up: worst case output buffer size */ + const size_t o_frames = size_t(n_frames * ratio) + 1; float *output_buffer = (float *)buffer.Get(o_frames * frame_size); |