audioresample: changed inner_product_single semantics
authorCarlos Rafael Giani <dv@pseudoterminal.org>
Mon, 15 Oct 2012 20:21:14 +0000 (22:21 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 25 Oct 2012 12:03:52 +0000 (14:03 +0200)
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 <dv@pseudoterminal.org>
gst/audioresample/arch.h
gst/audioresample/fixed_generic.h
gst/audioresample/resample.c

index c518458..4e77e6e 100644 (file)
@@ -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)
index 3fb096e..6991352 100644 (file)
 #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))
index bd36bfa..b6b1de6 100644 (file)
@@ -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) {