1 /*
2 * AC-3 DSP functions
3 * Copyright (c) 2011 Justin Ruggles
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <math.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "config.h"
31
35
37 {
39
40 if (!num_reuse_blocks)
41 return;
42
44 uint8_t min_exp = *
exp;
45 uint8_t *exp1 =
exp + 256;
46 for (
blk = 0;
blk < num_reuse_blocks;
blk++) {
47 uint8_t next_exp = *exp1;
48 if (next_exp < min_exp)
49 min_exp = next_exp;
50 exp1 += 256;
51 }
53 }
54 }
55
57 {
58 const float scale = 1 << 24;
59 do {
70 }
71
73 int start, int end,
74 int snr_offset,
int floor,
75 const uint8_t *
bap_tab, uint8_t *bap)
76 {
77 int bin, band, band_end;
78
79 /* special case, if snr offset is -960, set all bap's to zero */
80 if (snr_offset == -960) {
82 return;
83 }
84
85 bin = start;
87 do {
90 band_end =
FFMIN(band_end, end);
91
92 for (; bin < band_end; bin++) {
95 }
96 } while (end > band_end);
97 }
98
101 {
103 mant_cnt[bap[
len]]++;
104 }
105
107 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16
108 };
109
111 {
114
116 // bap=1 : 3 mantissas in 5 bits
117 bits += (mant_cnt[
blk][1] / 3) * 5;
118 // bap=2 : 3 mantissas in 7 bits
119 // bap=4 : 2 mantissas in 7 bits
120 bits += ((mant_cnt[
blk][2] / 3) + (mant_cnt[
blk][4] >> 1)) * 7;
121 // bap=3 : 1 mantissa in 3 bits
123 // bap=5 to 15 : get bits per mantissa from table
124 for (bap = 5; bap < 16; bap++)
126 }
128 }
129
131 {
133
135 int v =
abs(coef[
i]);
137 }
138 }
139
144 {
146
147 sum[0] = sum[1] = sum[2] = sum[3] = 0;
148
149 for (
i = 0;
i <
len;
i++) {
153 int sd = lt - rt;
154 MAC64(sum[0], lt, lt);
155 MAC64(sum[1], rt, rt);
157 MAC64(sum[3], sd, sd);
158 }
159 }
160
162 const float *coef0,
163 const float *coef1,
165 {
167
168 sum[0] = sum[1] = sum[2] = sum[3] = 0;
169
170 for (
i = 0;
i <
len;
i++) {
174 float sd = lt - rt;
175 sum[0] += lt * lt;
176 sum[1] += rt * rt;
178 sum[3] += sd * sd;
179 }
180 }
181
184 {
187 float front_mix = matrix[0][0];
188 float center_mix = matrix[0][1];
189 float surround_mix = matrix[0][3];
190
191 for (
i = 0;
i <
len;
i++) {
195
199
202 }
203 }
204
207 {
209 float front_mix = matrix[0][0];
210 float center_mix = matrix[0][1];
211 float surround_mix = matrix[0][3];
212
213 for (
i = 0;
i <
len;
i++) {
219 }
220 }
221
223 int out_ch,
int in_ch,
int len)
224 {
227
228 if (out_ch == 2) {
229 for (
i = 0;
i <
len;
i++) {
231 for (j = 0; j < in_ch; j++) {
234 }
237 }
238 } else if (out_ch == 1) {
239 for (
i = 0;
i <
len;
i++) {
241 for (j = 0; j < in_ch; j++)
244 }
245 }
246 }
247
250 {
253 int16_t front_mix = matrix[0][0];
254 int16_t center_mix = matrix[0][1];
255 int16_t surround_mix = matrix[0][3];
256
257 for (
i = 0;
i <
len;
i++) {
259 (int64_t)
samples[1][
i] * center_mix +
260 (int64_t)
samples[3][
i] * surround_mix;
261
262 v1 = (int64_t)
samples[1][
i] * center_mix +
263 (int64_t)
samples[2][
i] * front_mix +
264 (int64_t)
samples[4][
i] * surround_mix;
265
268 }
269 }
270
273 {
276 int16_t front_mix = matrix[0][0];
277 int16_t center_mix = matrix[0][1];
278 int16_t surround_mix = matrix[0][3];
279
280 for (
i = 0;
i <
len;
i++) {
282 (int64_t)
samples[1][
i] * center_mix +
283 (int64_t)
samples[2][
i] * front_mix +
284 (int64_t)
samples[3][
i] * surround_mix +
285 (int64_t)
samples[4][
i] * surround_mix;
286
288 }
289 }
290
292 int out_ch,
int in_ch,
int len)
293 {
296 if (out_ch == 2) {
297 for (
i = 0;
i <
len;
i++) {
299 for (j = 0; j < in_ch; j++) {
301 v1 += (int64_t)
samples[j][
i] * matrix[1][j];
302 }
305 }
306 } else if (out_ch == 1) {
307 for (
i = 0;
i <
len;
i++) {
309 for (j = 0; j < in_ch; j++)
312 }
313 }
314 }
315
317 int out_ch,
int in_ch,
int len)
318 {
319 if (
c->in_channels != in_ch ||
c->out_channels != out_ch) {
320 c->in_channels = in_ch;
321 c->out_channels = out_ch;
322 c->downmix_fixed =
NULL;
323
324 if (in_ch == 5 && out_ch == 2 &&
325 !(matrix[1][0] | matrix[0][2] |
326 matrix[1][3] | matrix[0][4] |
327 (matrix[0][1] ^ matrix[1][1]) |
328 (matrix[0][0] ^ matrix[1][2]))) {
330 } else if (in_ch == 5 && out_ch == 1 &&
331 matrix[0][0] == matrix[0][2] &&
332 matrix[0][3] == matrix[0][4]) {
334 }
335 }
336
337 if (
c->downmix_fixed)
339 else
341 }
342
344 int out_ch,
int in_ch,
int len)
345 {
346 if (
c->in_channels != in_ch ||
c->out_channels != out_ch) {
347 int **matrix_cmp = (int **)matrix;
348
349 c->in_channels = in_ch;
350 c->out_channels = out_ch;
352
353 if (in_ch == 5 && out_ch == 2 &&
354 !(matrix_cmp[1][0] | matrix_cmp[0][2] |
355 matrix_cmp[1][3] | matrix_cmp[0][4] |
356 (matrix_cmp[0][1] ^ matrix_cmp[1][1]) |
357 (matrix_cmp[0][0] ^ matrix_cmp[1][2]))) {
359 } else if (in_ch == 5 && out_ch == 1 &&
360 matrix_cmp[0][0] == matrix_cmp[0][2] &&
361 matrix_cmp[0][3] == matrix_cmp[0][4]) {
363 }
364
365 if (ARCH_X86)
367 }
368
371 else
373 }
374
376 {
388 c->downmix_fixed =
NULL;
389
390 if (ARCH_ARM)
392 if (ARCH_X86)
394 if (ARCH_MIPS)
396 }