Commit 953b258e authored by Max Kellermann's avatar Max Kellermann

pcm_resample_fallback: corrected the sample calculation

Due to rounding errors, it was possible that the fallback resampler returned partial frames.
parent 285a741b
...@@ -29,6 +29,7 @@ MPD 0.14.1 - not yet released ...@@ -29,6 +29,7 @@ MPD 0.14.1 - not yet released
- honour http_proxy_* config directives - honour http_proxy_* config directives
- fix assertion failure on "connection refused" - fix assertion failure on "connection refused"
- fix assertion failure with empty HTTP responses - fix assertion failure with empty HTTP responses
* corrected the sample calculation in the fallback resampler
* log: automatically append newline * log: automatically append newline
* fix setenv() conflict on Solaris * fix setenv() conflict on Solaris
* configure.ac: check for pkg-config before using it * configure.ac: check for pkg-config before using it
......
...@@ -37,9 +37,10 @@ pcm_resample_16(struct pcm_resample_state *state, ...@@ -37,9 +37,10 @@ pcm_resample_16(struct pcm_resample_state *state,
size_t *dest_size_r) size_t *dest_size_r)
{ {
unsigned src_pos, dest_pos = 0; unsigned src_pos, dest_pos = 0;
unsigned src_samples = src_size / sizeof(*src_buffer); unsigned src_frames = src_size / channels / sizeof(*src_buffer);
unsigned dest_samples = unsigned dest_frames =
(src_samples * dest_rate + src_rate - 1) / src_rate; (src_frames * dest_rate + src_rate - 1) / src_rate;
unsigned dest_samples = dest_frames * channels;
size_t dest_size = dest_samples * sizeof(*src_buffer); size_t dest_size = dest_samples * sizeof(*src_buffer);
int16_t *dest_buffer = pcm_buffer_get(&state->buffer, dest_size); int16_t *dest_buffer = pcm_buffer_get(&state->buffer, dest_size);
...@@ -77,9 +78,10 @@ pcm_resample_24(struct pcm_resample_state *state, ...@@ -77,9 +78,10 @@ pcm_resample_24(struct pcm_resample_state *state,
size_t *dest_size_r) size_t *dest_size_r)
{ {
unsigned src_pos, dest_pos = 0; unsigned src_pos, dest_pos = 0;
unsigned src_samples = src_size / sizeof(*src_buffer); unsigned src_frames = src_size / channels / sizeof(*src_buffer);
unsigned dest_samples = unsigned dest_frames =
(src_samples * dest_rate + src_rate - 1) / src_rate; (src_frames * dest_rate + src_rate - 1) / src_rate;
unsigned dest_samples = dest_frames * channels;
size_t dest_size = dest_samples * sizeof(*src_buffer); size_t dest_size = dest_samples * sizeof(*src_buffer);
int32_t *dest_buffer = pcm_buffer_get(&state->buffer, dest_size); int32_t *dest_buffer = pcm_buffer_get(&state->buffer, 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