]> code.delx.au - pulseaudio/commitdiff
resampler: Improve s16<-->s32 conversion, use s16 work format if input or output...
authorPeter Meerwald <p.meerwald@bct-electronic.com>
Wed, 30 Jan 2013 10:04:05 +0000 (11:04 +0100)
committerTanu Kaskinen <tanuk@iki.fi>
Fri, 1 Feb 2013 08:10:30 +0000 (10:10 +0200)
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@bct-electronic.com>
src/pulsecore/resampler.c

index 6c3b1f02953c44f5e183949213d2998024772c76..f0b3fd493a12e5f601cfd32704d750971d667375 100644 (file)
@@ -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 ||