1 /*
2 * Copyright (C) 2016 foo86
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #define BITSTREAM_READER_LE
22
24
30
32
36 };
37
50 };
51
83 };
84
89
91 { 0, -1, -1, -1, -1 }, // C
92 { 0, 1, -1, -1, -1 }, // LR
93 { 0, 1, 2, -1, -1 }, // LR C
94 { 0, 1, -1, -1, -1 }, // LsRs
95 { 1, 2, 0, -1, -1 }, // LsRs C
96 { 0, 1, 2, 3, -1 }, // LR LsRs
97 { 0, 1, 3, 4, 2 }, // LR LsRs C
98 };
99
101 { 0, -1, -1, -1, -1 }, // C
102 { 0, 1, -1, -1, -1 }, // LR
103 { 0, 1, 2, -1, -1 }, // LR C
104 { 1, 2, -1, -1, -1 }, // LsRs
105 { 2, 3, 0, -1, -1 }, // LsRs C
106 { 0, 1, 3, 4, -1 }, // LR LsRs
107 { 0, 1, 4, 5, 2 }, // LR LsRs C
108 };
109
111 1, 2, 3, 0, 1, 2, 3
112 };
113
115 1, 2, 3, 2, 3, 4, 5
116 };
117
126 };
127
130
132 {
133 static int initialized;
134 int i;
135
136 if (initialized)
137 return;
138
139 for (i = 0; i < 256; i++)
141
142 for (i = 0; i < 16; i++)
143 lpc_tab[i] = sin((i - 8) * (
M_PI / ((i < 8) ? 17 : 15)));
144
145 initialized = 1;
146 }
147
149 {
151 int i, ps, si, code, step_i;
153
155 si = ps >> 23;
156
157 value = (((ps & 0x7fffff) ^ -si) + si) * (1.0f / 0x7fffff);
158
160 if (step_i > step_max) {
162 return -1;
163 }
164
166
167 for (i = 0; i < 64; i++) {
169
170 delta = step * 0.03125f;
171 if (code & 16)
172 delta += step;
173 if (code & 8)
174 delta += step * 0.5f;
175 if (code & 4)
176 delta += step * 0.25f;
177 if (code & 2)
178 delta += step * 0.125f;
179 if (code & 1)
180 delta += step * 0.0625f;
181
182 if (code & 32) {
184 if (value < -3.0f)
185 value = -3.0f;
186 } else {
188 if (value > 3.0f)
189 value = 3.0f;
190 }
191
193 step_i = av_clip(step_i, 0, step_max);
194
197 }
198
199 return 0;
200 }
201
203 {
205 int i, ps, si, code, step_i;
207
209 si = ps >> 15;
210
211 value = (((ps & 0x7fff) ^ -si) + si) * (1.0f / 0x7fff);
212
214 if (step_i > step_max) {
216 return -1;
217 }
218
220
221 for (i = 0; i < 64; i++) {
223
224 delta = step * 0.125f;
225 if (code & 4)
226 delta += step;
227 if (code & 2)
228 delta += step * 0.5f;
229 if (code & 1)
230 delta += step * 0.25f;
231
232 if (code & 8) {
234 if (value < -3.0f)
235 value = -3.0f;
236 } else {
238 if (value > 3.0f)
239 value = 3.0f;
240 }
241
243 step_i = av_clip(step_i, 0, step_max);
244
247 }
248
249 return 0;
250 }
251
253 {
255 return 0;
256
258 return 0;
259
261 return -1;
262
263 // Determine bit depth from chunk size
264 if (chunk->
len >= 52)
266 if (chunk->
len >= 35)
268
270 return -1;
271 }
272
274 {
276 if (v > 0)
277 return v - 1;
278 // Rare value
280 }
281
283 {
287 int sf, sf_idx,
ch, main_ch, freq;
289
290 // Parse subframes for this group
291 for (sf = 0; sf < 1 << group; sf += diff ? 8 : 1) {
292 sf_idx = ((s->
framenum << group) + sf) & 31;
294
295 // Parse tones for this subframe
296 for (freq = 1;; freq++) {
299 return -1;
300 }
301
305 return -1;
306 }
307
309 if (diff <= 1)
310 break; // End of subframe
311
312 freq += diff - 2;
313 if (freq >> (5 - group) > s->
nsubbands * 4 - 5) {
315 return -1;
316 }
317
318 // Main channel
323 amp[main_ch] = main_amp <
AMP_MAX ? main_amp : 0;
325
326 // Secondary channels
328 if (ch == main_ch)
329 continue;
333 } else {
336 }
337 }
338
339 if (amp[main_ch]) {
340 // Allocate new tone
343
344 t->
x_freq = freq >> (5 - group);
345 t->
f_delt = (freq & ((1 << (5 - group)) - 1)) << group;
347
350
354 }
355 }
356 }
357
359 }
360
361 return 0;
362 }
363
365 {
366 int sb, group;
367
369 return 0;
370
372 return -1;
373
374 // Scale factors
378 return -1;
379 }
380 for (sb = 0; sb < 6; sb++)
382 }
383
384 // Tonal groups
386 for (group = 0; group < 5; group++)
388 return -1;
389
390 return 0;
391 }
392
394 {
396 return 0;
397
399 return -1;
400
402 }
403
404 /**
405 * Check point to ensure that enough bits are left. Aborts decoding
406 * by skipping to the end of chunk otherwise.
407 */
409 {
411 if (left < 0)
412 return -1;
413 if (left < n) {
415 return 1;
416 }
417 return 0;
418 }
419
421 {
422 int i, sf, prev, next, dist;
423
424 // Truncated scale factors remain zero
426 return 0;
427
428 // Initial scale factor
430
431 for (sf = 0; sf < 7; sf += dist) {
432 scf[sf] = prev; // Store previous value
433
435 return 0;
436
437 // Interpolation distance
439 if (dist > 7 - sf) {
441 return -1;
442 }
443
445 return 0;
446
447 // Final interpolation point
449
450 if (next & 1)
451 next = prev + ((next + 1) >> 1);
452 else
453 next = prev - ( next >> 1);
454
455 // Interpolate
456 switch (dist) {
457 case 2:
458 if (next > prev)
459 scf[sf + 1] = prev + ((next - prev) >> 1);
460 else
461 scf[sf + 1] = prev - ((prev - next) >> 1);
462 break;
463
464 case 4:
465 if (next > prev) {
466 scf[sf + 1] = prev + ( (next - prev) >> 2);
467 scf[sf + 2] = prev + ( (next - prev) >> 1);
468 scf[sf + 3] = prev + (((next - prev) * 3) >> 2);
469 } else {
470 scf[sf + 1] = prev - ( (prev - next) >> 2);
471 scf[sf + 2] = prev - ( (prev - next) >> 1);
472 scf[sf + 3] = prev - (((prev - next) * 3) >> 2);
473 }
474 break;
475
476 default:
477 for (i = 1; i < dist; i++)
478 scf[sf + i] = prev + (next - prev) * i / dist;
479 break;
480 }
481
482 prev = next;
483 }
484
485 scf[sf] = next; // Store final value
486
487 return 0;
488 }
489
491 {
493
494 if (v & 1)
495 v = 16 + (v >> 1);
496 else
497 v = 16 - (v >> 1);
498
500 v = 16;
501 return v;
502 }
503
505 {
506 int ch, sb, sf, nsubbands;
507
509 return 0;
510
512 return -1;
513
514 // Scale factors
516 for (sb = 2; sb < nsubbands; sb++) {
518 return -1;
521 return -1;
522 }
523
525 return 0; // Should not happen, but a sample exists that proves otherwise
526
527 // Average values for third grid
528 for (sb = 0; sb < s->
nsubbands - 4; sb++) {
530 if (ch1 != ch2) {
533 else
535 }
536 }
537
540 return -1;
541 }
542
543 // Stereo image for partial mono mode
544 if (ch1 != ch2) {
545 int min_v[2];
546
548 return 0;
549
552
554 for (sb = 0; sb < nsubbands; sb++)
555 for (ch = ch1; ch <= ch2; ch++)
556 for (sf = 1; sf <= 4; sf++)
558
561 }
562
563 // Low resolution spatial information is not decoded
564
565 return 0;
566 }
567
569 {
570 int sb, nsubbands;
571
572 // Scale factors
574 for (sb = 2; sb < nsubbands; sb++) {
577 return -1;
578 }
579
580 // Average values for third grid
581 for (sb = 0; sb < s->
nsubbands - 4; sb++) {
584 return 0;
586 }
587 }
588
589 return 0;
590 }
591
593 {
595
596 for (ch = ch1; ch <= ch2; ch++) {
598 continue;
599
601 continue; // Already parsed
602
603 for (i = 0; i < 8; i++) {
605 return;
607 }
608
609 // Flag scale factors for this subband parsed
611 }
612 }
613
615 {
618 }
619
620 /**
621 * Parse time samples for one subband, filling truncated samples with randomness
622 */
624 {
626 int i, j, code, nblocks, coding_method;
627
629 return; // Too few bits left
630
632
633 switch (quant_level) {
634 case 1:
636 for (i = 0; i < nblocks; i++, samples += 8) {
638 for (j = 0; j < 8; j++)
640 }
641 i = nblocks * 8;
642 break;
643
644 case 2:
645 if (coding_method) {
649 else
650 samples[i] = 0;
651 }
652 } else {
654 for (i = 0; i < nblocks; i++, samples += 5) {
656 for (j = 0; j < 5; j++)
658 }
659 i = nblocks * 5;
660 }
661 break;
662
663 case 3:
665 for (i = 0; i < nblocks; i++, samples += 3) {
667 for (j = 0; j < 3; j++)
669 }
670 i = nblocks * 3;
671 break;
672
673 case 4:
676 break;
677
678 case 5:
680 for (i = 0; i < nblocks; i++)
682 break;
683
684 default:
686 }
687
689 return; // Skip incomplete mono subband
690
693
695 }
696
698 int start_sb,
int end_sb,
int flag)
699 {
700 int sb, sb_g3, sb_reorder, quant_level;
701
702 for (sb = start_sb; sb < end_sb; sb++) {
703 // Subband number before reordering
704 if (sb < 6) {
705 sb_reorder = sb;
706 } else if (flag && sb < s->max_mono_subband) {
708 } else {
710 break;
712 if (sb_reorder < 6)
713 sb_reorder = 6;
715 }
717 return -1;
718
719 // Third grid scale factors
720 if (sb == 12) {
723 } else if (sb < 12 && sb_reorder >= 4) {
725 }
726
727 // Secondary channel flags
728 if (ch1 != ch2) {
730 break;
735 }
736
738 if (!quant_level)
739 return -1;
740
741 // Time samples for one or both channels
743 if (!flag)
744 parse_ch(s, ch1, sb_reorder, quant_level, 0);
745 else if (ch1 != ch2)
746 parse_ch(s, ch2, sb_reorder, quant_level, 1);
747 } else {
748 parse_ch(s, ch1, sb_reorder, quant_level, 0);
749 if (ch1 != ch2)
750 parse_ch(s, ch2, sb_reorder, quant_level, 0);
751 }
752 }
753
754 return 0;
755 }
756
757 /**
758 * Convert from reflection coefficients to direct form coefficients
759 */
761 {
762 int i, j;
763
764 for (i = 0; i < 8; i++) {
766 for (j = 0; j < (i + 1) / 2; j++) {
767 float tmp1 = coeff[ j ];
768 float tmp2 = coeff[i - j - 1];
769 coeff[ j ] = tmp1 + rc * tmp2;
770 coeff[i - j - 1] = tmp2 + rc * tmp1;
771 }
772 coeff[i] = rc;
773 }
774 }
775
777 {
779 int i, sb,
ch, codes[16];
780
781 // First two subbands have two sets of coefficients, third subband has one
782 for (sb = start_sb; sb < end_sb; sb++) {
783 int ncodes = 8 * (1 + (sb < 2));
784 for (ch = ch1; ch <= ch2; ch++) {
786 return 0;
787 for (i = 0; i < ncodes; i++)
789 for (i = 0; i < ncodes / 8; i++)
791 }
792 }
793
794 return 0;
795 }
796
798 {
801
803 return 0;
804
806 return -1;
807
808 // Quantizer profile
810 // Overall level
811 ol = (profile >> 3) & 7;
812 // Steepness
813 st = profile >> 6;
814 // Max energy subband
815 max_sb = profile & 7;
816
817 // Calculate quantization levels
820 int a = 18000 / (12 * f / 1000 + 100 + 40 * st) + 20 * ol;
821 if (a <= 95)
822 quant_levels[sb] = 1;
823 else if (a <= 140)
824 quant_levels[sb] = 2;
825 else if (a <= 180)
826 quant_levels[sb] = 3;
827 else if (a <= 230)
828 quant_levels[sb] = 4;
829 else
830 quant_levels[sb] = 5;
831 }
832
833 // Reorder quantization levels for lower subbands
834 for (sb = 0; sb < 8; sb++)
838
839 // LPC for the first two subbands
841 return -1;
842
843 // Time-samples for the first two subbands of main channel
844 if (
parse_ts(s, ch1, ch2, 0, 2, 0) < 0)
845 return -1;
846
847 // First two bands of the first grid
848 for (sb = 0; sb < 2; sb++)
849 for (ch = ch1; ch <= ch2; ch++)
851 return -1;
852
853 return 0;
854 }
855
857 int start_sb,
int end_sb,
int flag)
858 {
859 int i, j, sb,
ch, nsubbands;
860
862 if (end_sb > nsubbands)
863 end_sb = nsubbands;
864
865 for (sb = start_sb; sb < end_sb; sb++) {
866 for (ch = ch1; ch <= ch2; ch++) {
868
870 if (!flag)
872 continue;
873 }
874
875 // Scale factors in groups of 8
876 for (i = 0; i < 8; i++, g2_scf += 8) {
878 memset(g2_scf, 0, 64 - i * 8);
879 break;
880 }
881 // Bit indicating if whole group has zero values
883 for (j = 0; j < 8; j++) {
885 break;
887 }
888 } else {
889 memset(g2_scf, 0, 8);
890 }
891 }
892 }
893 }
894
895 return 0;
896 }
897
899 {
901 return 0;
903 return -1;
905 return -1;
906 if (
parse_ts(s, ch1, ch2, 2, 4, 0) < 0)
907 return -1;
909 return -1;
910 if (
parse_ts(s, ch1, ch2, 4, 6, 0) < 0)
911 return -1;
912 return 0;
913 }
914
916 {
918 return 0;
920 return -1;
922 return -1;
924 return -1;
925 if (ch1 != ch2) {
927 return -1;
929 return -1;
930 }
932 return -1;
933 return 0;
934 }
935
937 {
938 double scale = (-1.0 / (1 << 17)) * sqrt(1 << (2 - s->
limited_range));
940
942
944 return -1;
945
948
949 if (br_per_ch < 14000)
950 scale = 0.85;
951 else if (br_per_ch < 32000)
952 scale = (br_per_ch - 14000) * (1.0 / 120000) + 0.85;
953 else
954 scale = 1.0;
955
956 scale *= 1.0 / INT_MAX;
957
959 if (i < 2)
960 s->
sb_scf[i] = 0;
// The first two subbands are always zero
961 else if (i < 5)
962 s->
sb_scf[i] = (i - 1) * 0.25 * 0.785 * scale;
963 else
964 s->
sb_scf[i] = 0.785 * scale;
965 }
966
968
969 return 0;
970 }
971
973 {
974 // Reserve space for history and padding
978 float *ptr;
979
980 // Reallocate time sample buffer
983 return -1;
984
989 ptr += nchsamples;
990 }
991 }
992
993 return 0;
994 }
995
997 {
1002 unsigned int sr_code;
1003
1004 // Sample rate of LBR audio
1005 sr_code = bytestream2_get_byte(gb);
1009 }
1014 }
1015
1016 // LBR speaker mask
1017 s->
ch_mask = bytestream2_get_le16(gb);
1021 }
1025 }
1026
1027 // LBR bitstream version
1028 version = bytestream2_get_le16(gb);
1029 if ((version & 0xff00) != 0x0800) {
1032 }
1033
1034 // Flags for LBR decoder initialization
1035 s->
flags = bytestream2_get_byte(gb);
1039 }
1044 }
1046 }
1047
1048 // Most significant bit rate nibbles
1049 bit_rate_hi = bytestream2_get_byte(gb);
1050
1051 // Least significant original bit rate word
1052 s->
bit_rate_orig = bytestream2_get_le16(gb) | ((bit_rate_hi & 0x0F) << 16);
1053
1054 // Least significant scaled bit rate word
1055 s->
bit_rate_scaled = bytestream2_get_le16(gb) | ((bit_rate_hi & 0xF0) << 12);
1056
1057 // Setup number of fullband channels
1060
1061 // Setup band limit
1065 break;
1068 break;
1071 break;
1072 default:
1075 }
1076
1077 // Setup frequency range
1079
1080 // Setup resolution profile
1085 else
1087
1088 // Setup limited sample rate, number of subbands, etc
1094 }
1095
1097
1101
1105
1109
1110 // Handle change of sample rate
1113
1114 // Setup stereo downmix
1117
1121 }
1122
1123 // This decoder doesn't support ECS chunk
1127 }
1128
1129 // Account for extra downmixed channel pair
1134 }
1135
1136 // Handle change of sample rate or number of channels
1143 }
1144
1145 return 0;
1146 }
1147
1149 {
1150 struct {
1158 } chunk = { {0} };
1159
1161
1162 int i,
ch, sb, sf, ret, group, chunk_id, chunk_len;
1163
1165
1166 // LBR sync word
1170 }
1171
1172 // LBR header type
1173 switch (bytestream2_get_byte(&gb)) {
1178 }
1179 break;
1183 return ret;
1184 }
1185 break;
1186 default:
1189 }
1190
1191 // LBR frame chunk header
1192 chunk_id = bytestream2_get_byte(&gb);
1193 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1194
1200 }
1201
1203
1204 switch (chunk_id & 0x7f) {
1207 int checksum = bytestream2_get_be16(&gb);
1208 uint16_t res = chunk_id;
1209 res += (chunk_len >> 8) & 0xff;
1210 res += chunk_len & 0xff;
1211 for (i = 0; i < chunk_len - 2; i++)
1213 if (checksum != res) {
1217 }
1218 } else {
1220 }
1221 break;
1223 break;
1224 default:
1227 }
1228
1229 // Clear current frame
1244
1246 for (sb = 0; sb < s->
nsubbands / 4; sb++) {
1249 }
1250 }
1251
1253
1254 for (group = 0; group < 5; group++) {
1255 for (sf = 0; sf < 1 << group; sf++) {
1256 int sf_idx = ((s->
framenum << group) + sf) & 31;
1259 }
1260 }
1261
1262 // Parse chunk headers
1264 chunk_id = bytestream2_get_byte(&gb);
1265 chunk_len = (chunk_id & 0x80) ? bytestream2_get_be16(&gb) : bytestream2_get_byte(&gb);
1266 chunk_id &= 0x7f;
1267
1273 }
1274
1275 switch (chunk_id) {
1277 chunk.lfe.len = chunk_len;
1278 chunk.lfe.data = gb.
buffer;
1279 break;
1280
1284 chunk.tonal.id = chunk_id;
1285 chunk.tonal.len = chunk_len;
1286 chunk.tonal.data = gb.
buffer;
1287 break;
1288
1295 chunk.tonal_grp[i].id = i;
1296 chunk.tonal_grp[i].len = chunk_len;
1297 chunk.tonal_grp[i].data = gb.
buffer;
1298 break;
1299
1306 chunk.tonal_grp[i].id = i;
1307 chunk.tonal_grp[i].len = chunk_len;
1308 chunk.tonal_grp[i].data = gb.
buffer;
1309 break;
1310
1315 chunk.grid1[i].len = chunk_len;
1316 chunk.grid1[i].data = gb.
buffer;
1317 break;
1318
1323 chunk.hr_grid[i].len = chunk_len;
1324 chunk.hr_grid[i].data = gb.
buffer;
1325 break;
1326
1331 chunk.ts1[i].len = chunk_len;
1332 chunk.ts1[i].data = gb.
buffer;
1333 break;
1334
1339 chunk.ts2[i].len = chunk_len;
1340 chunk.ts2[i].data = gb.
buffer;
1341 break;
1342 }
1343
1345 }
1346
1347 // Parse the chunks
1349
1351
1352 for (i = 0; i < 5; i++)
1354
1355 for (i = 0; i < (s->
nchannels + 1) / 2; i++) {
1356 int ch1 = i * 2;
1358
1361 ret = -1;
1362 continue;
1363 }
1364
1365 // TS chunks depend on both grids. TS_2 depends on TS_1.
1366 if (!chunk.grid1[i].len || !chunk.hr_grid[i].len || !chunk.ts1[i].len)
1367 continue;
1368
1371 ret = -1;
1372 continue;
1373 }
1374 }
1375
1378
1379 return 0;
1380 }
1381
1382 /**
1383 * Reconstruct high-frequency resolution grid from first and third grids
1384 */
1386 {
1388
1389 for (ch = ch1; ch <= ch2; ch++) {
1392
1395
1398
1400
1401 if (sb < 4) {
1402 for (i = 0; i < 8; i++) {
1403 int scf = w1 * g1_scf_a[i] + w2 * g1_scf_b[i];
1404 hr_scf[i] = scf >> 7;
1405 }
1406 } else {
1409
1410 for (i = 0; i < 8; i++) {
1411 int scf = w1 * g1_scf_a[i] + w2 * g1_scf_b[i];
1412 hr_scf[i] = (scf >> 7) - g3_avg - g3_scf[i];
1413 }
1414 }
1415 }
1416 }
1417 }
1418
1419 /**
1420 * Fill unallocated subbands with randomness
1421 */
1423 {
1424 int i, j, k,
ch, sb;
1425
1426 for (ch = ch1; ch <= ch2; ch++) {
1429
1431 continue; // Skip allocated subband
1432
1433 if (sb < 2) {
1434 // The first two subbands are always zero
1436 } else if (sb < 10) {
1439 } else {
1441 float accum[8] = { 0 };
1442
1443 // Modulate by subbands 2-5 in blocks of 8
1444 for (k = 2; k < 6; k++) {
1446 for (j = 0; j < 8; j++)
1447 accum[j] += fabs(other[j]);
1448 }
1449
1450 for (j = 0; j < 8; j++)
1451 samples[j] = (accum[j] * 0.25f + 0.5f) *
lbr_rand(s, sb);
1452 }
1453 }
1454 }
1455 }
1456 }
1457
1459 {
1460 int i, j;
1461
1462 for (i = 0; i < nsamples; i++) {
1463 float res = 0;
1464 for (j = 0; j < 8; j++)
1465 res += coeff[j] * samples[i - j - 1];
1466 samples[i] -= res;
1467 }
1468 }
1469
1471 {
1474
1475 for (ch = ch1; ch <= ch2; ch++) {
1477
1478 if (!(s->
ch_pres[ch] & (1
U << sb)))
1479 continue;
1480
1481 if (sb < 2) {
1485 } else {
1488 }
1489 }
1490 }
1491
1493 {
1495
1497 // Scale factors
1498 for (ch = ch1; ch <= ch2; ch++) {
1501 if (sb < 4) {
1503 unsigned int scf = hr_scf[i];
1506 for (j = 0; j < 16; j++)
1508 }
1509 } else {
1512 unsigned int scf = hr_scf[i / 8] - g2_scf[i];
1517 }
1518 }
1519 }
1520
1521 // Mid-side stereo
1522 if (ch1 != ch2) {
1525 int ch2_pres = s->
ch_pres[ch2] & (1
U << sb);
1526
1528 int sbms = (s->
sec_ch_sbms[ch1 / 2][sb] >> i) & 1;
1529 int lrms = (s->
sec_ch_lrms[ch1 / 2][sb] >> i) & 1;
1530
1532 if (lrms && ch2_pres) {
1533 if (sbms) {
1534 for (j = 0; j < 16; j++) {
1535 float tmp = samples_l[j];
1536 samples_l[j] = samples_r[j];
1537 samples_r[j] = -
tmp;
1538 }
1539 } else {
1540 for (j = 0; j < 16; j++) {
1541 float tmp = samples_l[j];
1542 samples_l[j] = samples_r[j];
1544 }
1545 }
1546 } else if (!ch2_pres) {
1548 for (j = 0; j < 16; j++)
1549 samples_r[j] = -samples_l[j];
1550 } else {
1551 for (j = 0; j < 16; j++)
1552 samples_r[j] = samples_l[j];
1553 }
1554 }
1555 } else if (sbms && ch2_pres) {
1556 for (j = 0; j < 16; j++) {
1557 float tmp = samples_l[j];
1558 samples_l[j] = (tmp + samples_r[j]) * 0.5f;
1559 samples_r[j] = (tmp - samples_r[j]) * 0.5f;
1560 }
1561 }
1562
1563 samples_l += 16;
1564 samples_r += 16;
1565 }
1566 }
1567
1568 // Inverse prediction
1569 if (sb < 3)
1571 }
1572 }
1573
1574 /**
1575 * Modulate by interpolated partial stereo coefficients
1576 */
1578 {
1580
1581 for (ch = ch1; ch <= ch2; ch++) {
1585
1587 continue;
1588
1589 for (sf = 1; sf <= 4; sf++, samples += 32) {
1592
1593 for (i = 0; i < 32; i++)
1594 samples[i] *= (32 - i) * prev + i * next;
1595 }
1596 }
1597 }
1598 }
1599
1600 /**
1601 * Synthesise tones in the given group for the given tonal subframe
1602 */
1604 int group, int group_sf, int synth_idx)
1605 {
1607
1608 if (synth_idx < 0)
1609 return;
1610
1613
1614 for (i = 0; i <
count; i++) {
1616
1623
1624 switch (x_freq) {
1625 case 0:
1626 goto p0;
1627 case 1:
1628 values[3] += cf[0] * -
s;
1629 values[2] += cf[1] *
c;
1630 values[1] += cf[2] *
s;
1631 values[0] += cf[3] * -
c;
1632 goto p1;
1633 case 2:
1634 values[2] += cf[0] * -
s;
1635 values[1] += cf[1] *
c;
1636 values[0] += cf[2] *
s;
1637 goto p2;
1638 case 3:
1639 values[1] += cf[0] * -
s;
1640 values[0] += cf[1] *
c;
1641 goto p3;
1642 case 4:
1643 values[0] += cf[0] * -
s;
1644 goto p4;
1645 }
1646
1647 values[x_freq - 5] += cf[ 0] * -
s;
1648 p4: values[x_freq - 4] += cf[ 1] *
c;
1649 p3: values[x_freq - 3] += cf[ 2] *
s;
1650 p2: values[x_freq - 2] += cf[ 3] * -
c;
1651 p1: values[x_freq - 1] += cf[ 4] * -
s;
1652 p0: values[x_freq ] += cf[ 5] *
c;
1653 values[x_freq + 1] += cf[ 6] *
s;
1654 values[x_freq + 2] += cf[ 7] * -
c;
1655 values[x_freq + 3] += cf[ 8] * -
s;
1656 values[x_freq + 4] += cf[ 9] *
c;
1657 values[x_freq + 5] += cf[10] *
s;
1658 }
1659
1661 }
1662 }
1663
1664 /**
1665 * Synthesise all tones in all groups for the given residual subframe
1666 */
1668 {
1669 int group;
1670
1671 // Tonal vs residual shift is 22 subframes
1672 for (group = 0; group < 5; group++) {
1673 int group_sf = (s->
framenum << group) + ((sf - 22) >> (5 - group));
1674 int synth_idx = ((((sf - 22) & 31) << group) & 31) + (1 << group) - 1;
1675
1676 synth_tones(s, ch, values, group, (group_sf - 1) & 31, 30 - synth_idx);
1677 synth_tones(s, ch, values, group, (group_sf ) & 31, synth_idx);
1678 }
1679 }
1680
1682 {
1686
1687 // Clear inactive subbands
1688 if (nsubbands < noutsubbands)
1689 memset(values[nsubbands], 0, (noutsubbands - nsubbands) * sizeof(values[0]));
1690
1692 // Hybrid filterbank
1695
1697
1699
1700 // Long window and overlap-add
1702 s->
history[ch], noutsubbands * 4);
1704 s->
window, noutsubbands * 4);
1705 output += noutsubbands * 4;
1706 }
1707
1708 // Update history for LPC and forward MDCT
1709 for (sb = 0; sb < nsubbands; sb++) {
1712 }
1713 }
1714
1716 {
1718 int i, ret, nchannels, ch_conf = (s->
ch_mask & 0x7) - 1;
1719 const int8_t *reorder;
1720
1728
1733 } else {
1735 }
1736
1739 return ret;
1740
1741 // Filter fullband channels
1742 for (i = 0; i < (s->
nchannels + 1) / 2; i++) {
1743 int ch1 = i * 2;
1745
1747
1749
1751
1754
1755 if (ch1 < nchannels)
1757
1758 if (ch1 != ch2 && ch2 < nchannels)
1760 }
1761
1762 // Interpolate LFE channel
1767 }
1768
1770 return ret;
1771
1772 return 0;
1773 }
1774
1776 {
1778
1780 return;
1781
1782 // Clear history
1790
1795 }
1796 }
1797 }
1798
1800 {
1802
1804 return -1;
1805
1807 return 0;
1808 }
1809
1811 {
1813
1816
1819 }
static void parse_grid_3(DCALbrDecoder *s, int ch1, int ch2, int sb, int flag)
int ntones
Circular buffer head position.
static int parse_grid_1_sec_ch(DCALbrDecoder *s, int ch2)
const float ff_dca_rsd_level_2b[2]
static int parse_tonal_chunk(DCALbrDecoder *s, LBRChunk *chunk)
float window[DCA_LBR_SUBBANDS *4]
Long window for IMDCT.
static void synth_lpc(DCALbrDecoder *s, int ch1, int ch2, int sb)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
const float ff_dca_st_coeff[34]
int bit_rate_scaled
Scaled bit rate.
ptrdiff_t const GLvoid * data
int ff_dca_lbr_parse(DCALbrDecoder *s, uint8_t *data, DCAExssAsset *asset)
uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]
Grid 2 scale factors.
uint32_t ch_pres[DCA_LBR_CHANNELS]
Subband allocation flags.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
const int8_t ff_dca_ph0_shift[8]
#define AV_CH_LAYOUT_SURROUND
#define DCA_LBR_CHANNELS_TOTAL
int max_mono_subband
Subband index where mono encoding ends.
static void skip_bits_long(GetBitContext *s, int n)
unsigned int ts_size
Time sample buffer size.
const uint8_t ff_dca_scf_to_grid_1[32]
static float cos_tab[256]
static int parse_st_code(GetBitContext *s, int min_v)
int nchannels_total
Total number of fullband channels.
int freq_range
Frequency range of LBR audio.
const float ff_dca_lfe_step_size_24[144]
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define FF_PROFILE_DTS_EXPRESS
uint8_t x_freq
Spectral line offset.
const uint16_t ff_dca_rsd_pack_5_in_8[256]
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats, and store the result in a vector of floats...
static int parse_lfe_16(DCALbrDecoder *s)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_CH_LAYOUT_STEREO
int bit_rate_orig
Original bit rate.
static int init_sample_rate(DCALbrDecoder *s)
const float ff_dca_quant_amp[57]
#define AV_CH_LAYOUT_5POINT0
static int parse_grid_1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
float * ts_buffer
Time sample buffer base.
const uint8_t ff_dca_freq_ranges[16]
float sb_scf[DCA_LBR_SUBBANDS]
Subband randomization scale factors.
float lfe_scale
Scale factor of LFE samples before IIR filter.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int ensure_bits(GetBitContext *s, int n)
Check point to ensure that enough bits are left.
enum AVSampleFormat sample_fmt
audio sample format
static void filter_ts(DCALbrDecoder *s, int ch1, int ch2)
int ch_mask
LBR speaker mask.
uint8_t part_stereo_pres
Partial stereo coefficients presence flags.
static void random_ts(DCALbrDecoder *s, int ch1, int ch2)
Fill unallocated subbands with randomness.
#define AV_CH_LOW_FREQUENCY
static void parse_ch(DCALbrDecoder *s, int ch, int sb, int quant_level, int flag)
Parse time samples for one subband, filling truncated samples with randomness.
uint8_t phs[DCA_LBR_CHANNELS]
Per-channel phase.
static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk *chunk)
static void transform_channel(DCALbrDecoder *s, int ch, float *output)
int nchannels
Number of fullband channels to decode.
int sample_rate
Sample rate of LBR audio.
static int get_bits_left(GetBitContext *gb)
static float lbr_rand(DCALbrDecoder *s, int sb)
const int8_t ff_dca_lfe_delta_index_16[8]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
DCALbrTone tones[DCA_LBR_TONES]
Circular buffer of tones.
uint8_t tonal_scf[6]
Tonal scale factors.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
void(* lfe_iir)(float *output, const float *input, const float iir[5][4], float hist[5][2], ptrdiff_t factor)
uint8_t ph_rot
Phase rotation.
int warned
Flags for warning suppression.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const float ff_dca_rsd_level_5[5]
static av_cold void init_tables(void)
float lfe_history[5][2]
LFE IIR filter history.
const uint32_t ff_dca_sampling_freqs[16]
uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS/4][5]
Partial stereo coefficients.
int lbr_offset
Offset to LBR component from start of substream.
uint8_t amp[DCA_LBR_CHANNELS]
Per-channel amplitude.
#define DCA_SPEAKER_LAYOUT_STEREO
static int parse_tonal_group(DCALbrDecoder *s, LBRChunk *chunk)
uint64_t channel_layout
Audio channel layout.
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
uint16_t tonal_bounds[5][32][2]
Per-group per-subframe start/end positions of tones.
static int alloc_sample_buffer(DCALbrDecoder *s)
const float ff_dca_synth_env[32]
static void base_func_synth(DCALbrDecoder *s, int ch, float *values, int sf)
Synthesise all tones in all groups for the given residual subframe.
audio channel layout utility functions
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
const float ff_dca_rsd_level_8[8]
const uint8_t ff_dca_scf_to_grid_2[32]
const uint16_t ff_dca_avg_g3_freqs[3]
GLsizei GLboolean const GLfloat * value
int lbr_rand
Seed for subband randomization.
const float ff_dca_rsd_level_16[16]
uint8_t sec_ch_sbms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Right channel inversion or mid/side decoding flags.
int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS-4]
Grid 3 average values.
int nsubbands
Number of encoded subbands.
av_cold void ff_dca_lbr_flush(DCALbrDecoder *s)
av_cold void ff_dca_lbr_close(DCALbrDecoder *s)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static int parse_lpc(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb)
static int parse_ts(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb, int flag)
#define AV_CH_FRONT_CENTER
uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]
Grid 1 scale factors.
static volatile int checksum
const float ff_dca_bank_coeff[10]
VLC ff_dca_vlc_tnl_grp[5]
static const uint8_t channel_counts[7]
int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
static void predict(float *samples, const float *coeff, int nsamples)
#define FF_ARRAY_ELEMS(a)
static int parse_high_res_grid(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
void(* lbr_bank)(float output[32][4], float **input, const float *coeff, ptrdiff_t ofs, ptrdiff_t len)
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int parse_ts2_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]
Predictor coefficients.
static const int8_t channel_reorder_lfe[7][5]
const float ff_dca_corr_cf[32][11]
float history[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS *4]
IMDCT history.
const float ff_dca_lfe_iir[5][4]
int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS-4][8]
Grid 3 scale factors.
int sample_rate
samples per second
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
int band_limit
Band limit factor.
main external API structure.
static int parse_ts1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch2)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int lbr_size
Size of LBR component in extension substream.
const uint8_t ff_dca_freq_to_sb[32]
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
void(* vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len)
Calculate the entry wise product of two vectors of floats, add a third vector of floats and store the...
static int parse_tonal(DCALbrDecoder *s, int group)
static unsigned int get_bits1(GetBitContext *s)
static const uint16_t channel_layouts[7]
int res_profile
Resolution profile.
const float ff_dca_long_window[128]
static void convert_lpc(float *coeff, const int *codes)
Convert from reflection coefficients to direct form coefficients.
uint8_t sb_indices[DCA_LBR_SUBBANDS]
Subband reordering indices.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data...
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
const uint8_t ff_dca_rsd_pack_3_in_7[128][3]
int limited_range
Band limited frequency range.
static int parse_lfe_24(DCALbrDecoder *s)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const float ff_dca_rsd_level_3[3]
static int ff_dca_count_chs_for_mask(unsigned int mask)
Return number of individual channels in DCASpeakerPair mask.
uint8_t f_delt
Difference between original and center frequency.
#define DCA_LBR_TIME_HISTORY
#define LOCAL_ALIGNED_32(t, v,...)
int framenum
Lower 5 bits of current frame number.
int limited_rate
Band limited sample rate.
uint8_t sec_ch_lrms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Flags indicating if left/right channel are swapped.
const uint8_t ff_dca_grid_1_to_scf[11]
float lfe_data[64]
Decimated LFE samples.
#define DCA_LBR_TIME_SAMPLES
uint32_t grid_3_pres[DCA_LBR_CHANNELS]
Grid 3 scale factors presence flags.
const float ff_dca_rsd_level_2a[2]
const uint16_t ff_dca_fst_amp[44]
const float ff_dca_lfe_step_size_16[101]
int request_channel_layout
Converted from avctx.request_channel_layout.
static int parse_grid_2(DCALbrDecoder *s, int ch1, int ch2, int start_sb, int end_sb, int flag)
static int parse_vlc(GetBitContext *s, VLC *vlc, int max_depth)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
float * time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]
Time samples.
VLC ff_dca_vlc_fst_rsd_amp
static av_always_inline int diff(const uint32_t a, const uint32_t b)
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
static const double coeff[2][5]
const uint8_t ff_dca_sb_reorder[8][8]
static const int8_t channel_reorder_nolfe[7][5]
static void decode_part_stereo(DCALbrDecoder *s, int ch1, int ch2)
Modulate by interpolated partial stereo coefficients.
int flags
Flags for LBR decoder initialization.
static void synth_tones(DCALbrDecoder *s, int ch, float *values, int group, int group_sf, int synth_idx)
Synthesise tones in the given group for the given tonal subframe.
av_cold int ff_dca_lbr_init(DCALbrDecoder *s)
uint8_t quant_levels[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Quantization levels.
const int8_t ff_dca_lfe_delta_index_24[32]
static const uint8_t lfe_index[7]
int min_mono_subband
Subband index where mono encoding starts.
const uint8_t ff_dca_grid_2_to_scf[3]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
int nb_samples
number of audio samples (per channel) described by this frame
int g3_avg_only_start_sb
Subband index where grid 3 scale factors end.
static int parse_decoder_init(DCALbrDecoder *s, GetByteContext *gb)
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]
High-frequency resolution scale factors.
static void decode_grid(DCALbrDecoder *s, int ch1, int ch2)
Reconstruct high-frequency resolution grid from first and third grids.
const uint8_t ff_dca_grid_1_weights[12][32]