[pulseaudio-discuss] [PATCH] When Speex is compiled with FIXED_POINT defined, it scales float input to +/-32768 instead of +/-1. But Pulseaudio invokes speex float method with input in range of +/-1. So in order to make floating point resamplers work with Speex compiled with FIXED_POINT, we need to rescale the input to Speex.

Fahad Arslan fahad_arslan at mentor.com
Mon Dec 23 10:09:17 PST 2013


From: Fahad Arslan <Fahad_Arslan at mentor.com>

Signed-off-by: Fahad Arslan <Fahad_Arslan at mentor.com>
---
 src/pulsecore/resampler.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index f0c663f..34bdfc3 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -1435,7 +1435,7 @@ static int libsamplerate_init(pa_resampler *r) {
 
 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;
+    uint32_t inf = in_n_frames, outf = *out_n_frames, i;
     SpeexResamplerState *state;
 
     pa_assert(r);
@@ -1448,6 +1448,11 @@ static unsigned speex_resample_float(pa_resampler *r, const pa_memchunk *input,
     in = pa_memblock_acquire_chunk(input);
     out = pa_memblock_acquire_chunk(output);
 
+    /* Speex float API scale range is +/-32768 instead of +/-1.
+       So rescale input before passing it to Speex. */
+    for (i = 0; i < inf; i++)
+        in[i] = 32768.*in[i];
+    
     pa_assert_se(speex_resampler_process_interleaved_float(state, in, &inf, out, &outf) == 0);
 
     pa_memblock_release(input->memblock);
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list