From ef74eff3e8549997dd856ec658a79d1a9c2c860d Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 25 Jan 2004 18:29:11 +0000 Subject: [PATCH] Altivec optimized stereo resampler by Romain Dolbeau (made it working under Linux myself) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@11850 b3059339-0415-0410-9bf9-f77b7e298cf2 --- liba52/resample.c | 16 ++++++++- liba52/resample_altivec.c | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 liba52/resample_altivec.c diff --git a/liba52/resample.c b/liba52/resample.c index af3730c2f6..03210840b5 100644 --- a/liba52/resample.c +++ b/liba52/resample.c @@ -19,6 +19,10 @@ int (* a52_resample) (float * _f, int16_t * s16)=NULL; #include "resample_mmx.c" #endif +#ifdef HAVE_ALTIVEC +#include "resample_altivec.c" +#endif + void* a52_resample_init(uint32_t mm_accel,int flags,int chans){ void* tmp; @@ -32,7 +36,17 @@ void* tmp; } } #endif - +#ifdef HAVE_ALTIVEC + if(mm_accel&MM_ACCEL_PPC_ALTIVEC){ + tmp=a52_resample_altivec(flags,chans); + if(tmp){ + if(a52_resample==NULL) fprintf(stderr, "Using AltiVec optimized resampler\n"); + a52_resample=tmp; + return tmp; + } + } +#endif + tmp=a52_resample_C(flags,chans); if(tmp){ if(a52_resample==NULL) fprintf(stderr, "No accelerated resampler found\n"); diff --git a/liba52/resample_altivec.c b/liba52/resample_altivec.c new file mode 100644 index 0000000000..8768be0d72 --- /dev/null +++ b/liba52/resample_altivec.c @@ -0,0 +1,74 @@ +// this code is based on a52dec/libao/audio_out_oss.c +// AltiVec support Copyright (c) 2004 Romain Dolbeau + +#ifndef SYS_DARWIN +#include +#endif + +const vector signed int magic = {0x43c00000,0x43c00000,0x43c00000,0x43c00000}; + +static inline vector signed short convert16_altivec(vector signed int v1, vector signed int v2) +{ + register vector signed short result; + v1 = vec_subs(v1, magic); + v2 = vec_subs(v2, magic); + result = vec_packs(v1, v2); + + return result; +} + +static int a52_resample_STEREO_to_2_altivec(float * _f, int16_t * s16){ +#if 0 + int i; + int32_t * f = (int32_t *) _f; + for (i = 0; i < 256; i++) { + s16[2*i] = convert (f[i]); + s16[2*i+1] = convert (f[i+256]); + } + return 2*256; +#else + int i = 0; + int32_t * f = (int32_t *) _f; + register vector signed int f0, f4, f256, f260; + register vector signed short reven, rodd, r0, r1; + + for (i = 0; i < 256; i+= 8) { + f0 = vec_ld(0, f); + f4 = vec_ld(16, f); + + f256 = vec_ld(1024, f); + f260 = vec_ld(1040, f); + + reven = convert16_altivec(f0, f4); + rodd = convert16_altivec(f256, f260); + + r0 = vec_mergeh(reven, rodd); + r1 = vec_mergel(reven, rodd); + + vec_st(r0, 0, s16); + vec_st(r1, 16, s16); + + f += 8; + s16 += 16; + } + return(2*256); +#endif +} + +static void* a52_resample_altivec(int flags, int ch){ +fprintf(stderr, "Checking for AltiVec resampler : 0x%08x, %d\n", flags, ch); + + switch (flags) { + case A52_CHANNEL: + case A52_STEREO: + case A52_DOLBY: + if(ch==2) return a52_resample_STEREO_to_2_altivec; + break; + + default: + fprintf(stderr, "Unsupported flags: 0x%08x (%d channels)\n", flags, ch); + break; + } + return NULL; +} +