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
36
38 {
40
41 if (!num_reuse_blocks)
42 return;
43
45 uint8_t min_exp = *
exp;
46 uint8_t *exp1 =
exp + 256;
47 for (
blk = 0;
blk < num_reuse_blocks;
blk++) {
48 uint8_t next_exp = *exp1;
49 if (next_exp < min_exp)
50 min_exp = next_exp;
51 exp1 += 256;
52 }
54 }
55 }
56
58 {
59 const float scale = 1 << 24;
60 do {
71 }
72
74 int start, int end,
75 int snr_offset,
int floor,
76 const uint8_t *
bap_tab, uint8_t *bap)
77 {
78 int bin, band, band_end;
79
80 /* special case, if snr offset is -960, set all bap's to zero */
81 if (snr_offset == -960) {
83 return;
84 }
85
86 bin = start;
88 do {
91 band_end =
FFMIN(band_end, end);
92
93 for (; bin < band_end; bin++) {
96 }
97 } while (end > band_end);
98 }
99
102 {
104 mant_cnt[bap[
len]]++;
105 }
106
108 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16
109 };
110
112 {
115
117 // bap=1 : 3 mantissas in 5 bits
118 bits += (mant_cnt[
blk][1] / 3) * 5;
119 // bap=2 : 3 mantissas in 7 bits
120 // bap=4 : 2 mantissas in 7 bits
121 bits += ((mant_cnt[
blk][2] / 3) + (mant_cnt[
blk][4] >> 1)) * 7;
122 // bap=3 : 1 mantissa in 3 bits
124 // bap=5 to 15 : get bits per mantissa from table
125 for (bap = 5; bap < 16; bap++)
127 }
129 }
130
132 {
134
136 int v =
abs(coef[
i]);
138 }
139 }
140
145 {
147
148 sum[0] = sum[1] = sum[2] = sum[3] = 0;
149
150 for (
i = 0;
i <
len;
i++) {
154 int sd = lt - rt;
155 MAC64(sum[0], lt, lt);
156 MAC64(sum[1], rt, rt);
158 MAC64(sum[3], sd, sd);
159 }
160 }
161
163 const float *coef0,
164 const float *coef1,
166 {
168
169 sum[0] = sum[1] = sum[2] = sum[3] = 0;
170
171 for (
i = 0;
i <
len;
i++) {
175 float sd = lt - rt;
176 sum[0] += lt * lt;
177 sum[1] += rt * rt;
179 sum[3] += sd * sd;
180 }
181 }
182
185 {
187 float v0, v1;
188 float front_mix =
matrix[0][0];
189 float center_mix =
matrix[0][1];
190 float surround_mix =
matrix[0][3];
191
192 for (
i = 0;
i <
len;
i++) {
196
200
203 }
204 }
205
208 {
210 float front_mix =
matrix[0][0];
211 float center_mix =
matrix[0][1];
212 float surround_mix =
matrix[0][3];
213
214 for (
i = 0;
i <
len;
i++) {
220 }
221 }
222
224 int out_ch,
int in_ch,
int len)
225 {
227 float v0, v1;
228
229 if (out_ch == 2) {
230 for (
i = 0;
i <
len;
i++) {
231 v0 = v1 = 0.0f;
232 for (j = 0; j < in_ch; j++) {
235 }
238 }
239 } else if (out_ch == 1) {
240 for (
i = 0;
i <
len;
i++) {
241 v0 = 0.0f;
242 for (j = 0; j < in_ch; j++)
245 }
246 }
247 }
248
251 {
254 int16_t front_mix =
matrix[0][0];
255 int16_t center_mix =
matrix[0][1];
256 int16_t surround_mix =
matrix[0][3];
257
258 for (
i = 0;
i <
len;
i++) {
262
266
269 }
270 }
271
274 {
277 int16_t front_mix =
matrix[0][0];
278 int16_t center_mix =
matrix[0][1];
279 int16_t surround_mix =
matrix[0][3];
280
281 for (
i = 0;
i <
len;
i++) {
287
289 }
290 }
291
293 int out_ch,
int in_ch,
int len)
294 {
297 if (out_ch == 2) {
298 for (
i = 0;
i <
len;
i++) {
299 v0 = v1 = 0;
300 for (j = 0; j < in_ch; j++) {
303 }
306 }
307 } else if (out_ch == 1) {
308 for (
i = 0;
i <
len;
i++) {
309 v0 = 0;
310 for (j = 0; j < in_ch; j++)
313 }
314 }
315 }
316
318 int out_ch,
int in_ch,
int len)
319 {
320 if (
c->in_channels != in_ch ||
c->out_channels != out_ch) {
321 c->in_channels = in_ch;
322 c->out_channels = out_ch;
323 c->downmix_fixed =
NULL;
324
325 if (in_ch == 5 && out_ch == 2 &&
331 } else if (in_ch == 5 && out_ch == 1 &&
335 }
336 }
337
338 if (
c->downmix_fixed)
340 else
342 }
343
345 int out_ch,
int in_ch,
int len)
346 {
347 if (
c->in_channels != in_ch ||
c->out_channels != out_ch) {
348 int **matrix_cmp = (
int **)
matrix;
349
350 c->in_channels = in_ch;
351 c->out_channels = out_ch;
353
354 if (in_ch == 5 && out_ch == 2 &&
355 !(matrix_cmp[1][0] | matrix_cmp[0][2] |
356 matrix_cmp[1][3] | matrix_cmp[0][4] |
357 (matrix_cmp[0][1] ^ matrix_cmp[1][1]) |
358 (matrix_cmp[0][0] ^ matrix_cmp[1][2]))) {
360 } else if (in_ch == 5 && out_ch == 1 &&
361 matrix_cmp[0][0] == matrix_cmp[0][2] &&
362 matrix_cmp[0][3] == matrix_cmp[0][4]) {
364 }
365
366 #if ARCH_X86
368 #endif
369 }
370
373 else
375 }
376
378 {
390 c->downmix_fixed =
NULL;
391
392 #if ARCH_AARCH64
394 #elif ARCH_ARM
396 #elif ARCH_X86
398 #elif ARCH_MIPS
400 #elif ARCH_RISCV
402 #endif
403 }