libavformat is now the default for mov, update extension.c to match this.
[mplayer/glamo.git] / liba52 / resample_altivec.c
blob1328a2a021367bc5da852c9736a71ea71c5fc909
1 /*
2 * resample.c
3 * Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
5 * This file is part of a52dec, a free ATSC A-52 stream decoder.
6 * See http://liba52.sourceforge.net/ for updates.
8 * File added for use with MPlayer and not part of original a52dec.
10 * a52dec is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * a52dec is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifdef HAVE_ALTIVEC_H
26 #include <altivec.h>
27 #endif
29 const vector signed int magic = {0x43c00000,0x43c00000,0x43c00000,0x43c00000};
31 static inline vector signed short convert16_altivec(vector signed int v1, vector signed int v2)
33 register vector signed short result;
34 v1 = vec_subs(v1, magic);
35 v2 = vec_subs(v2, magic);
36 result = vec_packs(v1, v2);
38 return result;
41 static void unaligned_store(vector signed short value, int off, int16_t *dst)
43 register vector unsigned char align = vec_lvsr(0, dst),
44 mask = vec_lvsl(0, dst);
45 register vector signed short t0,t1, edges;
47 t0 = vec_ld(0+off, dst);
48 t1 = vec_ld(15+off, dst);
49 edges = vec_perm(t1 ,t0, mask);
50 t1 = vec_perm(value, edges, align);
51 t0 = vec_perm(edges, value, align);
52 vec_st(t1, 15+off, dst);
53 vec_st(t0, 0+off, dst);
56 static int a52_resample_STEREO_to_2_altivec(float * _f, int16_t * s16){
57 #if 0
58 int i;
59 int32_t * f = (int32_t *) _f;
60 for (i = 0; i < 256; i++) {
61 s16[2*i] = convert (f[i]);
62 s16[2*i+1] = convert (f[i+256]);
64 return 2*256;
65 #else
66 int i = 0;
67 int32_t * f = (int32_t *) _f;
68 register vector signed int f0, f4, f256, f260;
69 register vector signed short reven, rodd, r0, r1;
71 for (i = 0; i < 256; i+= 8) {
72 f0 = vec_ld(0, f);
73 f4 = vec_ld(16, f);
75 f256 = vec_ld(1024, f);
76 f260 = vec_ld(1040, f);
78 reven = convert16_altivec(f0, f4);
79 rodd = convert16_altivec(f256, f260);
81 r0 = vec_mergeh(reven, rodd);
82 r1 = vec_mergel(reven, rodd);
83 // FIXME can be merged to spare some I/O
84 unaligned_store(r0, 0, s16);
85 unaligned_store(r1, 16, s16);
87 f += 8;
88 s16 += 16;
90 return(2*256);
91 #endif
94 static void* a52_resample_altivec(int flags, int ch){
95 fprintf(stderr, "Checking for AltiVec resampler : 0x%08x, %d\n", flags, ch);
97 switch (flags) {
98 case A52_CHANNEL:
99 case A52_STEREO:
100 case A52_DOLBY:
101 if(ch==2) return a52_resample_STEREO_to_2_altivec;
102 break;
104 default:
105 fprintf(stderr, "Unsupported flags: 0x%08x (%d channels)\n", flags, ch);
106 break;
108 return NULL;