Some people confuse vidix with kernel drivers, so let's add a note about it
[mplayer/glamo.git] / liba52 / resample_altivec.c
blob8768be0d72e15fd44b2b8a3579ff982869eab25b
1 // this code is based on a52dec/libao/audio_out_oss.c
2 // AltiVec support Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
4 #ifndef SYS_DARWIN
5 #include <altivec.h>
6 #endif
8 const vector signed int magic = {0x43c00000,0x43c00000,0x43c00000,0x43c00000};
10 static inline vector signed short convert16_altivec(vector signed int v1, vector signed int v2)
12 register vector signed short result;
13 v1 = vec_subs(v1, magic);
14 v2 = vec_subs(v2, magic);
15 result = vec_packs(v1, v2);
17 return result;
20 static int a52_resample_STEREO_to_2_altivec(float * _f, int16_t * s16){
21 #if 0
22 int i;
23 int32_t * f = (int32_t *) _f;
24 for (i = 0; i < 256; i++) {
25 s16[2*i] = convert (f[i]);
26 s16[2*i+1] = convert (f[i+256]);
28 return 2*256;
29 #else
30 int i = 0;
31 int32_t * f = (int32_t *) _f;
32 register vector signed int f0, f4, f256, f260;
33 register vector signed short reven, rodd, r0, r1;
35 for (i = 0; i < 256; i+= 8) {
36 f0 = vec_ld(0, f);
37 f4 = vec_ld(16, f);
39 f256 = vec_ld(1024, f);
40 f260 = vec_ld(1040, f);
42 reven = convert16_altivec(f0, f4);
43 rodd = convert16_altivec(f256, f260);
45 r0 = vec_mergeh(reven, rodd);
46 r1 = vec_mergel(reven, rodd);
48 vec_st(r0, 0, s16);
49 vec_st(r1, 16, s16);
51 f += 8;
52 s16 += 16;
54 return(2*256);
55 #endif
58 static void* a52_resample_altivec(int flags, int ch){
59 fprintf(stderr, "Checking for AltiVec resampler : 0x%08x, %d\n", flags, ch);
61 switch (flags) {
62 case A52_CHANNEL:
63 case A52_STEREO:
64 case A52_DOLBY:
65 if(ch==2) return a52_resample_STEREO_to_2_altivec;
66 break;
68 default:
69 fprintf(stderr, "Unsupported flags: 0x%08x (%d channels)\n", flags, ch);
70 break;
72 return NULL;