[pulseaudio-discuss] [PATCH v2] resampler: Support speex resampler compiled with FIXED_POINT
Alexander E. Patrakov
patrakov at gmail.com
Sat May 10 08:32:53 PDT 2014
When Speex is compiled with FIXED_POINT defined, it scales float input
to ±32768 instead of ±1. In order to make floating point resampler
work with speex compiled with FIXED_POINT, we need to rescale the input
to speex. This rescaling does not hurt normal speex, so we do it
unconditionally.
Signed-off-by: Alexander E. Patrakov <patrakov at gmail.com>
Reported-by: Fahad Arslan <fahad_arslan at mentor.com>
Original-author: Peter Meerwald <pmeerw at pmeerw.net>
Cc: Damir Jelić <poljarinho at gmail.com>
Cc: Peter Meerwald <pmeerw at pmeerw.net>
---
src/pulsecore/resampler.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 1153281..fca6887 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -1473,9 +1473,11 @@ static int libsamplerate_init(pa_resampler *r) {
/*** speex based implementation ***/
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;
+ pa_memblock *b;
+ float *in, *out, *t;
uint32_t inf = in_n_frames, outf = *out_n_frames;
SpeexResamplerState *state;
+ unsigned i, nsamples;
pa_assert(r);
pa_assert(input);
@@ -1484,12 +1486,29 @@ static unsigned speex_resample_float(pa_resampler *r, const pa_memchunk *input,
state = r->impl.data;
+ nsamples = r->work_channels * in_n_frames;
+ b = pa_memblock_new(r->mempool, nsamples * sizeof(float));
+ t = pa_memblock_acquire(b);
+
in = pa_memblock_acquire_chunk(input);
- out = pa_memblock_acquire_chunk(output);
- pa_assert_se(speex_resampler_process_interleaved_float(state, in, &inf, out, &outf) == 0);
+ for (i = 0; i < nsamples; i++)
+ t[i] = 32768.0f * in[i];
pa_memblock_release(input->memblock);
+
+ out = pa_memblock_acquire_chunk(output);
+
+ pa_assert_se(speex_resampler_process_interleaved_float(state, t, &inf, out, &outf) == 0);
+
+ pa_memblock_release(b);
+ pa_memblock_unref(b);
+
+ nsamples = r->work_channels * outf;
+
+ for (i = 0; i < nsamples; i++)
+ out[i] = out[i] * (1.0f / 32768.0f);
+
pa_memblock_release(output->memblock);
pa_assert(inf == in_n_frames);
--
1.9.2
More information about the pulseaudio-discuss
mailing list