From 3a3c4eb4622feb8115d1387f33a4bfa722e0061a Mon Sep 17 00:00:00 2001
From: Peter Meerwald
Date: Wed, 30 Jan 2013 11:04:05 +0100
Subject: [PATCH] resampler: Improve s16<-->s32 conversion, use s16 work format
if input or output is s16
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
---
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 6c3b1f02..f0b3fd49 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 ||
--
2.39.2