Mercurial > mplayer.hg
annotate liba52/resample_c.c @ 21221:7124c26f3db3
Add generic target that allow compiling without any assembler or otherwise
architecture specific code (except endiannes of course).
Usage example: ./configure --target=generic-linux
author | reimar |
---|---|
date | Sat, 25 Nov 2006 17:58:33 +0000 |
parents | faf5af8e5481 |
children | b393dffbbcc7 |
rev | line source |
---|---|
3909 | 1 // this code is based on a52dec/libao/audio_out_oss.c |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
2 |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
3 static inline int16_t convert (int32_t i) |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
4 { |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
5 if (i > 0x43c07fff) |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
6 return 32767; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
7 else if (i < 0x43bf8000) |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
8 return -32768; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
9 else |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
10 return i - 0x43c00000; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
11 } |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
12 |
3909 | 13 static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){ |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
14 int i; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
15 int32_t * f = (int32_t *) _f; |
3626 | 16 for (i = 0; i < 256; i++) { |
17 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; | |
18 s16[5*i+4] = convert (f[i]); | |
19 } | |
3909 | 20 return 5*256; |
21 } | |
22 | |
3967 | 23 static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){ |
24 int i; | |
25 int32_t * f = (int32_t *) _f; | |
26 for (i = 0; i < 256; i++) { | |
27 s16[i] = convert (f[i]); | |
28 } | |
29 return 1*256; | |
30 } | |
31 | |
3909 | 32 static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){ |
33 int i; | |
34 int32_t * f = (int32_t *) _f; | |
3626 | 35 for (i = 0; i < 256; i++) { |
36 s16[2*i] = convert (f[i]); | |
37 s16[2*i+1] = convert (f[i+256]); | |
38 } | |
3909 | 39 return 2*256; |
40 } | |
41 | |
42 static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){ | |
43 int i; | |
44 int32_t * f = (int32_t *) _f; | |
3626 | 45 for (i = 0; i < 256; i++) { |
46 s16[5*i] = convert (f[i]); | |
47 s16[5*i+1] = convert (f[i+512]); | |
48 s16[5*i+2] = s16[5*i+3] = 0; | |
49 s16[5*i+4] = convert (f[i+256]); | |
50 } | |
3909 | 51 return 5*256; |
52 } | |
53 | |
54 static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){ | |
55 int i; | |
56 int32_t * f = (int32_t *) _f; | |
3626 | 57 for (i = 0; i < 256; i++) { |
58 s16[4*i] = convert (f[i]); | |
59 s16[4*i+1] = convert (f[i+256]); | |
60 s16[4*i+2] = convert (f[i+512]); | |
61 s16[4*i+3] = convert (f[i+768]); | |
62 } | |
3909 | 63 return 4*256; |
64 } | |
65 | |
66 static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){ | |
67 int i; | |
68 int32_t * f = (int32_t *) _f; | |
3626 | 69 for (i = 0; i < 256; i++) { |
70 s16[5*i] = convert (f[i]); | |
71 s16[5*i+1] = convert (f[i+512]); | |
72 s16[5*i+2] = convert (f[i+768]); | |
73 s16[5*i+3] = convert (f[i+1024]); | |
74 s16[5*i+4] = convert (f[i+256]); | |
75 } | |
3909 | 76 return 5*256; |
77 } | |
78 | |
79 static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){ | |
80 int i; | |
81 int32_t * f = (int32_t *) _f; | |
3626 | 82 for (i = 0; i < 256; i++) { |
83 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; | |
84 s16[6*i+4] = convert (f[i+256]); | |
85 s16[6*i+5] = convert (f[i]); | |
86 } | |
3909 | 87 return 6*256; |
88 } | |
89 | |
90 static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){ | |
91 int i; | |
92 int32_t * f = (int32_t *) _f; | |
3626 | 93 for (i = 0; i < 256; i++) { |
94 s16[6*i] = convert (f[i+256]); | |
95 s16[6*i+1] = convert (f[i+512]); | |
96 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; | |
97 s16[6*i+5] = convert (f[i]); | |
98 } | |
3909 | 99 return 6*256; |
100 } | |
101 | |
102 static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){ | |
103 int i; | |
104 int32_t * f = (int32_t *) _f; | |
3626 | 105 for (i = 0; i < 256; i++) { |
106 s16[6*i] = convert (f[i+256]); | |
107 s16[6*i+1] = convert (f[i+768]); | |
108 s16[6*i+2] = s16[6*i+3] = 0; | |
109 s16[6*i+4] = convert (f[i+512]); | |
110 s16[6*i+5] = convert (f[i]); | |
111 } | |
3909 | 112 return 6*256; |
113 } | |
114 | |
115 static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){ | |
116 int i; | |
117 int32_t * f = (int32_t *) _f; | |
3626 | 118 for (i = 0; i < 256; i++) { |
119 s16[6*i] = convert (f[i+256]); | |
120 s16[6*i+1] = convert (f[i+512]); | |
121 s16[6*i+2] = convert (f[i+768]); | |
122 s16[6*i+3] = convert (f[i+1024]); | |
123 s16[6*i+4] = 0; | |
124 s16[6*i+5] = convert (f[i]); | |
125 } | |
3909 | 126 return 6*256; |
127 } | |
128 | |
129 static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){ | |
130 int i; | |
131 int32_t * f = (int32_t *) _f; | |
3626 | 132 for (i = 0; i < 256; i++) { |
133 s16[6*i] = convert (f[i+256]); | |
134 s16[6*i+1] = convert (f[i+768]); | |
135 s16[6*i+2] = convert (f[i+1024]); | |
136 s16[6*i+3] = convert (f[i+1280]); | |
137 s16[6*i+4] = convert (f[i+512]); | |
138 s16[6*i+5] = convert (f[i]); | |
139 } | |
3909 | 140 return 6*256; |
3626 | 141 } |
142 | |
143 | |
3909 | 144 static void* a52_resample_C(int flags, int ch){ |
3626 | 145 switch (flags) { |
146 case A52_MONO: | |
3909 | 147 if(ch==5) return a52_resample_MONO_to_5_C; |
3967 | 148 if(ch==1) return a52_resample_MONO_to_1_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
149 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
150 case A52_CHANNEL: |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
151 case A52_STEREO: |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
152 case A52_DOLBY: |
3909 | 153 if(ch==2) return a52_resample_STEREO_to_2_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
154 break; |
3909 | 155 case A52_3F: |
156 if(ch==5) return a52_resample_3F_to_5_C; | |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
157 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
158 case A52_2F2R: |
3909 | 159 if(ch==4) return a52_resample_2F_2R_to_4_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
160 break; |
3909 | 161 case A52_3F2R: |
162 if(ch==5) return a52_resample_3F_2R_to_5_C; | |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
163 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
164 case A52_MONO | A52_LFE: |
3909 | 165 if(ch==6) return a52_resample_MONO_LFE_to_6_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
166 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
167 case A52_CHANNEL | A52_LFE: |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
168 case A52_STEREO | A52_LFE: |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
169 case A52_DOLBY | A52_LFE: |
3909 | 170 if(ch==6) return a52_resample_STEREO_LFE_to_6_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
171 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
172 case A52_3F | A52_LFE: |
3909 | 173 if(ch==6) return a52_resample_3F_LFE_to_6_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
174 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
175 case A52_2F2R | A52_LFE: |
3909 | 176 if(ch==6) return a52_resample_2F_2R_LFE_to_6_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
177 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
178 case A52_3F2R | A52_LFE: |
3909 | 179 if(ch==6) return a52_resample_3F_2R_LFE_to_6_C; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
180 break; |
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
181 } |
3909 | 182 return NULL; |
3412
21d65a4ae3c9
resample.c added - float->int conversion and channel ordering
arpi
parents:
diff
changeset
|
183 } |