summaryrefslogtreecommitdiff
path: root/apps/codecs/liba52/downmix.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/liba52/downmix.c')
-rw-r--r--apps/codecs/liba52/downmix.c674
1 files changed, 337 insertions, 337 deletions
diff --git a/apps/codecs/liba52/downmix.c b/apps/codecs/liba52/downmix.c
index 2e8567bceb..b9506de8c1 100644
--- a/apps/codecs/liba52/downmix.c
+++ b/apps/codecs/liba52/downmix.c
@@ -32,135 +32,135 @@
32#define CONVERT(acmod,output) (((output) << 3) + (acmod)) 32#define CONVERT(acmod,output) (((output) << 3) + (acmod))
33 33
34int a52_downmix_init (int input, int flags, level_t * level, 34int a52_downmix_init (int input, int flags, level_t * level,
35 level_t clev, level_t slev) 35 level_t clev, level_t slev)
36{ 36{
37 static uint8_t table[11][8] = { 37 static uint8_t table[11][8] = {
38 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO, 38 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
39 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO}, 39 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
40 {A52_MONO, A52_MONO, A52_MONO, A52_MONO, 40 {A52_MONO, A52_MONO, A52_MONO, A52_MONO,
41 A52_MONO, A52_MONO, A52_MONO, A52_MONO}, 41 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
42 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO, 42 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
43 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO}, 43 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
44 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F, 44 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
45 A52_STEREO, A52_3F, A52_STEREO, A52_3F}, 45 A52_STEREO, A52_3F, A52_STEREO, A52_3F},
46 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO, 46 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
47 A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R}, 47 A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R},
48 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO, 48 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
49 A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R}, 49 A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R},
50 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F, 50 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
51 A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R}, 51 A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R},
52 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F, 52 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
53 A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R}, 53 A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R},
54 {A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO, 54 {A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO,
55 A52_MONO, A52_MONO, A52_MONO, A52_MONO}, 55 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
56 {A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO, 56 {A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO,
57 A52_MONO, A52_MONO, A52_MONO, A52_MONO}, 57 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
58 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY, 58 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY,
59 A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY} 59 A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY}
60 }; 60 };
61 int output; 61 int output;
62 62
63 output = flags & A52_CHANNEL_MASK; 63 output = flags & A52_CHANNEL_MASK;
64 if (output > A52_DOLBY) 64 if (output > A52_DOLBY)
65 return -1; 65 return -1;
66 66
67 output = table[output][input & 7]; 67 output = table[output][input & 7];
68 68
69 if (output == A52_STEREO && 69 if (output == A52_STEREO &&
70 (input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB)))) 70 (input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB))))
71 output = A52_DOLBY; 71 output = A52_DOLBY;
72 72
73 if (flags & A52_ADJUST_LEVEL) { 73 if (flags & A52_ADJUST_LEVEL) {
74 level_t adjust; 74 level_t adjust;
75 75
76 switch (CONVERT (input & 7, output)) { 76 switch (CONVERT (input & 7, output)) {
77 77
78 case CONVERT (A52_3F, A52_MONO): 78 case CONVERT (A52_3F, A52_MONO):
79 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev); 79 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
80 break; 80 break;
81 81
82 case CONVERT (A52_STEREO, A52_MONO): 82 case CONVERT (A52_STEREO, A52_MONO):
83 case CONVERT (A52_2F2R, A52_2F1R): 83 case CONVERT (A52_2F2R, A52_2F1R):
84 case CONVERT (A52_3F2R, A52_3F1R): 84 case CONVERT (A52_3F2R, A52_3F1R):
85 level_3db: 85 level_3db:
86 adjust = LEVEL (LEVEL_3DB); 86 adjust = LEVEL (LEVEL_3DB);
87 break; 87 break;
88 88
89 case CONVERT (A52_3F2R, A52_2F1R): 89 case CONVERT (A52_3F2R, A52_2F1R):
90 if (clev < LEVEL (LEVEL_PLUS3DB - 1)) 90 if (clev < LEVEL (LEVEL_PLUS3DB - 1))
91 goto level_3db; 91 goto level_3db;
92 /* break thru */ 92 /* break thru */
93 case CONVERT (A52_3F, A52_STEREO): 93 case CONVERT (A52_3F, A52_STEREO):
94 case CONVERT (A52_3F1R, A52_2F1R): 94 case CONVERT (A52_3F1R, A52_2F1R):
95 case CONVERT (A52_3F1R, A52_2F2R): 95 case CONVERT (A52_3F1R, A52_2F2R):
96 case CONVERT (A52_3F2R, A52_2F2R): 96 case CONVERT (A52_3F2R, A52_2F2R):
97 adjust = DIV (1, LEVEL (1) + clev); 97 adjust = DIV (1, LEVEL (1) + clev);
98 break; 98 break;
99 99
100 case CONVERT (A52_2F1R, A52_MONO): 100 case CONVERT (A52_2F1R, A52_MONO):
101 adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev); 101 adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
102 break; 102 break;
103 103
104 case CONVERT (A52_2F1R, A52_STEREO): 104 case CONVERT (A52_2F1R, A52_STEREO):
105 case CONVERT (A52_3F1R, A52_3F): 105 case CONVERT (A52_3F1R, A52_3F):
106 adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB)); 106 adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
107 break; 107 break;
108 108
109 case CONVERT (A52_3F1R, A52_MONO): 109 case CONVERT (A52_3F1R, A52_MONO):
110 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5)); 110 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
111 break; 111 break;
112 112
113 case CONVERT (A52_3F1R, A52_STEREO): 113 case CONVERT (A52_3F1R, A52_STEREO):
114 adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB)); 114 adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
115 break; 115 break;
116 116
117 case CONVERT (A52_2F2R, A52_MONO): 117 case CONVERT (A52_2F2R, A52_MONO):
118 adjust = DIV (LEVEL_3DB, LEVEL (1) + slev); 118 adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
119 break; 119 break;
120 120
121 case CONVERT (A52_2F2R, A52_STEREO): 121 case CONVERT (A52_2F2R, A52_STEREO):
122 case CONVERT (A52_3F2R, A52_3F): 122 case CONVERT (A52_3F2R, A52_3F):
123 adjust = DIV (1, LEVEL (1) + slev); 123 adjust = DIV (1, LEVEL (1) + slev);
124 break; 124 break;
125 125
126 case CONVERT (A52_3F2R, A52_MONO): 126 case CONVERT (A52_3F2R, A52_MONO):
127 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev); 127 adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
128 break; 128 break;
129 129
130 case CONVERT (A52_3F2R, A52_STEREO): 130 case CONVERT (A52_3F2R, A52_STEREO):
131 adjust = DIV (1, LEVEL (1) + clev + slev); 131 adjust = DIV (1, LEVEL (1) + clev + slev);
132 break; 132 break;
133 133
134 case CONVERT (A52_MONO, A52_DOLBY): 134 case CONVERT (A52_MONO, A52_DOLBY):
135 adjust = LEVEL (LEVEL_PLUS3DB); 135 adjust = LEVEL (LEVEL_PLUS3DB);
136 break; 136 break;
137 137
138 case CONVERT (A52_3F, A52_DOLBY): 138 case CONVERT (A52_3F, A52_DOLBY):
139 case CONVERT (A52_2F1R, A52_DOLBY): 139 case CONVERT (A52_2F1R, A52_DOLBY):
140 adjust = LEVEL (1 / (1 + LEVEL_3DB)); 140 adjust = LEVEL (1 / (1 + LEVEL_3DB));
141 break; 141 break;
142 142
143 case CONVERT (A52_3F1R, A52_DOLBY): 143 case CONVERT (A52_3F1R, A52_DOLBY):
144 case CONVERT (A52_2F2R, A52_DOLBY): 144 case CONVERT (A52_2F2R, A52_DOLBY):
145 adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB)); 145 adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
146 break; 146 break;
147 147
148 case CONVERT (A52_3F2R, A52_DOLBY): 148 case CONVERT (A52_3F2R, A52_DOLBY):
149 adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB)); 149 adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
150 break; 150 break;
151 151
152 default: 152 default:
153 return output; 153 return output;
154 } 154 }
155 155
156 *level = MUL_L (*level, adjust); 156 *level = MUL_L (*level, adjust);
157 } 157 }
158 158
159 return output; 159 return output;
160} 160}
161 161
162int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level, 162int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
163 level_t clev, level_t slev) 163 level_t clev, level_t slev)
164{ 164{
165 level_t level_3db; 165 level_t level_3db;
166 166
@@ -177,156 +177,156 @@ int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
177 case CONVERT (A52_2F2R, A52_2F2R): 177 case CONVERT (A52_2F2R, A52_2F2R):
178 case CONVERT (A52_3F2R, A52_3F2R): 178 case CONVERT (A52_3F2R, A52_3F2R):
179 case CONVERT (A52_STEREO, A52_DOLBY): 179 case CONVERT (A52_STEREO, A52_DOLBY):
180 coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level; 180 coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
181 return 0; 181 return 0;
182 182
183 case CONVERT (A52_CHANNEL, A52_MONO): 183 case CONVERT (A52_CHANNEL, A52_MONO):
184 coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB); 184 coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
185 return 3; 185 return 3;
186 186
187 case CONVERT (A52_STEREO, A52_MONO): 187 case CONVERT (A52_STEREO, A52_MONO):
188 coeff[0] = coeff[1] = level_3db; 188 coeff[0] = coeff[1] = level_3db;
189 return 3; 189 return 3;
190 190
191 case CONVERT (A52_3F, A52_MONO): 191 case CONVERT (A52_3F, A52_MONO):
192 coeff[0] = coeff[2] = level_3db; 192 coeff[0] = coeff[2] = level_3db;
193 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB); 193 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
194 return 7; 194 return 7;
195 195
196 case CONVERT (A52_2F1R, A52_MONO): 196 case CONVERT (A52_2F1R, A52_MONO):
197 coeff[0] = coeff[1] = level_3db; 197 coeff[0] = coeff[1] = level_3db;
198 coeff[2] = MUL_L (level_3db, slev); 198 coeff[2] = MUL_L (level_3db, slev);
199 return 7; 199 return 7;
200 200
201 case CONVERT (A52_2F2R, A52_MONO): 201 case CONVERT (A52_2F2R, A52_MONO):
202 coeff[0] = coeff[1] = level_3db; 202 coeff[0] = coeff[1] = level_3db;
203 coeff[2] = coeff[3] = MUL_L (level_3db, slev); 203 coeff[2] = coeff[3] = MUL_L (level_3db, slev);
204 return 15; 204 return 15;
205 205
206 case CONVERT (A52_3F1R, A52_MONO): 206 case CONVERT (A52_3F1R, A52_MONO):
207 coeff[0] = coeff[2] = level_3db; 207 coeff[0] = coeff[2] = level_3db;
208 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB); 208 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
209 coeff[3] = MUL_L (level_3db, slev); 209 coeff[3] = MUL_L (level_3db, slev);
210 return 15; 210 return 15;
211 211
212 case CONVERT (A52_3F2R, A52_MONO): 212 case CONVERT (A52_3F2R, A52_MONO):
213 coeff[0] = coeff[2] = level_3db; 213 coeff[0] = coeff[2] = level_3db;
214 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB); 214 coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
215 coeff[3] = coeff[4] = MUL_L (level_3db, slev); 215 coeff[3] = coeff[4] = MUL_L (level_3db, slev);
216 return 31; 216 return 31;
217 217
218 case CONVERT (A52_MONO, A52_DOLBY): 218 case CONVERT (A52_MONO, A52_DOLBY):
219 coeff[0] = level_3db; 219 coeff[0] = level_3db;
220 return 0; 220 return 0;
221 221
222 case CONVERT (A52_3F, A52_DOLBY): 222 case CONVERT (A52_3F, A52_DOLBY):
223 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level; 223 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
224 coeff[1] = level_3db; 224 coeff[1] = level_3db;
225 return 7; 225 return 7;
226 226
227 case CONVERT (A52_3F, A52_STEREO): 227 case CONVERT (A52_3F, A52_STEREO):
228 case CONVERT (A52_3F1R, A52_2F1R): 228 case CONVERT (A52_3F1R, A52_2F1R):
229 case CONVERT (A52_3F2R, A52_2F2R): 229 case CONVERT (A52_3F2R, A52_2F2R):
230 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level; 230 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
231 coeff[1] = MUL_L (level, clev); 231 coeff[1] = MUL_L (level, clev);
232 return 7; 232 return 7;
233 233
234 case CONVERT (A52_2F1R, A52_DOLBY): 234 case CONVERT (A52_2F1R, A52_DOLBY):
235 coeff[0] = coeff[1] = level; 235 coeff[0] = coeff[1] = level;
236 coeff[2] = level_3db; 236 coeff[2] = level_3db;
237 return 7; 237 return 7;
238 238
239 case CONVERT (A52_2F1R, A52_STEREO): 239 case CONVERT (A52_2F1R, A52_STEREO):
240 coeff[0] = coeff[1] = level; 240 coeff[0] = coeff[1] = level;
241 coeff[2] = MUL_L (level_3db, slev); 241 coeff[2] = MUL_L (level_3db, slev);
242 return 7; 242 return 7;
243 243
244 case CONVERT (A52_3F1R, A52_DOLBY): 244 case CONVERT (A52_3F1R, A52_DOLBY):
245 coeff[0] = coeff[2] = level; 245 coeff[0] = coeff[2] = level;
246 coeff[1] = coeff[3] = level_3db; 246 coeff[1] = coeff[3] = level_3db;
247 return 15; 247 return 15;
248 248
249 case CONVERT (A52_3F1R, A52_STEREO): 249 case CONVERT (A52_3F1R, A52_STEREO):
250 coeff[0] = coeff[2] = level; 250 coeff[0] = coeff[2] = level;
251 coeff[1] = MUL_L (level, clev); 251 coeff[1] = MUL_L (level, clev);
252 coeff[3] = MUL_L (level_3db, slev); 252 coeff[3] = MUL_L (level_3db, slev);
253 return 15; 253 return 15;
254 254
255 case CONVERT (A52_2F2R, A52_DOLBY): 255 case CONVERT (A52_2F2R, A52_DOLBY):
256 coeff[0] = coeff[1] = level; 256 coeff[0] = coeff[1] = level;
257 coeff[2] = coeff[3] = level_3db; 257 coeff[2] = coeff[3] = level_3db;
258 return 15; 258 return 15;
259 259
260 case CONVERT (A52_2F2R, A52_STEREO): 260 case CONVERT (A52_2F2R, A52_STEREO):
261 coeff[0] = coeff[1] = level; 261 coeff[0] = coeff[1] = level;
262 coeff[2] = coeff[3] = MUL_L (level, slev); 262 coeff[2] = coeff[3] = MUL_L (level, slev);
263 return 15; 263 return 15;
264 264
265 case CONVERT (A52_3F2R, A52_DOLBY): 265 case CONVERT (A52_3F2R, A52_DOLBY):
266 coeff[0] = coeff[2] = level; 266 coeff[0] = coeff[2] = level;
267 coeff[1] = coeff[3] = coeff[4] = level_3db; 267 coeff[1] = coeff[3] = coeff[4] = level_3db;
268 return 31; 268 return 31;
269 269
270 case CONVERT (A52_3F2R, A52_2F1R): 270 case CONVERT (A52_3F2R, A52_2F1R):
271 coeff[0] = coeff[2] = level; 271 coeff[0] = coeff[2] = level;
272 coeff[1] = MUL_L (level, clev); 272 coeff[1] = MUL_L (level, clev);
273 coeff[3] = coeff[4] = level_3db; 273 coeff[3] = coeff[4] = level_3db;
274 return 31; 274 return 31;
275 275
276 case CONVERT (A52_3F2R, A52_STEREO): 276 case CONVERT (A52_3F2R, A52_STEREO):
277 coeff[0] = coeff[2] = level; 277 coeff[0] = coeff[2] = level;
278 coeff[1] = MUL_L (level, clev); 278 coeff[1] = MUL_L (level, clev);
279 coeff[3] = coeff[4] = MUL_L (level, slev); 279 coeff[3] = coeff[4] = MUL_L (level, slev);
280 return 31; 280 return 31;
281 281
282 case CONVERT (A52_3F1R, A52_3F): 282 case CONVERT (A52_3F1R, A52_3F):
283 coeff[0] = coeff[1] = coeff[2] = level; 283 coeff[0] = coeff[1] = coeff[2] = level;
284 coeff[3] = MUL_L (level_3db, slev); 284 coeff[3] = MUL_L (level_3db, slev);
285 return 13; 285 return 13;
286 286
287 case CONVERT (A52_3F2R, A52_3F): 287 case CONVERT (A52_3F2R, A52_3F):
288 coeff[0] = coeff[1] = coeff[2] = level; 288 coeff[0] = coeff[1] = coeff[2] = level;
289 coeff[3] = coeff[4] = MUL_L (level, slev); 289 coeff[3] = coeff[4] = MUL_L (level, slev);
290 return 29; 290 return 29;
291 291
292 case CONVERT (A52_2F2R, A52_2F1R): 292 case CONVERT (A52_2F2R, A52_2F1R):
293 coeff[0] = coeff[1] = level; 293 coeff[0] = coeff[1] = level;
294 coeff[2] = coeff[3] = level_3db; 294 coeff[2] = coeff[3] = level_3db;
295 return 12; 295 return 12;
296 296
297 case CONVERT (A52_3F2R, A52_3F1R): 297 case CONVERT (A52_3F2R, A52_3F1R):
298 coeff[0] = coeff[1] = coeff[2] = level; 298 coeff[0] = coeff[1] = coeff[2] = level;
299 coeff[3] = coeff[4] = level_3db; 299 coeff[3] = coeff[4] = level_3db;
300 return 24; 300 return 24;
301 301
302 case CONVERT (A52_2F1R, A52_2F2R): 302 case CONVERT (A52_2F1R, A52_2F2R):
303 coeff[0] = coeff[1] = level; 303 coeff[0] = coeff[1] = level;
304 coeff[2] = level_3db; 304 coeff[2] = level_3db;
305 return 0; 305 return 0;
306 306
307 case CONVERT (A52_3F1R, A52_2F2R): 307 case CONVERT (A52_3F1R, A52_2F2R):
308 coeff[0] = coeff[2] = level; 308 coeff[0] = coeff[2] = level;
309 coeff[1] = MUL_L (level, clev); 309 coeff[1] = MUL_L (level, clev);
310 coeff[3] = level_3db; 310 coeff[3] = level_3db;
311 return 7; 311 return 7;
312 312
313 case CONVERT (A52_3F1R, A52_3F2R): 313 case CONVERT (A52_3F1R, A52_3F2R):
314 coeff[0] = coeff[1] = coeff[2] = level; 314 coeff[0] = coeff[1] = coeff[2] = level;
315 coeff[3] = level_3db; 315 coeff[3] = level_3db;
316 return 0; 316 return 0;
317 317
318 case CONVERT (A52_CHANNEL, A52_CHANNEL1): 318 case CONVERT (A52_CHANNEL, A52_CHANNEL1):
319 coeff[0] = level; 319 coeff[0] = level;
320 coeff[1] = 0; 320 coeff[1] = 0;
321 return 0; 321 return 0;
322 322
323 case CONVERT (A52_CHANNEL, A52_CHANNEL2): 323 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
324 coeff[0] = 0; 324 coeff[0] = 0;
325 coeff[1] = level; 325 coeff[1] = level;
326 return 0; 326 return 0;
327 } 327 }
328 328
329 return -1; /* NOTREACHED */ 329 return -1; /* NOTREACHED */
330} 330}
331 331
332static void mix2to1 (sample_t * dest, sample_t * src) 332static void mix2to1 (sample_t * dest, sample_t * src)
@@ -334,7 +334,7 @@ static void mix2to1 (sample_t * dest, sample_t * src)
334 int i; 334 int i;
335 335
336 for (i = 0; i < 256; i++) 336 for (i = 0; i < 256; i++)
337 dest[i] += BIAS (src[i]); 337 dest[i] += BIAS (src[i]);
338} 338}
339 339
340static void mix3to1 (sample_t * samples) 340static void mix3to1 (sample_t * samples)
@@ -342,7 +342,7 @@ static void mix3to1 (sample_t * samples)
342 int i; 342 int i;
343 343
344 for (i = 0; i < 256; i++) 344 for (i = 0; i < 256; i++)
345 samples[i] += BIAS (samples[i + 256] + samples[i + 512]); 345 samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
346} 346}
347 347
348static void mix4to1 (sample_t * samples) 348static void mix4to1 (sample_t * samples)
@@ -350,8 +350,8 @@ static void mix4to1 (sample_t * samples)
350 int i; 350 int i;
351 351
352 for (i = 0; i < 256; i++) 352 for (i = 0; i < 256; i++)
353 samples[i] += BIAS (samples[i + 256] + samples[i + 512] + 353 samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
354 samples[i + 768]); 354 samples[i + 768]);
355} 355}
356 356
357static void mix5to1 (sample_t * samples) 357static void mix5to1 (sample_t * samples)
@@ -359,8 +359,8 @@ static void mix5to1 (sample_t * samples)
359 int i; 359 int i;
360 360
361 for (i = 0; i < 256; i++) 361 for (i = 0; i < 256; i++)
362 samples[i] += BIAS (samples[i + 256] + samples[i + 512] + 362 samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
363 samples[i + 768] + samples[i + 1024]); 363 samples[i + 768] + samples[i + 1024]);
364} 364}
365 365
366static void mix3to2 (sample_t * samples) 366static void mix3to2 (sample_t * samples)
@@ -369,9 +369,9 @@ static void mix3to2 (sample_t * samples)
369 sample_t common; 369 sample_t common;
370 370
371 for (i = 0; i < 256; i++) { 371 for (i = 0; i < 256; i++) {
372 common = BIAS (samples[i + 256]); 372 common = BIAS (samples[i + 256]);
373 samples[i] += common; 373 samples[i] += common;
374 samples[i + 256] = samples[i + 512] + common; 374 samples[i + 256] = samples[i + 512] + common;
375 } 375 }
376} 376}
377 377
@@ -381,9 +381,9 @@ static void mix21to2 (sample_t * left, sample_t * right)
381 sample_t common; 381 sample_t common;
382 382
383 for (i = 0; i < 256; i++) { 383 for (i = 0; i < 256; i++) {
384 common = BIAS (right[i + 256]); 384 common = BIAS (right[i + 256]);
385 left[i] += common; 385 left[i] += common;
386 right[i] += common; 386 right[i] += common;
387 } 387 }
388} 388}
389 389
@@ -393,9 +393,9 @@ static void mix21toS (sample_t * samples)
393 sample_t surround; 393 sample_t surround;
394 394
395 for (i = 0; i < 256; i++) { 395 for (i = 0; i < 256; i++) {
396 surround = samples[i + 512]; 396 surround = samples[i + 512];
397 samples[i] += BIAS (-surround); 397 samples[i] += BIAS (-surround);
398 samples[i + 256] += BIAS (surround); 398 samples[i + 256] += BIAS (surround);
399 } 399 }
400} 400}
401 401
@@ -405,9 +405,9 @@ static void mix31to2 (sample_t * samples)
405 sample_t common; 405 sample_t common;
406 406
407 for (i = 0; i < 256; i++) { 407 for (i = 0; i < 256; i++) {
408 common = BIAS (samples[i + 256] + samples[i + 768]); 408 common = BIAS (samples[i + 256] + samples[i + 768]);
409 samples[i] += common; 409 samples[i] += common;
410 samples[i + 256] = samples[i + 512] + common; 410 samples[i + 256] = samples[i + 512] + common;
411 } 411 }
412} 412}
413 413
@@ -417,10 +417,10 @@ static void mix31toS (sample_t * samples)
417 sample_t common, surround; 417 sample_t common, surround;
418 418
419 for (i = 0; i < 256; i++) { 419 for (i = 0; i < 256; i++) {
420 common = BIAS (samples[i + 256]); 420 common = BIAS (samples[i + 256]);
421 surround = samples[i + 768]; 421 surround = samples[i + 768];
422 samples[i] += common - surround; 422 samples[i] += common - surround;
423 samples[i + 256] = samples[i + 512] + common + surround; 423 samples[i + 256] = samples[i + 512] + common + surround;
424 } 424 }
425} 425}
426 426
@@ -430,9 +430,9 @@ static void mix22toS (sample_t * samples)
430 sample_t surround; 430 sample_t surround;
431 431
432 for (i = 0; i < 256; i++) { 432 for (i = 0; i < 256; i++) {
433 surround = samples[i + 512] + samples[i + 768]; 433 surround = samples[i + 512] + samples[i + 768];
434 samples[i] += BIAS (-surround); 434 samples[i] += BIAS (-surround);
435 samples[i + 256] += BIAS (surround); 435 samples[i + 256] += BIAS (surround);
436 } 436 }
437} 437}
438 438
@@ -442,9 +442,9 @@ static void mix32to2 (sample_t * samples)
442 sample_t common; 442 sample_t common;
443 443
444 for (i = 0; i < 256; i++) { 444 for (i = 0; i < 256; i++) {
445 common = BIAS (samples[i + 256]); 445 common = BIAS (samples[i + 256]);
446 samples[i] += common + samples[i + 768]; 446 samples[i] += common + samples[i + 768];
447 samples[i + 256] = common + samples[i + 512] + samples[i + 1024]; 447 samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
448 } 448 }
449} 449}
450 450
@@ -454,10 +454,10 @@ static void mix32toS (sample_t * samples)
454 sample_t common, surround; 454 sample_t common, surround;
455 455
456 for (i = 0; i < 256; i++) { 456 for (i = 0; i < 256; i++) {
457 common = BIAS (samples[i + 256]); 457 common = BIAS (samples[i + 256]);
458 surround = samples[i + 768] + samples[i + 1024]; 458 surround = samples[i + 768] + samples[i + 1024];
459 samples[i] += common - surround; 459 samples[i] += common - surround;
460 samples[i + 256] = samples[i + 512] + common + surround; 460 samples[i + 256] = samples[i + 512] + common + surround;
461 } 461 }
462} 462}
463 463
@@ -466,7 +466,7 @@ static void move2to1 (sample_t * src, sample_t * dest)
466 int i; 466 int i;
467 467
468 for (i = 0; i < 256; i++) 468 for (i = 0; i < 256; i++)
469 dest[i] = BIAS (src[i] + src[i + 256]); 469 dest[i] = BIAS (src[i] + src[i + 256]);
470} 470}
471 471
472static void zero (sample_t * samples) 472static void zero (sample_t * samples)
@@ -474,11 +474,11 @@ static void zero (sample_t * samples)
474 int i; 474 int i;
475 475
476 for (i = 0; i < 256; i++) 476 for (i = 0; i < 256; i++)
477 samples[i] = 0; 477 samples[i] = 0;
478} 478}
479 479
480void a52_downmix (sample_t * samples, int acmod, int output, 480void a52_downmix (sample_t * samples, int acmod, int output,
481 level_t clev, level_t slev) 481 level_t clev, level_t slev)
482{ 482{
483 /* avoid compiler warning */ 483 /* avoid compiler warning */
484 (void)clev; 484 (void)clev;
@@ -486,138 +486,138 @@ void a52_downmix (sample_t * samples, int acmod, int output,
486 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) { 486 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
487 487
488 case CONVERT (A52_CHANNEL, A52_CHANNEL2): 488 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
489 memcpy (samples, samples + 256, 256 * sizeof (sample_t)); 489 memcpy (samples, samples + 256, 256 * sizeof (sample_t));
490 break; 490 break;
491 491
492 case CONVERT (A52_CHANNEL, A52_MONO): 492 case CONVERT (A52_CHANNEL, A52_MONO):
493 case CONVERT (A52_STEREO, A52_MONO): 493 case CONVERT (A52_STEREO, A52_MONO):
494 mix_2to1: 494 mix_2to1:
495 mix2to1 (samples, samples + 256); 495 mix2to1 (samples, samples + 256);
496 break; 496 break;
497 497
498 case CONVERT (A52_2F1R, A52_MONO): 498 case CONVERT (A52_2F1R, A52_MONO):
499 if (slev == 0) 499 if (slev == 0)
500 goto mix_2to1; 500 goto mix_2to1;
501 case CONVERT (A52_3F, A52_MONO): 501 case CONVERT (A52_3F, A52_MONO):
502 mix_3to1: 502 mix_3to1:
503 mix3to1 (samples); 503 mix3to1 (samples);
504 break; 504 break;
505 505
506 case CONVERT (A52_3F1R, A52_MONO): 506 case CONVERT (A52_3F1R, A52_MONO):
507 if (slev == 0) 507 if (slev == 0)
508 goto mix_3to1; 508 goto mix_3to1;
509 case CONVERT (A52_2F2R, A52_MONO): 509 case CONVERT (A52_2F2R, A52_MONO):
510 if (slev == 0) 510 if (slev == 0)
511 goto mix_2to1; 511 goto mix_2to1;
512 mix4to1 (samples); 512 mix4to1 (samples);
513 break; 513 break;
514 514
515 case CONVERT (A52_3F2R, A52_MONO): 515 case CONVERT (A52_3F2R, A52_MONO):
516 if (slev == 0) 516 if (slev == 0)
517 goto mix_3to1; 517 goto mix_3to1;
518 mix5to1 (samples); 518 mix5to1 (samples);
519 break; 519 break;
520 520
521 case CONVERT (A52_MONO, A52_DOLBY): 521 case CONVERT (A52_MONO, A52_DOLBY):
522 memcpy (samples + 256, samples, 256 * sizeof (sample_t)); 522 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
523 break; 523 break;
524 524
525 case CONVERT (A52_3F, A52_STEREO): 525 case CONVERT (A52_3F, A52_STEREO):
526 case CONVERT (A52_3F, A52_DOLBY): 526 case CONVERT (A52_3F, A52_DOLBY):
527 mix_3to2: 527 mix_3to2:
528 mix3to2 (samples); 528 mix3to2 (samples);
529 break; 529 break;
530 530
531 case CONVERT (A52_2F1R, A52_STEREO): 531 case CONVERT (A52_2F1R, A52_STEREO):
532 if (slev == 0) 532 if (slev == 0)
533 break; 533 break;
534 mix21to2 (samples, samples + 256); 534 mix21to2 (samples, samples + 256);
535 break; 535 break;
536 536
537 case CONVERT (A52_2F1R, A52_DOLBY): 537 case CONVERT (A52_2F1R, A52_DOLBY):
538 mix21toS (samples); 538 mix21toS (samples);
539 break; 539 break;
540 540
541 case CONVERT (A52_3F1R, A52_STEREO): 541 case CONVERT (A52_3F1R, A52_STEREO):
542 if (slev == 0) 542 if (slev == 0)
543 goto mix_3to2; 543 goto mix_3to2;
544 mix31to2 (samples); 544 mix31to2 (samples);
545 break; 545 break;
546 546
547 case CONVERT (A52_3F1R, A52_DOLBY): 547 case CONVERT (A52_3F1R, A52_DOLBY):
548 mix31toS (samples); 548 mix31toS (samples);
549 break; 549 break;
550 550
551 case CONVERT (A52_2F2R, A52_STEREO): 551 case CONVERT (A52_2F2R, A52_STEREO):
552 if (slev == 0) 552 if (slev == 0)
553 break; 553 break;
554 mix2to1 (samples, samples + 512); 554 mix2to1 (samples, samples + 512);
555 mix2to1 (samples + 256, samples + 768); 555 mix2to1 (samples + 256, samples + 768);
556 break; 556 break;
557 557
558 case CONVERT (A52_2F2R, A52_DOLBY): 558 case CONVERT (A52_2F2R, A52_DOLBY):
559 mix22toS (samples); 559 mix22toS (samples);
560 break; 560 break;
561 561
562 case CONVERT (A52_3F2R, A52_STEREO): 562 case CONVERT (A52_3F2R, A52_STEREO):
563 if (slev == 0) 563 if (slev == 0)
564 goto mix_3to2; 564 goto mix_3to2;
565 mix32to2 (samples); 565 mix32to2 (samples);
566 break; 566 break;
567 567
568 case CONVERT (A52_3F2R, A52_DOLBY): 568 case CONVERT (A52_3F2R, A52_DOLBY):
569 mix32toS (samples); 569 mix32toS (samples);
570 break; 570 break;
571 571
572 case CONVERT (A52_3F1R, A52_3F): 572 case CONVERT (A52_3F1R, A52_3F):
573 if (slev == 0) 573 if (slev == 0)
574 break; 574 break;
575 mix21to2 (samples, samples + 512); 575 mix21to2 (samples, samples + 512);
576 break; 576 break;
577 577
578 case CONVERT (A52_3F2R, A52_3F): 578 case CONVERT (A52_3F2R, A52_3F):
579 if (slev == 0) 579 if (slev == 0)
580 break; 580 break;
581 mix2to1 (samples, samples + 768); 581 mix2to1 (samples, samples + 768);
582 mix2to1 (samples + 512, samples + 1024); 582 mix2to1 (samples + 512, samples + 1024);
583 break; 583 break;
584 584
585 case CONVERT (A52_3F1R, A52_2F1R): 585 case CONVERT (A52_3F1R, A52_2F1R):
586 mix3to2 (samples); 586 mix3to2 (samples);
587 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t)); 587 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
588 break; 588 break;
589 589
590 case CONVERT (A52_2F2R, A52_2F1R): 590 case CONVERT (A52_2F2R, A52_2F1R):
591 mix2to1 (samples + 512, samples + 768); 591 mix2to1 (samples + 512, samples + 768);
592 break; 592 break;
593 593
594 case CONVERT (A52_3F2R, A52_2F1R): 594 case CONVERT (A52_3F2R, A52_2F1R):
595 mix3to2 (samples); 595 mix3to2 (samples);
596 move2to1 (samples + 768, samples + 512); 596 move2to1 (samples + 768, samples + 512);
597 break; 597 break;
598 598
599 case CONVERT (A52_3F2R, A52_3F1R): 599 case CONVERT (A52_3F2R, A52_3F1R):
600 mix2to1 (samples + 768, samples + 1024); 600 mix2to1 (samples + 768, samples + 1024);
601 break; 601 break;
602 602
603 case CONVERT (A52_2F1R, A52_2F2R): 603 case CONVERT (A52_2F1R, A52_2F2R):
604 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t)); 604 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
605 break; 605 break;
606 606
607 case CONVERT (A52_3F1R, A52_2F2R): 607 case CONVERT (A52_3F1R, A52_2F2R):
608 mix3to2 (samples); 608 mix3to2 (samples);
609 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t)); 609 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
610 break; 610 break;
611 611
612 case CONVERT (A52_3F2R, A52_2F2R): 612 case CONVERT (A52_3F2R, A52_2F2R):
613 mix3to2 (samples); 613 mix3to2 (samples);
614 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t)); 614 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
615 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t)); 615 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
616 break; 616 break;
617 617
618 case CONVERT (A52_3F1R, A52_3F2R): 618 case CONVERT (A52_3F1R, A52_3F2R):
619 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t)); 619 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
620 break; 620 break;
621 } 621 }
622} 622}
623 623
@@ -626,63 +626,63 @@ void a52_upmix (sample_t * samples, int acmod, int output)
626 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) { 626 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
627 627
628 case CONVERT (A52_CHANNEL, A52_CHANNEL2): 628 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
629 memcpy (samples + 256, samples, 256 * sizeof (sample_t)); 629 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
630 break; 630 break;
631 631
632 case CONVERT (A52_3F2R, A52_MONO): 632 case CONVERT (A52_3F2R, A52_MONO):
633 zero (samples + 1024); 633 zero (samples + 1024);
634 case CONVERT (A52_3F1R, A52_MONO): 634 case CONVERT (A52_3F1R, A52_MONO):
635 case CONVERT (A52_2F2R, A52_MONO): 635 case CONVERT (A52_2F2R, A52_MONO):
636 zero (samples + 768); 636 zero (samples + 768);
637 case CONVERT (A52_3F, A52_MONO): 637 case CONVERT (A52_3F, A52_MONO):
638 case CONVERT (A52_2F1R, A52_MONO): 638 case CONVERT (A52_2F1R, A52_MONO):
639 zero (samples + 512); 639 zero (samples + 512);
640 case CONVERT (A52_CHANNEL, A52_MONO): 640 case CONVERT (A52_CHANNEL, A52_MONO):
641 case CONVERT (A52_STEREO, A52_MONO): 641 case CONVERT (A52_STEREO, A52_MONO):
642 zero (samples + 256); 642 zero (samples + 256);
643 break; 643 break;
644 644
645 case CONVERT (A52_3F2R, A52_STEREO): 645 case CONVERT (A52_3F2R, A52_STEREO):
646 case CONVERT (A52_3F2R, A52_DOLBY): 646 case CONVERT (A52_3F2R, A52_DOLBY):
647 zero (samples + 1024); 647 zero (samples + 1024);
648 case CONVERT (A52_3F1R, A52_STEREO): 648 case CONVERT (A52_3F1R, A52_STEREO):
649 case CONVERT (A52_3F1R, A52_DOLBY): 649 case CONVERT (A52_3F1R, A52_DOLBY):
650 zero (samples + 768); 650 zero (samples + 768);
651 case CONVERT (A52_3F, A52_STEREO): 651 case CONVERT (A52_3F, A52_STEREO):
652 case CONVERT (A52_3F, A52_DOLBY): 652 case CONVERT (A52_3F, A52_DOLBY):
653 mix_3to2: 653 mix_3to2:
654 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t)); 654 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
655 zero (samples + 256); 655 zero (samples + 256);
656 break; 656 break;
657 657
658 case CONVERT (A52_2F2R, A52_STEREO): 658 case CONVERT (A52_2F2R, A52_STEREO):
659 case CONVERT (A52_2F2R, A52_DOLBY): 659 case CONVERT (A52_2F2R, A52_DOLBY):
660 zero (samples + 768); 660 zero (samples + 768);
661 case CONVERT (A52_2F1R, A52_STEREO): 661 case CONVERT (A52_2F1R, A52_STEREO):
662 case CONVERT (A52_2F1R, A52_DOLBY): 662 case CONVERT (A52_2F1R, A52_DOLBY):
663 zero (samples + 512); 663 zero (samples + 512);
664 break; 664 break;
665 665
666 case CONVERT (A52_3F2R, A52_3F): 666 case CONVERT (A52_3F2R, A52_3F):
667 zero (samples + 1024); 667 zero (samples + 1024);
668 case CONVERT (A52_3F1R, A52_3F): 668 case CONVERT (A52_3F1R, A52_3F):
669 case CONVERT (A52_2F2R, A52_2F1R): 669 case CONVERT (A52_2F2R, A52_2F1R):
670 zero (samples + 768); 670 zero (samples + 768);
671 break; 671 break;
672 672
673 case CONVERT (A52_3F2R, A52_3F1R): 673 case CONVERT (A52_3F2R, A52_3F1R):
674 zero (samples + 1024); 674 zero (samples + 1024);
675 break; 675 break;
676 676
677 case CONVERT (A52_3F2R, A52_2F1R): 677 case CONVERT (A52_3F2R, A52_2F1R):
678 zero (samples + 1024); 678 zero (samples + 1024);
679 case CONVERT (A52_3F1R, A52_2F1R): 679 case CONVERT (A52_3F1R, A52_2F1R):
680 mix_31to21: 680 mix_31to21:
681 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t)); 681 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
682 goto mix_3to2; 682 goto mix_3to2;
683 683
684 case CONVERT (A52_3F2R, A52_2F2R): 684 case CONVERT (A52_3F2R, A52_2F2R):
685 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t)); 685 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
686 goto mix_31to21; 686 goto mix_31to21;
687 } 687 }
688} 688}