src/pulsecore/resampler.c | 179 +++++++++++++++++++++++----------------------- src/pulsecore/resampler.h | 5 + 2 files changed, 95 insertions(+), 89 deletions(-)
New commits: commit da5c215d9bc49dcc93b5ac29a0fc6a26dc163c0b Author: Peter Meerwald <pme...@pmeerw.net> Date: Sun Jul 21 23:14:42 2013 +0200 resampler: Cleanup, rename xxxx_buf_samples to xxxx_buf_size we measure the capacity of a buffer in bytes, not samples Signed-off-by: Peter Meerwald <pme...@pmeerw.net> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 7754ef8..856fd29 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -60,10 +60,10 @@ struct pa_resampler { pa_memchunk remap_buf; pa_memchunk resample_buf; pa_memchunk from_work_format_buf; - unsigned to_work_format_buf_samples; + size_t to_work_format_buf_size; size_t remap_buf_size; - unsigned resample_buf_samples; - unsigned from_work_format_buf_samples; + size_t resample_buf_size; + size_t from_work_format_buf_size; bool remap_buf_contains_leftover_data; pa_sample_format_t work_format; @@ -1148,11 +1148,11 @@ static pa_memchunk* convert_to_work_format(pa_resampler *r, pa_memchunk *input) r->to_work_format_buf.index = 0; r->to_work_format_buf.length = r->w_sz * n_samples; - if (!r->to_work_format_buf.memblock || r->to_work_format_buf_samples < n_samples) { + if (!r->to_work_format_buf.memblock || r->to_work_format_buf_size < r->to_work_format_buf.length) { if (r->to_work_format_buf.memblock) pa_memblock_unref(r->to_work_format_buf.memblock); - r->to_work_format_buf_samples = n_samples; + r->to_work_format_buf_size = r->to_work_format_buf.length; r->to_work_format_buf.memblock = pa_memblock_new(r->mempool, r->to_work_format_buf.length); } @@ -1270,9 +1270,7 @@ static void save_leftover(pa_resampler *r, void *buf, size_t len) { } static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) { - unsigned in_n_frames, in_n_samples; - unsigned out_n_frames, out_n_samples; - unsigned leftover_n_frames; + unsigned in_n_frames, out_n_frames, leftover_n_frames; pa_assert(r); pa_assert(input); @@ -1282,20 +1280,18 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) { if (!r->impl.resample || !input->length) return input; - in_n_samples = (unsigned) (input->length / r->w_sz); - in_n_frames = (unsigned) (in_n_samples / r->work_channels); + in_n_frames = (unsigned) (input->length / r->w_fz); out_n_frames = ((in_n_frames*r->o_ss.rate)/r->i_ss.rate)+EXTRA_FRAMES; - out_n_samples = out_n_frames * r->work_channels; r->resample_buf.index = 0; - r->resample_buf.length = r->w_sz * out_n_samples; + r->resample_buf.length = r->w_fz * out_n_frames; - if (!r->resample_buf.memblock || r->resample_buf_samples < out_n_samples) { + if (!r->resample_buf.memblock || r->resample_buf_size < r->resample_buf.length) { if (r->resample_buf.memblock) pa_memblock_unref(r->resample_buf.memblock); - r->resample_buf_samples = out_n_samples; + r->resample_buf_size = r->resample_buf.length; r->resample_buf.memblock = pa_memblock_new(r->mempool, r->resample_buf.length); } @@ -1331,11 +1327,11 @@ static pa_memchunk *convert_from_work_format(pa_resampler *r, pa_memchunk *input r->from_work_format_buf.index = 0; r->from_work_format_buf.length = r->o_fz * n_frames; - if (!r->from_work_format_buf.memblock || r->from_work_format_buf_samples < n_samples) { + if (!r->from_work_format_buf.memblock || r->from_work_format_buf_size < r->from_work_format_buf.length) { if (r->from_work_format_buf.memblock) pa_memblock_unref(r->from_work_format_buf.memblock); - r->from_work_format_buf_samples = n_samples; + r->from_work_format_buf_size = r->from_work_format_buf.length; r->from_work_format_buf.memblock = pa_memblock_new(r->mempool, r->from_work_format_buf.length); } commit 53104b36e63173731177ec0909aafa11a4311ae8 Author: Peter Meerwald <pme...@pmeerw.net> Date: Sun Jul 21 23:14:41 2013 +0200 resampler: Handle leftover samples, use new return value Signed-off-by: Peter Meerwald <pme...@pmeerw.net> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 657f0da..7754ef8 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -1243,9 +1243,36 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) { return &r->remap_buf; } +static void save_leftover(pa_resampler *r, void *buf, size_t len) { + void *dst; + + pa_assert(r); + pa_assert(buf); + pa_assert(len > 0); + + /* Store the leftover to remap_buf. */ + + r->remap_buf.length = len; + + if (!r->remap_buf.memblock || r->remap_buf_size < r->remap_buf.length) { + if (r->remap_buf.memblock) + pa_memblock_unref(r->remap_buf.memblock); + + r->remap_buf_size = r->remap_buf.length; + r->remap_buf.memblock = pa_memblock_new(r->mempool, r->remap_buf.length); + } + + dst = pa_memblock_acquire(r->remap_buf.memblock); + memcpy(dst, buf, r->remap_buf.length); + pa_memblock_release(r->remap_buf.memblock); + + r->remap_buf_contains_leftover_data = true; +} + static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) { unsigned in_n_frames, in_n_samples; unsigned out_n_frames, out_n_samples; + unsigned leftover_n_frames; pa_assert(r); pa_assert(input); @@ -1272,7 +1299,14 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) { r->resample_buf.memblock = pa_memblock_new(r->mempool, r->resample_buf.length); } - r->impl.resample(r, input, in_n_frames, &r->resample_buf, &out_n_frames); + leftover_n_frames = r->impl.resample(r, input, in_n_frames, &r->resample_buf, &out_n_frames); + + if (leftover_n_frames > 0) { + void *leftover_data = (uint8_t *) pa_memblock_acquire_chunk(input) + (in_n_frames - leftover_n_frames) * r->w_fz; + save_leftover(r, leftover_data, leftover_n_frames * r->w_fz); + pa_memblock_release(input->memblock); + } + r->resample_buf.length = out_n_frames * r->w_fz; return &r->resample_buf; @@ -1341,32 +1375,6 @@ void pa_resampler_run(pa_resampler *r, const pa_memchunk *in, pa_memchunk *out) pa_memchunk_reset(out); } -static void save_leftover(pa_resampler *r, void *buf, size_t len) { - void *dst; - - pa_assert(r); - pa_assert(buf); - pa_assert(len > 0); - - /* Store the leftover to remap_buf. */ - - r->remap_buf.length = len; - - if (!r->remap_buf.memblock || r->remap_buf_size < r->remap_buf.length) { - if (r->remap_buf.memblock) - pa_memblock_unref(r->remap_buf.memblock); - - r->remap_buf_size = r->remap_buf.length; - r->remap_buf.memblock = pa_memblock_new(r->mempool, r->remap_buf.length); - } - - dst = pa_memblock_acquire(r->remap_buf.memblock); - memcpy(dst, buf, r->remap_buf.length); - pa_memblock_release(r->remap_buf.memblock); - - r->remap_buf_contains_leftover_data = true; -} - /*** libsamplerate based implementation ***/ #ifdef HAVE_LIBSAMPLERATE @@ -1393,19 +1401,12 @@ static unsigned libsamplerate_resample(pa_resampler *r, const pa_memchunk *input pa_assert_se(src_process(state, &data) == 0); - if (data.input_frames_used < in_n_frames) { - void *leftover_data = data.data_in + data.input_frames_used * r->work_channels; - size_t leftover_length = (in_n_frames - data.input_frames_used) * r->w_fz; - - save_leftover(r, leftover_data, leftover_length); - } - pa_memblock_release(input->memblock); pa_memblock_release(output->memblock); *out_n_frames = (unsigned) data.output_frames_gen; - return 0; + return in_n_frames - data.input_frames_used; } static void libsamplerate_update_rates(pa_resampler *r) { @@ -1832,17 +1833,9 @@ static unsigned ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsig pa_memblock_unref(w); } - if (previous_consumed_frames < (int) in_n_frames) { - void *leftover_data = (int16_t *) pa_memblock_acquire_chunk(input) + previous_consumed_frames * r->work_channels; - size_t leftover_length = (in_n_frames - previous_consumed_frames) * r->w_fz; - - save_leftover(r, leftover_data, leftover_length); - pa_memblock_release(input->memblock); - } - *out_n_frames = used_frames; - return 0; + return in_n_frames - previous_consumed_frames; } static void ffmpeg_free(pa_resampler *r) { commit 79b237ca02cbcce41e1c3de5f11143f0f3ced678 Author: Peter Meerwald <pme...@pmeerw.net> Date: Sun Jul 21 23:14:40 2013 +0200 resampler: Change interface, resampler may return the number of leftover frames some resampler implementations (e.g. libsamplerate and ffmpeg) do not consume the entire input buffer; the impl_resample() function now has a return value returning the number of frames in the input buffer not processed these frames must be saved in appropriate buffer and presented together with new input data also change the parameter names from in_samples, out_samples to in_n_frames, out_n_frames, respectively (n_frames = samples / channels) Signed-off-by: Peter Meerwald <pme...@pmeerw.net> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 104207d..657f0da 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -1370,7 +1370,7 @@ static void save_leftover(pa_resampler *r, void *buf, size_t len) { /*** libsamplerate based implementation ***/ #ifdef HAVE_LIBSAMPLERATE -static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +static unsigned libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { SRC_DATA data; SRC_STATE *state; @@ -1404,6 +1404,8 @@ static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, un pa_memblock_release(output->memblock); *out_n_frames = (unsigned) data.output_frames_gen; + + return 0; } static void libsamplerate_update_rates(pa_resampler *r) { @@ -1453,7 +1455,7 @@ static int libsamplerate_init(pa_resampler *r) { #ifdef HAVE_SPEEX /*** speex based implementation ***/ -static void speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +static unsigned speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { float *in, *out; uint32_t inf = in_n_frames, outf = *out_n_frames; SpeexResamplerState *state; @@ -1475,9 +1477,11 @@ static void speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsi pa_assert(inf == in_n_frames); *out_n_frames = outf; + + return 0; } -static void speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +static unsigned speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { int16_t *in, *out; uint32_t inf = in_n_frames, outf = *out_n_frames; SpeexResamplerState *state; @@ -1499,6 +1503,8 @@ static void speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsign pa_assert(inf == in_n_frames); *out_n_frames = outf; + + return 0; } static void speex_update_rates(pa_resampler *r) { @@ -1565,7 +1571,7 @@ static int speex_init(pa_resampler *r) { /* Trivial implementation */ -static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +static unsigned trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { unsigned i_index, o_index; void *src, *dst; struct trivial_data *trivial_data; @@ -1606,6 +1612,8 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned trivial_data->i_counter -= r->i_ss.rate; trivial_data->o_counter -= r->o_ss.rate; } + + return 0; } static void trivial_update_rates_or_reset(pa_resampler *r) { @@ -1634,7 +1642,7 @@ static int trivial_init(pa_resampler*r) { /* Peak finder implementation */ -static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +static unsigned peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { unsigned c, o_index = 0; unsigned i, i_end = 0; void *src, *dst; @@ -1730,6 +1738,8 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i peaks_data->i_counter -= r->i_ss.rate; peaks_data->o_counter -= r->o_ss.rate; } + + return 0; } static void peaks_update_rates_or_reset(pa_resampler *r) { @@ -1760,7 +1770,7 @@ static int peaks_init(pa_resampler*r) { /*** ffmpeg based implementation ***/ -static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +static unsigned ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { unsigned used_frames = 0, c; int previous_consumed_frames = -1; struct ffmpeg_data *ffmpeg_data; @@ -1831,6 +1841,8 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned } *out_n_frames = used_frames; + + return 0; } static void ffmpeg_free(pa_resampler *r) { diff --git a/src/pulsecore/resampler.h b/src/pulsecore/resampler.h index 793b70b..058a800 100644 --- a/src/pulsecore/resampler.h +++ b/src/pulsecore/resampler.h @@ -33,7 +33,10 @@ typedef struct pa_resampler_impl pa_resampler_impl; struct pa_resampler_impl { void (*free)(pa_resampler *r); void (*update_rates)(pa_resampler *r); - void (*resample)(pa_resampler *r, const pa_memchunk *in, unsigned in_samples, pa_memchunk *out, unsigned *out_samples); + + /* Returns the number of leftover frames in the input buffer. */ + unsigned (*resample)(pa_resampler *r, const pa_memchunk *in, unsigned in_n_frames, pa_memchunk *out, unsigned *out_n_frames); + void (*reset)(pa_resampler *r); void *data; }; commit 6d61c7779d1f5dc139cd6f354d9b75ce4b20e37c Author: Peter Meerwald <pme...@pmeerw.net> Date: Sun Jul 21 23:14:39 2013 +0200 resampler: Introduce work_channels work_channels is the number of channels in the resampler stage Signed-off-by: Peter Meerwald <p.meerw...@bct-electronic.com> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 2956c54..104207d 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -67,6 +67,7 @@ struct pa_resampler { bool remap_buf_contains_leftover_data; pa_sample_format_t work_format; + uint8_t work_channels; pa_convert_func_t to_work_format_func; pa_convert_func_t from_work_format_func; @@ -397,7 +398,6 @@ pa_resampler* pa_resampler_new( pa_log_info("Using %s as working format.", pa_sample_format_to_string(r->work_format)); r->w_sz = pa_sample_size_of_format(r->work_format); - r->w_fz = pa_sample_size_of_format(r->work_format) * r->o_ss.channels; if (r->i_ss.format != r->work_format) { if (r->work_format == PA_SAMPLE_FLOAT32NE) { @@ -421,6 +421,9 @@ pa_resampler* pa_resampler_new( } } + r->work_channels = r->o_ss.channels; + r->w_fz = pa_sample_size_of_format(r->work_format) * r->work_channels; + /* initialize implementation */ if (init_table[method](r) < 0) goto fail; @@ -1253,10 +1256,10 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) { return input; in_n_samples = (unsigned) (input->length / r->w_sz); - in_n_frames = (unsigned) (in_n_samples / r->o_ss.channels); + in_n_frames = (unsigned) (in_n_samples / r->work_channels); out_n_frames = ((in_n_frames*r->o_ss.rate)/r->i_ss.rate)+EXTRA_FRAMES; - out_n_samples = out_n_frames * r->o_ss.channels; + out_n_samples = out_n_frames * r->work_channels; r->resample_buf.index = 0; r->resample_buf.length = r->w_sz * out_n_samples; @@ -1391,7 +1394,7 @@ static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, un pa_assert_se(src_process(state, &data) == 0); if (data.input_frames_used < in_n_frames) { - void *leftover_data = data.data_in + data.input_frames_used * r->o_ss.channels; + void *leftover_data = data.data_in + data.input_frames_used * r->work_channels; size_t leftover_length = (in_n_frames - data.input_frames_used) * r->w_fz; save_leftover(r, leftover_data, leftover_length); @@ -1434,7 +1437,7 @@ static int libsamplerate_init(pa_resampler *r) { pa_assert(r); - if (!(state = src_new(r->method, r->o_ss.channels, &err))) + if (!(state = src_new(r->method, r->work_channels, &err))) return -1; r->impl.free = libsamplerate_free; @@ -1551,7 +1554,7 @@ static int speex_init(pa_resampler *r) { pa_log_info("Choosing speex quality setting %i.", q); - if (!(state = speex_resampler_init(r->o_ss.channels, r->i_ss.rate, r->o_ss.rate, q, &err))) + if (!(state = speex_resampler_init(r->work_channels, r->i_ss.rate, r->o_ss.rate, q, &err))) return -1; r->impl.data = state; @@ -1656,7 +1659,7 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i pa_assert_fp(o_index * r->w_fz < pa_memblock_get_length(output->memblock)); /* 1ch float is treated separately, because that is the common case */ - if (r->o_ss.channels == 1 && r->work_format == PA_SAMPLE_FLOAT32NE) { + if (r->work_channels == 1 && r->work_format == PA_SAMPLE_FLOAT32NE) { float *s = (float*) src + i; float *d = (float*) dst + o_index; @@ -1673,11 +1676,11 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i o_index++, peaks_data->o_counter++; } } else if (r->work_format == PA_SAMPLE_S16NE) { - int16_t *s = (int16_t*) src + r->o_ss.channels * i; - int16_t *d = (int16_t*) dst + r->o_ss.channels * o_index; + int16_t *s = (int16_t*) src + r->work_channels * i; + int16_t *d = (int16_t*) dst + r->work_channels * o_index; for (; i < i_end && i < in_n_frames; i++) - for (c = 0; c < r->o_ss.channels; c++) { + for (c = 0; c < r->work_channels; c++) { int16_t n = abs(*s++); if (n > peaks_data->max_i[c]) @@ -1685,18 +1688,18 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i } if (i == i_end) { - for (c = 0; c < r->o_ss.channels; c++, d++) { + for (c = 0; c < r->work_channels; c++, d++) { *d = peaks_data->max_i[c]; peaks_data->max_i[c] = 0; } o_index++, peaks_data->o_counter++; } } else { - float *s = (float*) src + r->o_ss.channels * i; - float *d = (float*) dst + r->o_ss.channels * o_index; + float *s = (float*) src + r->work_channels * i; + float *d = (float*) dst + r->work_channels * o_index; for (; i < i_end && i < in_n_frames; i++) - for (c = 0; c < r->o_ss.channels; c++) { + for (c = 0; c < r->work_channels; c++) { float n = fabsf(*s++); if (n > peaks_data->max_f[c]) @@ -1704,7 +1707,7 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i } if (i == i_end) { - for (c = 0; c < r->o_ss.channels; c++, d++) { + for (c = 0; c < r->work_channels; c++, d++) { *d = peaks_data->max_f[c]; peaks_data->max_f[c] = 0; } @@ -1769,7 +1772,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned ffmpeg_data = r->impl.data; - for (c = 0; c < r->o_ss.channels; c++) { + for (c = 0; c < r->work_channels; c++) { unsigned u; pa_memblock *b, *w; int16_t *p, *t, *k, *q, *s; @@ -1784,7 +1787,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned k = p; for (u = 0; u < in_n_frames; u++) { *k = *t; - t += r->o_ss.channels; + t += r->work_channels; k ++; } pa_memblock_release(input->memblock); @@ -1798,7 +1801,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned q, p, &consumed_frames, (int) in_n_frames, (int) *out_n_frames, - c >= (unsigned) (r->o_ss.channels-1)); + c >= (unsigned) (r->work_channels-1)); pa_memblock_release(b); pa_memblock_unref(b); @@ -1812,7 +1815,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned for (u = 0; u < used_frames; u++) { *s = *q; q++; - s += r->o_ss.channels; + s += r->work_channels; } pa_memblock_release(output->memblock); pa_memblock_release(w); @@ -1820,7 +1823,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned } if (previous_consumed_frames < (int) in_n_frames) { - void *leftover_data = (int16_t *) pa_memblock_acquire_chunk(input) + previous_consumed_frames * r->o_ss.channels; + void *leftover_data = (int16_t *) pa_memblock_acquire_chunk(input) + previous_consumed_frames * r->work_channels; size_t leftover_length = (in_n_frames - previous_consumed_frames) * r->w_fz; save_leftover(r, leftover_data, leftover_length); commit c60a36ecdd58c739efb77714acbd0f1eca34d0a8 Author: Peter Meerwald <pme...@pmeerw.net> Date: Sun Jul 21 23:14:38 2013 +0200 resampler: Introduce work frame size (w_fz) w_fz represents the number of bytes per frame in the resampler stage Signed-off-by: Peter Meerwald <p.meerw...@bct-electronic.com> diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 46cf2ab..2956c54 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -53,7 +53,7 @@ struct pa_resampler { pa_sample_spec i_ss, o_ss; pa_channel_map i_cm, o_cm; - size_t i_fz, o_fz, w_sz; + size_t i_fz, o_fz, w_fz, w_sz; pa_mempool *mempool; pa_memchunk to_work_format_buf; @@ -397,6 +397,7 @@ pa_resampler* pa_resampler_new( pa_log_info("Using %s as working format.", pa_sample_format_to_string(r->work_format)); r->w_sz = pa_sample_size_of_format(r->work_format); + r->w_fz = pa_sample_size_of_format(r->work_format) * r->o_ss.channels; if (r->i_ss.format != r->work_format) { if (r->work_format == PA_SAMPLE_FLOAT32NE) { @@ -504,7 +505,7 @@ size_t pa_resampler_result(pa_resampler *r, size_t in_length) { frames = (in_length + r->i_fz - 1) / r->i_fz; if (r->remap_buf_contains_leftover_data) - frames += r->remap_buf.length / (r->w_sz * r->o_ss.channels); + frames += r->remap_buf.length / r->w_fz; return (((uint64_t) frames * r->o_ss.rate + r->i_ss.rate - 1) / r->i_ss.rate) * r->o_fz; } @@ -533,7 +534,7 @@ size_t pa_resampler_max_block_size(pa_resampler *r) { frames = block_size_max / max_fs - EXTRA_FRAMES; if (r->remap_buf_contains_leftover_data) - frames -= r->remap_buf.length / (r->w_sz * r->o_ss.channels); + frames -= r->remap_buf.length / r->w_fz; block_size_max = ((uint64_t) frames * r->i_ss.rate / max_ss.rate) * r->i_fz; @@ -1190,7 +1191,7 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) { if (have_leftover) { leftover_length = r->remap_buf.length; - out_n_frames += leftover_length / (r->w_sz * r->o_ss.channels); + out_n_frames += leftover_length / r->w_fz; } out_n_samples = out_n_frames * r->o_ss.channels; @@ -1269,7 +1270,7 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) { } r->impl.resample(r, input, in_n_frames, &r->resample_buf, &out_n_frames); - r->resample_buf.length = out_n_frames * r->w_sz * r->o_ss.channels; + r->resample_buf.length = out_n_frames * r->w_fz; return &r->resample_buf; } @@ -1391,7 +1392,7 @@ static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, un if (data.input_frames_used < in_n_frames) { void *leftover_data = data.data_in + data.input_frames_used * r->o_ss.channels; - size_t leftover_length = (in_n_frames - data.input_frames_used) * sizeof(float) * r->o_ss.channels; + size_t leftover_length = (in_n_frames - data.input_frames_used) * r->w_fz; save_leftover(r, leftover_data, leftover_length); } @@ -1562,7 +1563,6 @@ static int speex_init(pa_resampler *r) { /* Trivial implementation */ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { - size_t fz; unsigned i_index, o_index; void *src, *dst; struct trivial_data *trivial_data; @@ -1573,7 +1573,6 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned pa_assert(out_n_frames); trivial_data = r->impl.data; - fz = r->w_sz * r->o_ss.channels; src = pa_memblock_acquire_chunk(input); dst = pa_memblock_acquire_chunk(output); @@ -1585,9 +1584,9 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned if (i_index >= in_n_frames) break; - pa_assert_fp(o_index * fz < pa_memblock_get_length(output->memblock)); + pa_assert_fp(o_index * r->w_fz < pa_memblock_get_length(output->memblock)); - memcpy((uint8_t*) dst + fz * o_index, (uint8_t*) src + fz * i_index, (int) fz); + memcpy((uint8_t*) dst + r->w_fz * o_index, (uint8_t*) src + r->w_fz * i_index, (int) r->w_fz); } pa_memblock_release(input->memblock); @@ -1654,7 +1653,7 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i i_end = ((uint64_t) (peaks_data->o_counter + 1) * r->i_ss.rate) / r->o_ss.rate; i_end = i_end > peaks_data->i_counter ? i_end - peaks_data->i_counter : 0; - pa_assert_fp(o_index * r->w_sz * r->o_ss.channels < pa_memblock_get_length(output->memblock)); + pa_assert_fp(o_index * r->w_fz < pa_memblock_get_length(output->memblock)); /* 1ch float is treated separately, because that is the common case */ if (r->o_ss.channels == 1 && r->work_format == PA_SAMPLE_FLOAT32NE) { @@ -1822,7 +1821,7 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned if (previous_consumed_frames < (int) in_n_frames) { void *leftover_data = (int16_t *) pa_memblock_acquire_chunk(input) + previous_consumed_frames * r->o_ss.channels; - size_t leftover_length = (in_n_frames - previous_consumed_frames) * r->o_ss.channels * sizeof(int16_t); + size_t leftover_length = (in_n_frames - previous_consumed_frames) * r->w_fz; save_leftover(r, leftover_data, leftover_length); pa_memblock_release(input->memblock); _______________________________________________ pulseaudio-commits mailing list pulseaudio-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits