From 19073ab8c4898a7fb780e73748a5bfe20f79d477 Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Mon, 15 Oct 2012 22:21:14 +0200 Subject: [PATCH] audioresample: changed inner_product_single semantics This is an adaptation of patch #3 from Jyri Sarha ( http://lists.xiph.org/pipermail/speex-dev/2011-September/008240.html ), but without the NEON optimizations (these come in a separate commit). The idea is to replace SATURATE32(PSHR32(x, shift), a) operations with a combined SATURATE32PSHR(x, shift, a) macro that can be optimized for specific platforms (and also avoids rare rounding errors). Signed-off-by: Carlos Rafael Giani --- gst/audioresample/arch.h | 1 + gst/audioresample/fixed_generic.h | 4 ++++ gst/audioresample/resample.c | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gst/audioresample/arch.h b/gst/audioresample/arch.h index c5184582a1..4e77e6e1c2 100644 --- a/gst/audioresample/arch.h +++ b/gst/audioresample/arch.h @@ -197,6 +197,7 @@ typedef float spx_word32_t; #define VSHR32(a,shift) (a) #define SATURATE16(x,a) (x) #define SATURATE32(x,a) (x) +#define SATURATE32PSHR(x,shift,a) (x) #define PSHR(a,shift) (a) #define SHR(a,shift) (a) diff --git a/gst/audioresample/fixed_generic.h b/gst/audioresample/fixed_generic.h index 3fb096ed90..6991352159 100644 --- a/gst/audioresample/fixed_generic.h +++ b/gst/audioresample/fixed_generic.h @@ -51,6 +51,10 @@ #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) + +#define SATURATE32PSHR(x,shift,a) (((x)>=(SHL32(a,shift))) ? (a) : \ + (x)<=-(SHL32(a,shift)) ? -(a) : \ + (PSHR32(x, shift))) #define SHR(a,shift) ((a) >> (shift)) #define SHL(a,shift) ((spx_word32_t)(a) << (shift)) diff --git a/gst/audioresample/resample.c b/gst/audioresample/resample.c index bd36bfa3db..b6b1de6604 100644 --- a/gst/audioresample/resample.c +++ b/gst/audioresample/resample.c @@ -478,7 +478,7 @@ resampler_basic_direct_single (SpeexResamplerState * st, sum = inner_product_single (sinc, iptr, N); SSE_END (INNER_PRODUCT_SINGLE) #endif - out[out_stride * out_sample++] = SATURATE32 (PSHR32 (sum, 15), 32767); + out[out_stride * out_sample++] = SATURATE32PSHR(sum, 15, 32767); last_sample += int_advance; samp_frac_num += frac_advance; if (samp_frac_num >= den_rate) { @@ -616,7 +616,7 @@ resampler_basic_interpolate_single (SpeexResamplerState * st, interp); SSE_END (INTERPOLATE_PRODUCT_SINGLE) #endif - out[out_stride * out_sample++] = SATURATE32 (PSHR32 (sum, 14), 32767); + out[out_stride * out_sample++] = SATURATE32PSHR(sum, 14, 32767); last_sample += int_advance; samp_frac_num += frac_advance; if (samp_frac_num >= den_rate) {