[pulseaudio-discuss] [PATCH 10/10] resampler: Improve s16<-->s32 conversion, use s16 work format if input or output is s16

Peter Meerwald pmeerw at pmeerw.net
Wed Jan 30 02:04:05 PST 2013


From: Peter Meerwald <p.meerwald at bct-electronic.com>

Problem: s16 to s32 conversion is performed as s16->float->s32 (via work
format float) for resamplers TRIVIAL, COPY, PEAKS.
Precision and efficiency suffers: e.g. 0x9fff results in 0x9ffe4001 (instead
of 0x9fff0000) and there are two sample format conversions instead of one
conversion.

Solution: If input or output format is s16, then choose the work format
to be s16 as well.

If remapping is to be performed, we could stick to work format float32ne for
precision reseans. This is debateable.

Signed-off-by: Peter Meerwald <p.meerwald at bct-electronic.com>
---
 src/pulsecore/resampler.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 6c3b1f0..f0b3fd4 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -282,7 +282,9 @@ pa_resampler* pa_resampler_new(
 
         if (r->map_required || a->format != b->format || method == PA_RESAMPLER_PEAKS) {
 
-            if (a->format == PA_SAMPLE_S32NE || a->format == PA_SAMPLE_S32RE ||
+            if (a->format == PA_SAMPLE_S16NE || b->format == PA_SAMPLE_S16NE)
+                r->work_format = PA_SAMPLE_S16NE;
+            else if (a->format == PA_SAMPLE_S32NE || a->format == PA_SAMPLE_S32RE ||
                 a->format == PA_SAMPLE_FLOAT32NE || a->format == PA_SAMPLE_FLOAT32RE ||
                 a->format == PA_SAMPLE_S24NE || a->format == PA_SAMPLE_S24RE ||
                 a->format == PA_SAMPLE_S24_32NE || a->format == PA_SAMPLE_S24_32RE ||
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list