Libav
qdm2.c
Go to the documentation of this file.
1 /*
2  * QDM2 compatible decoder
3  * Copyright (c) 2003 Ewald Snel
4  * Copyright (c) 2005 Benjamin Larsson
5  * Copyright (c) 2005 Alex Beregszaszi
6  * Copyright (c) 2005 Roberto Togni
7  *
8  * This file is part of Libav.
9  *
10  * Libav is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * Libav is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with Libav; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
34 #include <math.h>
35 #include <stddef.h>
36 #include <stdio.h>
37 
38 #define BITSTREAM_READER_LE
40 #include "avcodec.h"
41 #include "get_bits.h"
42 #include "internal.h"
43 #include "rdft.h"
44 #include "mpegaudiodsp.h"
45 #include "mpegaudio.h"
46 
47 #include "qdm2data.h"
48 #include "qdm2_tablegen.h"
49 
50 #undef NDEBUG
51 #include <assert.h>
52 
53 
54 #define QDM2_LIST_ADD(list, size, packet) \
55 do { \
56  if (size > 0) { \
57  list[size - 1].next = &list[size]; \
58  } \
59  list[size].packet = packet; \
60  list[size].next = NULL; \
61  size++; \
62 } while(0)
63 
64 // Result is 8, 16 or 30
65 #define QDM2_SB_USED(sub_sampling) (((sub_sampling) >= 2) ? 30 : 8 << (sub_sampling))
66 
67 #define FIX_NOISE_IDX(noise_idx) \
68  if ((noise_idx) >= 3840) \
69  (noise_idx) -= 3840; \
70 
71 #define SB_DITHERING_NOISE(sb,noise_idx) (noise_table[(noise_idx)++] * sb_noise_attenuation[(sb)])
72 
73 #define SAMPLES_NEEDED \
74  av_log (NULL,AV_LOG_INFO,"This file triggers some untested code. Please contact the developers.\n");
75 
76 #define SAMPLES_NEEDED_2(why) \
77  av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
78 
79 #define QDM2_MAX_FRAME_SIZE 512
80 
81 typedef int8_t sb_int8_array[2][30][64];
82 
86 typedef struct {
87  int type;
88  unsigned int size;
89  const uint8_t *data;
91 
95 typedef struct QDM2SubPNode {
97  struct QDM2SubPNode *next;
98 } QDM2SubPNode;
99 
100 typedef struct {
101  float re;
102  float im;
103 } QDM2Complex;
104 
105 typedef struct {
106  float level;
108  const float *table;
109  int phase;
111  int duration;
112  short time_index;
113  short cutoff;
114 } FFTTone;
115 
116 typedef struct {
117  int16_t sub_packet;
119  int16_t offset;
120  int16_t exp;
123 
124 typedef struct {
126 } QDM2FFT;
127 
131 typedef struct {
134  int channels;
136  int fft_size;
138 
141  int fft_order;
147 
149  QDM2SubPacket sub_packets[16];
150  QDM2SubPNode sub_packet_list_A[16];
151  QDM2SubPNode sub_packet_list_B[16];
153  QDM2SubPNode sub_packet_list_C[16];
154  QDM2SubPNode sub_packet_list_D[16];
155 
157  FFTTone fft_tones[1000];
160  FFTCoefficient fft_coefs[1000];
162  int fft_coefs_min_index[5];
163  int fft_coefs_max_index[5];
164  int fft_level_exp[6];
167 
172 
175  DECLARE_ALIGNED(32, float, synth_buf)[MPA_MAX_CHANNELS][512*2];
176  int synth_buf_offset[MPA_MAX_CHANNELS];
177  DECLARE_ALIGNED(32, float, sb_samples)[MPA_MAX_CHANNELS][128][SBLIMIT];
179 
181  float tone_level[MPA_MAX_CHANNELS][30][64];
182  int8_t coding_method[MPA_MAX_CHANNELS][30][64];
183  int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8];
184  int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8];
185  int8_t tone_level_idx_hi1[MPA_MAX_CHANNELS][3][8][8];
186  int8_t tone_level_idx_mid[MPA_MAX_CHANNELS][26][8];
187  int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26];
188  int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64];
189  int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64];
190 
191  // Flags
195 
197  int noise_idx;
198 } QDM2Context;
199 
200 
214 
215 static const uint16_t qdm2_vlc_offs[] = {
216  0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
217 };
218 
219 static const int switchtable[23] = {
220  0, 5, 1, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 4
221 };
222 
223 static av_cold void qdm2_init_vlc(void)
224 {
225  static VLC_TYPE qdm2_table[3838][2];
226 
227  vlc_tab_level.table = &qdm2_table[qdm2_vlc_offs[0]];
228  vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
229  init_vlc(&vlc_tab_level, 8, 24,
233 
234  vlc_tab_diff.table = &qdm2_table[qdm2_vlc_offs[1]];
235  vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
236  init_vlc(&vlc_tab_diff, 8, 37,
237  vlc_tab_diff_huffbits, 1, 1,
240 
241  vlc_tab_run.table = &qdm2_table[qdm2_vlc_offs[2]];
242  vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
243  init_vlc(&vlc_tab_run, 5, 6,
244  vlc_tab_run_huffbits, 1, 1,
245  vlc_tab_run_huffcodes, 1, 1,
247 
248  fft_level_exp_alt_vlc.table = &qdm2_table[qdm2_vlc_offs[3]];
249  fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] -
250  qdm2_vlc_offs[3];
251  init_vlc(&fft_level_exp_alt_vlc, 8, 28,
255 
256  fft_level_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[4]];
257  fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
258  init_vlc(&fft_level_exp_vlc, 8, 20,
262 
263  fft_stereo_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[5]];
264  fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] -
265  qdm2_vlc_offs[5];
266  init_vlc(&fft_stereo_exp_vlc, 6, 7,
270 
271  fft_stereo_phase_vlc.table = &qdm2_table[qdm2_vlc_offs[6]];
272  fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] -
273  qdm2_vlc_offs[6];
274  init_vlc(&fft_stereo_phase_vlc, 6, 9,
278 
279  vlc_tab_tone_level_idx_hi1.table =
280  &qdm2_table[qdm2_vlc_offs[7]];
281  vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] -
282  qdm2_vlc_offs[7];
283  init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
287 
288  vlc_tab_tone_level_idx_mid.table =
289  &qdm2_table[qdm2_vlc_offs[8]];
290  vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] -
291  qdm2_vlc_offs[8];
292  init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
296 
297  vlc_tab_tone_level_idx_hi2.table =
298  &qdm2_table[qdm2_vlc_offs[9]];
299  vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] -
300  qdm2_vlc_offs[9];
301  init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
305 
306  vlc_tab_type30.table = &qdm2_table[qdm2_vlc_offs[10]];
307  vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
308  init_vlc(&vlc_tab_type30, 6, 9,
312 
313  vlc_tab_type34.table = &qdm2_table[qdm2_vlc_offs[11]];
314  vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
315  init_vlc(&vlc_tab_type34, 5, 10,
319 
320  vlc_tab_fft_tone_offset[0].table =
321  &qdm2_table[qdm2_vlc_offs[12]];
322  vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] -
323  qdm2_vlc_offs[12];
324  init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
328 
329  vlc_tab_fft_tone_offset[1].table =
330  &qdm2_table[qdm2_vlc_offs[13]];
331  vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] -
332  qdm2_vlc_offs[13];
333  init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
337 
338  vlc_tab_fft_tone_offset[2].table =
339  &qdm2_table[qdm2_vlc_offs[14]];
340  vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] -
341  qdm2_vlc_offs[14];
342  init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
346 
347  vlc_tab_fft_tone_offset[3].table =
348  &qdm2_table[qdm2_vlc_offs[15]];
349  vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] -
350  qdm2_vlc_offs[15];
351  init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
355 
356  vlc_tab_fft_tone_offset[4].table =
357  &qdm2_table[qdm2_vlc_offs[16]];
358  vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] -
359  qdm2_vlc_offs[16];
360  init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
364 }
365 
366 static int qdm2_get_vlc(GetBitContext *gb, VLC *vlc, int flag, int depth)
367 {
368  int value;
369 
370  value = get_vlc2(gb, vlc->table, vlc->bits, depth);
371 
372  /* stage-2, 3 bits exponent escape sequence */
373  if (value-- == 0)
374  value = get_bits(gb, get_bits(gb, 3) + 1);
375 
376  /* stage-3, optional */
377  if (flag) {
378  int tmp = vlc_stage3_values[value];
379 
380  if ((value & ~3) > 0)
381  tmp += get_bits(gb, (value >> 2));
382  value = tmp;
383  }
384 
385  return value;
386 }
387 
388 static int qdm2_get_se_vlc(VLC *vlc, GetBitContext *gb, int depth)
389 {
390  int value = qdm2_get_vlc(gb, vlc, 0, depth);
391 
392  return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
393 }
394 
404 static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
405 {
406  int i;
407 
408  for (i = 0; i < length; i++)
409  value -= data[i];
410 
411  return (uint16_t)(value & 0xffff);
412 }
413 
421  QDM2SubPacket *sub_packet)
422 {
423  sub_packet->type = get_bits(gb, 8);
424 
425  if (sub_packet->type == 0) {
426  sub_packet->size = 0;
427  sub_packet->data = NULL;
428  } else {
429  sub_packet->size = get_bits(gb, 8);
430 
431  if (sub_packet->type & 0x80) {
432  sub_packet->size <<= 8;
433  sub_packet->size |= get_bits(gb, 8);
434  sub_packet->type &= 0x7f;
435  }
436 
437  if (sub_packet->type == 0x7f)
438  sub_packet->type |= (get_bits(gb, 8) << 8);
439 
440  // FIXME: this depends on bitreader-internal data
441  sub_packet->data = &gb->buffer[get_bits_count(gb) / 8];
442  }
443 
444  av_log(NULL, AV_LOG_DEBUG, "Subpacket: type=%d size=%d start_offs=%x\n",
445  sub_packet->type, sub_packet->size, get_bits_count(gb) / 8);
446 }
447 
456  int type)
457 {
458  while (list && list->packet) {
459  if (list->packet->type == type)
460  return list;
461  list = list->next;
462  }
463  return NULL;
464 }
465 
473 {
474  int i, j, n, ch, sum;
475 
477 
478  for (ch = 0; ch < q->nb_channels; ch++)
479  for (i = 0; i < n; i++) {
480  sum = 0;
481 
482  for (j = 0; j < 8; j++)
483  sum += q->quantized_coeffs[ch][i][j];
484 
485  sum /= 8;
486  if (sum > 0)
487  sum--;
488 
489  for (j = 0; j < 8; j++)
490  q->quantized_coeffs[ch][i][j] = sum;
491  }
492 }
493 
502 {
503  int ch, j;
504 
506 
507  if (!q->nb_channels)
508  return;
509 
510  for (ch = 0; ch < q->nb_channels; ch++) {
511  for (j = 0; j < 64; j++) {
512  q->sb_samples[ch][j * 2][sb] =
513  SB_DITHERING_NOISE(sb, q->noise_idx) * q->tone_level[ch][sb][j];
514  q->sb_samples[ch][j * 2 + 1][sb] =
515  SB_DITHERING_NOISE(sb, q->noise_idx) * q->tone_level[ch][sb][j];
516  }
517  }
518 }
519 
528 static int fix_coding_method_array(int sb, int channels,
529  sb_int8_array coding_method)
530 {
531  int j, k;
532  int ch;
533  int run, case_val;
534 
535  for (ch = 0; ch < channels; ch++) {
536  for (j = 0; j < 64; ) {
537  if (coding_method[ch][sb][j] < 8)
538  return -1;
539  if ((coding_method[ch][sb][j] - 8) > 22) {
540  run = 1;
541  case_val = 8;
542  } else {
543  switch (switchtable[coding_method[ch][sb][j] - 8]) {
544  case 0: run = 10;
545  case_val = 10;
546  break;
547  case 1: run = 1;
548  case_val = 16;
549  break;
550  case 2: run = 5;
551  case_val = 24;
552  break;
553  case 3: run = 3;
554  case_val = 30;
555  break;
556  case 4: run = 1;
557  case_val = 30;
558  break;
559  case 5: run = 1;
560  case_val = 8;
561  break;
562  default: run = 1;
563  case_val = 8;
564  break;
565  }
566  }
567  for (k = 0; k < run; k++) {
568  if (j + k < 128) {
569  if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j]) {
570  if (k > 0) {
572  //not debugged, almost never used
573  memset(&coding_method[ch][sb][j + k], case_val,
574  k *sizeof(int8_t));
575  memset(&coding_method[ch][sb][j + k], case_val,
576  3 * sizeof(int8_t));
577  }
578  }
579  }
580  }
581  j += run;
582  }
583  }
584  return 0;
585 }
586 
594 static void fill_tone_level_array(QDM2Context *q, int flag)
595 {
596  int i, sb, ch, sb_used;
597  int tmp, tab;
598 
599  for (ch = 0; ch < q->nb_channels; ch++)
600  for (sb = 0; sb < 30; sb++)
601  for (i = 0; i < 8; i++) {
603  tmp = q->quantized_coeffs[ch][tab + 1][i] * dequant_table[q->coeff_per_sb_select][tab + 1][sb]+
605  else
606  tmp = q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];
607  if(tmp < 0)
608  tmp += 0xff;
609  q->tone_level_idx_base[ch][sb][i] = (tmp / 256) & 0xff;
610  }
611 
612  sb_used = QDM2_SB_USED(q->sub_sampling);
613 
614  if ((q->superblocktype_2_3 != 0) && !flag) {
615  for (sb = 0; sb < sb_used; sb++)
616  for (ch = 0; ch < q->nb_channels; ch++)
617  for (i = 0; i < 64; i++) {
618  q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
619  if (q->tone_level_idx[ch][sb][i] < 0)
620  q->tone_level[ch][sb][i] = 0;
621  else
622  q->tone_level[ch][sb][i] = fft_tone_level_table[0][q->tone_level_idx[ch][sb][i] & 0x3f];
623  }
624  } else {
625  tab = q->superblocktype_2_3 ? 0 : 1;
626  for (sb = 0; sb < sb_used; sb++) {
627  if ((sb >= 4) && (sb <= 23)) {
628  for (ch = 0; ch < q->nb_channels; ch++)
629  for (i = 0; i < 64; i++) {
630  tmp = q->tone_level_idx_base[ch][sb][i / 8] -
631  q->tone_level_idx_hi1[ch][sb / 8][i / 8][i % 8] -
632  q->tone_level_idx_mid[ch][sb - 4][i / 8] -
633  q->tone_level_idx_hi2[ch][sb - 4];
634  q->tone_level_idx[ch][sb][i] = tmp & 0xff;
635  if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
636  q->tone_level[ch][sb][i] = 0;
637  else
638  q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
639  }
640  } else {
641  if (sb > 4) {
642  for (ch = 0; ch < q->nb_channels; ch++)
643  for (i = 0; i < 64; i++) {
644  tmp = q->tone_level_idx_base[ch][sb][i / 8] -
645  q->tone_level_idx_hi1[ch][2][i / 8][i % 8] -
646  q->tone_level_idx_hi2[ch][sb - 4];
647  q->tone_level_idx[ch][sb][i] = tmp & 0xff;
648  if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
649  q->tone_level[ch][sb][i] = 0;
650  else
651  q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
652  }
653  } else {
654  for (ch = 0; ch < q->nb_channels; ch++)
655  for (i = 0; i < 64; i++) {
656  tmp = q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
657  if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
658  q->tone_level[ch][sb][i] = 0;
659  else
660  q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
661  }
662  }
663  }
664  }
665  }
666 }
667 
683 static void fill_coding_method_array(sb_int8_array tone_level_idx,
684  sb_int8_array tone_level_idx_temp,
685  sb_int8_array coding_method,
686  int nb_channels,
687  int c, int superblocktype_2_3,
688  int cm_table_select)
689 {
690  int ch, sb, j;
691  int tmp, acc, esp_40, comp;
692  int add1, add2, add3, add4;
693  int64_t multres;
694 
695  if (!superblocktype_2_3) {
696  /* This case is untested, no samples available */
698  for (ch = 0; ch < nb_channels; ch++)
699  for (sb = 0; sb < 30; sb++) {
700  for (j = 1; j < 63; j++) { // The loop only iterates to 63 so the code doesn't overflow the buffer
701  add1 = tone_level_idx[ch][sb][j] - 10;
702  if (add1 < 0)
703  add1 = 0;
704  add2 = add3 = add4 = 0;
705  if (sb > 1) {
706  add2 = tone_level_idx[ch][sb - 2][j] + tone_level_idx_offset_table[sb][0] - 6;
707  if (add2 < 0)
708  add2 = 0;
709  }
710  if (sb > 0) {
711  add3 = tone_level_idx[ch][sb - 1][j] + tone_level_idx_offset_table[sb][1] - 6;
712  if (add3 < 0)
713  add3 = 0;
714  }
715  if (sb < 29) {
716  add4 = tone_level_idx[ch][sb + 1][j] + tone_level_idx_offset_table[sb][3] - 6;
717  if (add4 < 0)
718  add4 = 0;
719  }
720  tmp = tone_level_idx[ch][sb][j + 1] * 2 - add4 - add3 - add2 - add1;
721  if (tmp < 0)
722  tmp = 0;
723  tone_level_idx_temp[ch][sb][j + 1] = tmp & 0xff;
724  }
725  tone_level_idx_temp[ch][sb][0] = tone_level_idx_temp[ch][sb][1];
726  }
727  acc = 0;
728  for (ch = 0; ch < nb_channels; ch++)
729  for (sb = 0; sb < 30; sb++)
730  for (j = 0; j < 64; j++)
731  acc += tone_level_idx_temp[ch][sb][j];
732 
733  multres = 0x66666667LL * (acc * 10);
734  esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31);
735  for (ch = 0; ch < nb_channels; ch++)
736  for (sb = 0; sb < 30; sb++)
737  for (j = 0; j < 64; j++) {
738  comp = tone_level_idx_temp[ch][sb][j]* esp_40 * 10;
739  if (comp < 0)
740  comp += 0xff;
741  comp /= 256; // signed shift
742  switch(sb) {
743  case 0:
744  if (comp < 30)
745  comp = 30;
746  comp += 15;
747  break;
748  case 1:
749  if (comp < 24)
750  comp = 24;
751  comp += 10;
752  break;
753  case 2:
754  case 3:
755  case 4:
756  if (comp < 16)
757  comp = 16;
758  }
759  if (comp <= 5)
760  tmp = 0;
761  else if (comp <= 10)
762  tmp = 10;
763  else if (comp <= 16)
764  tmp = 16;
765  else if (comp <= 24)
766  tmp = -1;
767  else
768  tmp = 0;
769  coding_method[ch][sb][j] = ((tmp & 0xfffa) + 30 )& 0xff;
770  }
771  for (sb = 0; sb < 30; sb++)
772  fix_coding_method_array(sb, nb_channels, coding_method);
773  for (ch = 0; ch < nb_channels; ch++)
774  for (sb = 0; sb < 30; sb++)
775  for (j = 0; j < 64; j++)
776  if (sb >= 10) {
777  if (coding_method[ch][sb][j] < 10)
778  coding_method[ch][sb][j] = 10;
779  } else {
780  if (sb >= 2) {
781  if (coding_method[ch][sb][j] < 16)
782  coding_method[ch][sb][j] = 16;
783  } else {
784  if (coding_method[ch][sb][j] < 30)
785  coding_method[ch][sb][j] = 30;
786  }
787  }
788  } else { // superblocktype_2_3 != 0
789  for (ch = 0; ch < nb_channels; ch++)
790  for (sb = 0; sb < 30; sb++)
791  for (j = 0; j < 64; j++)
792  coding_method[ch][sb][j] = coding_method_table[cm_table_select][sb];
793  }
794 }
795 
810  int length, int sb_min, int sb_max)
811 {
812  int sb, j, k, n, ch, run, channels;
813  int joined_stereo, zero_encoding;
814  int type34_first;
815  float type34_div = 0;
816  float type34_predictor;
817  float samples[10], sign_bits[16];
818 
819  if (length == 0) {
820  // If no data use noise
821  for (sb=sb_min; sb < sb_max; sb++)
823 
824  return;
825  }
826 
827  for (sb = sb_min; sb < sb_max; sb++) {
828  channels = q->nb_channels;
829 
830  if (q->nb_channels <= 1 || sb < 12)
831  joined_stereo = 0;
832  else if (sb >= 24)
833  joined_stereo = 1;
834  else
835  joined_stereo = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;
836 
837  if (joined_stereo) {
838  if (get_bits_left(gb) >= 16)
839  for (j = 0; j < 16; j++)
840  sign_bits[j] = get_bits1(gb);
841 
842  for (j = 0; j < 64; j++)
843  if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])
844  q->coding_method[0][sb][j] = q->coding_method[1][sb][j];
845 
847  q->coding_method)) {
849  continue;
850  }
851  channels = 1;
852  }
853 
854  for (ch = 0; ch < channels; ch++) {
856  zero_encoding = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;
857  type34_predictor = 0.0;
858  type34_first = 1;
859 
860  for (j = 0; j < 128; ) {
861  switch (q->coding_method[ch][sb][j / 2]) {
862  case 8:
863  if (get_bits_left(gb) >= 10) {
864  if (zero_encoding) {
865  for (k = 0; k < 5; k++) {
866  if ((j + 2 * k) >= 128)
867  break;
868  samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0;
869  }
870  } else {
871  n = get_bits(gb, 8);
872  for (k = 0; k < 5; k++)
873  samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
874  }
875  for (k = 0; k < 5; k++)
876  samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx);
877  } else {
878  for (k = 0; k < 10; k++)
879  samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
880  }
881  run = 10;
882  break;
883 
884  case 10:
885  if (get_bits_left(gb) >= 1) {
886  float f = 0.81;
887 
888  if (get_bits1(gb))
889  f = -f;
890  f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;
891  samples[0] = f;
892  } else {
893  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
894  }
895  run = 1;
896  break;
897 
898  case 16:
899  if (get_bits_left(gb) >= 10) {
900  if (zero_encoding) {
901  for (k = 0; k < 5; k++) {
902  if ((j + k) >= 128)
903  break;
904  samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)];
905  }
906  } else {
907  n = get_bits (gb, 8);
908  for (k = 0; k < 5; k++)
909  samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
910  }
911  } else {
912  for (k = 0; k < 5; k++)
913  samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
914  }
915  run = 5;
916  break;
917 
918  case 24:
919  if (get_bits_left(gb) >= 7) {
920  n = get_bits(gb, 7);
921  for (k = 0; k < 3; k++)
922  samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5;
923  } else {
924  for (k = 0; k < 3; k++)
925  samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
926  }
927  run = 3;
928  break;
929 
930  case 30:
931  if (get_bits_left(gb) >= 4) {
932  unsigned index = qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1);
933  if (index < FF_ARRAY_ELEMS(type30_dequant)) {
934  samples[0] = type30_dequant[index];
935  } else
936  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
937  } else
938  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
939 
940  run = 1;
941  break;
942 
943  case 34:
944  if (get_bits_left(gb) >= 7) {
945  if (type34_first) {
946  type34_div = (float)(1 << get_bits(gb, 2));
947  samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0;
948  type34_predictor = samples[0];
949  type34_first = 0;
950  } else {
951  unsigned index = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1);
952  if (index < FF_ARRAY_ELEMS(type34_delta)) {
953  samples[0] = type34_delta[index] / type34_div + type34_predictor;
954  type34_predictor = samples[0];
955  } else
956  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
957  }
958  } else {
959  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
960  }
961  run = 1;
962  break;
963 
964  default:
965  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
966  run = 1;
967  break;
968  }
969 
970  if (joined_stereo) {
971  for (k = 0; k < run && j + k < 128; k++) {
972  q->sb_samples[0][j + k][sb] =
973  q->tone_level[0][sb][(j + k) / 2] * samples[k];
974  if (q->nb_channels == 2) {
975  if (sign_bits[(j + k) / 8])
976  q->sb_samples[1][j + k][sb] =
977  q->tone_level[1][sb][(j + k) / 2] * -samples[k];
978  else
979  q->sb_samples[1][j + k][sb] =
980  q->tone_level[1][sb][(j + k) / 2] * samples[k];
981  }
982  }
983  } else {
984  for (k = 0; k < run; k++)
985  if ((j + k) < 128)
986  q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k];
987  }
988 
989  j += run;
990  } // j loop
991  } // channel loop
992  } // subband loop
993 }
994 
1005 static void init_quantized_coeffs_elem0(int8_t *quantized_coeffs,
1006  GetBitContext *gb)
1007 {
1008  int i, k, run, level, diff;
1009 
1010  if (get_bits_left(gb) < 16)
1011  return;
1012  level = qdm2_get_vlc(gb, &vlc_tab_level, 0, 2);
1013 
1014  quantized_coeffs[0] = level;
1015 
1016  for (i = 0; i < 7; ) {
1017  if (get_bits_left(gb) < 16)
1018  break;
1019  run = qdm2_get_vlc(gb, &vlc_tab_run, 0, 1) + 1;
1020 
1021  if (get_bits_left(gb) < 16)
1022  break;
1023  diff = qdm2_get_se_vlc(&vlc_tab_diff, gb, 2);
1024 
1025  for (k = 1; k <= run; k++)
1026  quantized_coeffs[i + k] = (level + ((k * diff) / run));
1027 
1028  level += diff;
1029  i += run;
1030  }
1031 }
1032 
1043 {
1044  int sb, j, k, n, ch;
1045 
1046  for (ch = 0; ch < q->nb_channels; ch++) {
1048 
1049  if (get_bits_left(gb) < 16) {
1050  memset(q->quantized_coeffs[ch][0], 0, 8);
1051  break;
1052  }
1053  }
1054 
1055  n = q->sub_sampling + 1;
1056 
1057  for (sb = 0; sb < n; sb++)
1058  for (ch = 0; ch < q->nb_channels; ch++)
1059  for (j = 0; j < 8; j++) {
1060  if (get_bits_left(gb) < 1)
1061  break;
1062  if (get_bits1(gb)) {
1063  for (k=0; k < 8; k++) {
1064  if (get_bits_left(gb) < 16)
1065  break;
1066  q->tone_level_idx_hi1[ch][sb][j][k] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi1, 0, 2);
1067  }
1068  } else {
1069  for (k=0; k < 8; k++)
1070  q->tone_level_idx_hi1[ch][sb][j][k] = 0;
1071  }
1072  }
1073 
1074  n = QDM2_SB_USED(q->sub_sampling) - 4;
1075 
1076  for (sb = 0; sb < n; sb++)
1077  for (ch = 0; ch < q->nb_channels; ch++) {
1078  if (get_bits_left(gb) < 16)
1079  break;
1080  q->tone_level_idx_hi2[ch][sb] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi2, 0, 2);
1081  if (sb > 19)
1082  q->tone_level_idx_hi2[ch][sb] -= 16;
1083  else
1084  for (j = 0; j < 8; j++)
1085  q->tone_level_idx_mid[ch][sb][j] = -16;
1086  }
1087 
1088  n = QDM2_SB_USED(q->sub_sampling) - 5;
1089 
1090  for (sb = 0; sb < n; sb++)
1091  for (ch = 0; ch < q->nb_channels; ch++)
1092  for (j = 0; j < 8; j++) {
1093  if (get_bits_left(gb) < 16)
1094  break;
1095  q->tone_level_idx_mid[ch][sb][j] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_mid, 0, 2) - 32;
1096  }
1097 }
1098 
1106 {
1107  GetBitContext gb;
1108  int i, j, k, n, ch, run, level, diff;
1109 
1110  init_get_bits(&gb, node->packet->data, node->packet->size * 8);
1111 
1113 
1114  for (i = 1; i < n; i++)
1115  for (ch = 0; ch < q->nb_channels; ch++) {
1116  level = qdm2_get_vlc(&gb, &vlc_tab_level, 0, 2);
1117  q->quantized_coeffs[ch][i][0] = level;
1118 
1119  for (j = 0; j < (8 - 1); ) {
1120  run = qdm2_get_vlc(&gb, &vlc_tab_run, 0, 1) + 1;
1121  diff = qdm2_get_se_vlc(&vlc_tab_diff, &gb, 2);
1122 
1123  for (k = 1; k <= run; k++)
1124  q->quantized_coeffs[ch][i][j + k] = (level + ((k * diff) / run));
1125 
1126  level += diff;
1127  j += run;
1128  }
1129  }
1130 
1131  for (ch = 0; ch < q->nb_channels; ch++)
1132  for (i = 0; i < 8; i++)
1133  q->quantized_coeffs[ch][0][i] = 0;
1134 }
1135 
1143 {
1144  GetBitContext gb;
1145 
1146  if (node) {
1147  init_get_bits(&gb, node->packet->data, node->packet->size * 8);
1149  fill_tone_level_array(q, 1);
1150  } else {
1151  fill_tone_level_array(q, 0);
1152  }
1153 }
1154 
1162 {
1163  GetBitContext gb;
1164  int length = 0;
1165 
1166  if (node) {
1167  length = node->packet->size * 8;
1168  init_get_bits(&gb, node->packet->data, length);
1169  }
1170 
1171  if (length >= 32) {
1172  int c = get_bits(&gb, 13);
1173 
1174  if (c > 3)
1177  q->nb_channels, 8 * c,
1179  }
1180 
1181  synthfilt_build_sb_samples(q, &gb, length, 0, 8);
1182 }
1183 
1191 {
1192  GetBitContext gb;
1193  int length = 0;
1194 
1195  if (node) {
1196  length = node->packet->size * 8;
1197  init_get_bits(&gb, node->packet->data, length);
1198  }
1199 
1200  synthfilt_build_sb_samples(q, &gb, length, 8, QDM2_SB_USED(q->sub_sampling));
1201 }
1202 
1203 /*
1204  * Process new subpackets for synthesis filter
1205  *
1206  * @param q context
1207  * @param list list with synthesis filter packets (list D)
1208  */
1210 {
1211  QDM2SubPNode *nodes[4];
1212 
1213  nodes[0] = qdm2_search_subpacket_type_in_list(list, 9);
1214  if (nodes[0])
1215  process_subpacket_9(q, nodes[0]);
1216 
1217  nodes[1] = qdm2_search_subpacket_type_in_list(list, 10);
1218  if (nodes[1])
1219  process_subpacket_10(q, nodes[1]);
1220  else
1222 
1223  nodes[2] = qdm2_search_subpacket_type_in_list(list, 11);
1224  if (nodes[0] && nodes[1] && nodes[2])
1225  process_subpacket_11(q, nodes[2]);
1226  else
1228 
1229  nodes[3] = qdm2_search_subpacket_type_in_list(list, 12);
1230  if (nodes[0] && nodes[1] && nodes[3])
1231  process_subpacket_12(q, nodes[3]);
1232  else
1234 }
1235 
1236 /*
1237  * Decode superblock, fill packet lists.
1238  *
1239  * @param q context
1240  */
1242 {
1243  GetBitContext gb;
1244  QDM2SubPacket header, *packet;
1245  int i, packet_bytes, sub_packet_size, sub_packets_D;
1246  unsigned int next_index = 0;
1247 
1248  memset(q->tone_level_idx_hi1, 0, sizeof(q->tone_level_idx_hi1));
1249  memset(q->tone_level_idx_mid, 0, sizeof(q->tone_level_idx_mid));
1250  memset(q->tone_level_idx_hi2, 0, sizeof(q->tone_level_idx_hi2));
1251 
1252  q->sub_packets_B = 0;
1253  sub_packets_D = 0;
1254 
1255  average_quantized_coeffs(q); // average elements in quantized_coeffs[max_ch][10][8]
1256 
1258  qdm2_decode_sub_packet_header(&gb, &header);
1259 
1260  if (header.type < 2 || header.type >= 8) {
1261  q->has_errors = 1;
1262  av_log(NULL, AV_LOG_ERROR, "bad superblock type\n");
1263  return;
1264  }
1265 
1266  q->superblocktype_2_3 = (header.type == 2 || header.type == 3);
1267  packet_bytes = (q->compressed_size - get_bits_count(&gb) / 8);
1268 
1269  init_get_bits(&gb, header.data, header.size * 8);
1270 
1271  if (header.type == 2 || header.type == 4 || header.type == 5) {
1272  int csum = 257 * get_bits(&gb, 8);
1273  csum += 2 * get_bits(&gb, 8);
1274 
1275  csum = qdm2_packet_checksum(q->compressed_data, q->checksum_size, csum);
1276 
1277  if (csum != 0) {
1278  q->has_errors = 1;
1279  av_log(NULL, AV_LOG_ERROR, "bad packet checksum\n");
1280  return;
1281  }
1282  }
1283 
1284  q->sub_packet_list_B[0].packet = NULL;
1285  q->sub_packet_list_D[0].packet = NULL;
1286 
1287  for (i = 0; i < 6; i++)
1288  if (--q->fft_level_exp[i] < 0)
1289  q->fft_level_exp[i] = 0;
1290 
1291  for (i = 0; packet_bytes > 0; i++) {
1292  int j;
1293 
1294  if (i >= FF_ARRAY_ELEMS(q->sub_packet_list_A)) {
1295  SAMPLES_NEEDED_2("too many packet bytes");
1296  return;
1297  }
1298 
1299  q->sub_packet_list_A[i].next = NULL;
1300 
1301  if (i > 0) {
1302  q->sub_packet_list_A[i - 1].next = &q->sub_packet_list_A[i];
1303 
1304  /* seek to next block */
1305  init_get_bits(&gb, header.data, header.size * 8);
1306  skip_bits(&gb, next_index * 8);
1307 
1308  if (next_index >= header.size)
1309  break;
1310  }
1311 
1312  /* decode subpacket */
1313  packet = &q->sub_packets[i];
1314  qdm2_decode_sub_packet_header(&gb, packet);
1315  next_index = packet->size + get_bits_count(&gb) / 8;
1316  sub_packet_size = ((packet->size > 0xff) ? 1 : 0) + packet->size + 2;
1317 
1318  if (packet->type == 0)
1319  break;
1320 
1321  if (sub_packet_size > packet_bytes) {
1322  if (packet->type != 10 && packet->type != 11 && packet->type != 12)
1323  break;
1324  packet->size += packet_bytes - sub_packet_size;
1325  }
1326 
1327  packet_bytes -= sub_packet_size;
1328 
1329  /* add subpacket to 'all subpackets' list */
1331 
1332  /* add subpacket to related list */
1333  if (packet->type == 8) {
1334  SAMPLES_NEEDED_2("packet type 8");
1335  return;
1336  } else if (packet->type >= 9 && packet->type <= 12) {
1337  /* packets for MPEG Audio like Synthesis Filter */
1338  QDM2_LIST_ADD(q->sub_packet_list_D, sub_packets_D, packet);
1339  } else if (packet->type == 13) {
1340  for (j = 0; j < 6; j++)
1341  q->fft_level_exp[j] = get_bits(&gb, 6);
1342  } else if (packet->type == 14) {
1343  for (j = 0; j < 6; j++)
1344  q->fft_level_exp[j] = qdm2_get_vlc(&gb, &fft_level_exp_vlc, 0, 2);
1345  } else if (packet->type == 15) {
1346  SAMPLES_NEEDED_2("packet type 15")
1347  return;
1348  } else if (packet->type >= 16 && packet->type < 48 &&
1349  !fft_subpackets[packet->type - 16]) {
1350  /* packets for FFT */
1352  }
1353  } // Packet bytes loop
1354 
1355  if (q->sub_packet_list_D[0].packet) {
1357  q->do_synth_filter = 1;
1358  } else if (q->do_synth_filter) {
1362  }
1363 }
1364 
1365 static void qdm2_fft_init_coefficient(QDM2Context *q, int sub_packet,
1366  int offset, int duration, int channel,
1367  int exp, int phase)
1368 {
1369  if (q->fft_coefs_min_index[duration] < 0)
1371 
1373  ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
1374  q->fft_coefs[q->fft_coefs_index].channel = channel;
1375  q->fft_coefs[q->fft_coefs_index].offset = offset;
1376  q->fft_coefs[q->fft_coefs_index].exp = exp;
1377  q->fft_coefs[q->fft_coefs_index].phase = phase;
1378  q->fft_coefs_index++;
1379 }
1380 
1382  GetBitContext *gb, int b)
1383 {
1384  int channel, stereo, phase, exp;
1385  int local_int_4, local_int_8, stereo_phase, local_int_10;
1386  int local_int_14, stereo_exp, local_int_20, local_int_28;
1387  int n, offset;
1388 
1389  local_int_4 = 0;
1390  local_int_28 = 0;
1391  local_int_20 = 2;
1392  local_int_8 = (4 - duration);
1393  local_int_10 = 1 << (q->group_order - duration - 1);
1394  offset = 1;
1395 
1396  while (1) {
1397  if (q->superblocktype_2_3) {
1398  while ((n = qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) {
1399  offset = 1;
1400  if (n == 0) {
1401  local_int_4 += local_int_10;
1402  local_int_28 += (1 << local_int_8);
1403  } else {
1404  local_int_4 += 8 * local_int_10;
1405  local_int_28 += (8 << local_int_8);
1406  }
1407  }
1408  offset += (n - 2);
1409  } else {
1410  offset += qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2);
1411  while (offset >= (local_int_10 - 1)) {
1412  offset += (1 - (local_int_10 - 1));
1413  local_int_4 += local_int_10;
1414  local_int_28 += (1 << local_int_8);
1415  }
1416  }
1417 
1418  if (local_int_4 >= q->group_size)
1419  return;
1420 
1421  local_int_14 = (offset >> local_int_8);
1422  if (local_int_14 >= FF_ARRAY_ELEMS(fft_level_index_table))
1423  return;
1424 
1425  if (q->nb_channels > 1) {
1426  channel = get_bits1(gb);
1427  stereo = get_bits1(gb);
1428  } else {
1429  channel = 0;
1430  stereo = 0;
1431  }
1432 
1433  exp = qdm2_get_vlc(gb, (b ? &fft_level_exp_vlc : &fft_level_exp_alt_vlc), 0, 2);
1434  exp += q->fft_level_exp[fft_level_index_table[local_int_14]];
1435  exp = (exp < 0) ? 0 : exp;
1436 
1437  phase = get_bits(gb, 3);
1438  stereo_exp = 0;
1439  stereo_phase = 0;
1440 
1441  if (stereo) {
1442  stereo_exp = (exp - qdm2_get_vlc(gb, &fft_stereo_exp_vlc, 0, 1));
1443  stereo_phase = (phase - qdm2_get_vlc(gb, &fft_stereo_phase_vlc, 0, 1));
1444  if (stereo_phase < 0)
1445  stereo_phase += 8;
1446  }
1447 
1448  if (q->frequency_range > (local_int_14 + 1)) {
1449  int sub_packet = (local_int_20 + local_int_28);
1450 
1451  qdm2_fft_init_coefficient(q, sub_packet, offset, duration,
1452  channel, exp, phase);
1453  if (stereo)
1454  qdm2_fft_init_coefficient(q, sub_packet, offset, duration,
1455  1 - channel,
1456  stereo_exp, stereo_phase);
1457  }
1458  offset++;
1459  }
1460 }
1461 
1463 {
1464  int i, j, min, max, value, type, unknown_flag;
1465  GetBitContext gb;
1466 
1467  if (!q->sub_packet_list_B[0].packet)
1468  return;
1469 
1470  /* reset minimum indexes for FFT coefficients */
1471  q->fft_coefs_index = 0;
1472  for (i = 0; i < 5; i++)
1473  q->fft_coefs_min_index[i] = -1;
1474 
1475  /* process subpackets ordered by type, largest type first */
1476  for (i = 0, max = 256; i < q->sub_packets_B; i++) {
1478 
1479  /* find subpacket with largest type less than max */
1480  for (j = 0, min = 0; j < q->sub_packets_B; j++) {
1481  value = q->sub_packet_list_B[j].packet->type;
1482  if (value > min && value < max) {
1483  min = value;
1484  packet = q->sub_packet_list_B[j].packet;
1485  }
1486  }
1487 
1488  max = min;
1489 
1490  /* check for errors (?) */
1491  if (!packet)
1492  return;
1493 
1494  if (i == 0 &&
1495  (packet->type < 16 || packet->type >= 48 ||
1496  fft_subpackets[packet->type - 16]))
1497  return;
1498 
1499  /* decode FFT tones */
1500  init_get_bits(&gb, packet->data, packet->size * 8);
1501 
1502  if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])
1503  unknown_flag = 1;
1504  else
1505  unknown_flag = 0;
1506 
1507  type = packet->type;
1508 
1509  if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {
1510  int duration = q->sub_sampling + 5 - (type & 15);
1511 
1512  if (duration >= 0 && duration < 4)
1513  qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);
1514  } else if (type == 31) {
1515  for (j = 0; j < 4; j++)
1516  qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
1517  } else if (type == 46) {
1518  for (j = 0; j < 6; j++)
1519  q->fft_level_exp[j] = get_bits(&gb, 6);
1520  for (j = 0; j < 4; j++)
1521  qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
1522  }
1523  } // Loop on B packets
1524 
1525  /* calculate maximum indexes for FFT coefficients */
1526  for (i = 0, j = -1; i < 5; i++)
1527  if (q->fft_coefs_min_index[i] >= 0) {
1528  if (j >= 0)
1530  j = i;
1531  }
1532  if (j >= 0)
1534 }
1535 
1537 {
1538  float level, f[6];
1539  int i;
1540  QDM2Complex c;
1541  const double iscale = 2.0 * M_PI / 512.0;
1542 
1543  tone->phase += tone->phase_shift;
1544 
1545  /* calculate current level (maximum amplitude) of tone */
1546  level = fft_tone_envelope_table[tone->duration][tone->time_index] * tone->level;
1547  c.im = level * sin(tone->phase * iscale);
1548  c.re = level * cos(tone->phase * iscale);
1549 
1550  /* generate FFT coefficients for tone */
1551  if (tone->duration >= 3 || tone->cutoff >= 3) {
1552  tone->complex[0].im += c.im;
1553  tone->complex[0].re += c.re;
1554  tone->complex[1].im -= c.im;
1555  tone->complex[1].re -= c.re;
1556  } else {
1557  f[1] = -tone->table[4];
1558  f[0] = tone->table[3] - tone->table[0];
1559  f[2] = 1.0 - tone->table[2] - tone->table[3];
1560  f[3] = tone->table[1] + tone->table[4] - 1.0;
1561  f[4] = tone->table[0] - tone->table[1];
1562  f[5] = tone->table[2];
1563  for (i = 0; i < 2; i++) {
1564  tone->complex[fft_cutoff_index_table[tone->cutoff][i]].re +=
1565  c.re * f[i];
1566  tone->complex[fft_cutoff_index_table[tone->cutoff][i]].im +=
1567  c.im * ((tone->cutoff <= i) ? -f[i] : f[i]);
1568  }
1569  for (i = 0; i < 4; i++) {
1570  tone->complex[i].re += c.re * f[i + 2];
1571  tone->complex[i].im += c.im * f[i + 2];
1572  }
1573  }
1574 
1575  /* copy the tone if it has not yet died out */
1576  if (++tone->time_index < ((1 << (5 - tone->duration)) - 1)) {
1577  memcpy(&q->fft_tones[q->fft_tone_end], tone, sizeof(FFTTone));
1578  q->fft_tone_end = (q->fft_tone_end + 1) % 1000;
1579  }
1580 }
1581 
1582 static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet)
1583 {
1584  int i, j, ch;
1585  const double iscale = 0.25 * M_PI;
1586 
1587  for (ch = 0; ch < q->channels; ch++) {
1588  memset(q->fft.complex[ch], 0, q->fft_size * sizeof(QDM2Complex));
1589  }
1590 
1591 
1592  /* apply FFT tones with duration 4 (1 FFT period) */
1593  if (q->fft_coefs_min_index[4] >= 0)
1594  for (i = q->fft_coefs_min_index[4]; i < q->fft_coefs_max_index[4]; i++) {
1595  float level;
1596  QDM2Complex c;
1597 
1598  if (q->fft_coefs[i].sub_packet != sub_packet)
1599  break;
1600 
1601  ch = (q->channels == 1) ? 0 : q->fft_coefs[i].channel;
1602  level = (q->fft_coefs[i].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[i].exp & 63];
1603 
1604  c.re = level * cos(q->fft_coefs[i].phase * iscale);
1605  c.im = level * sin(q->fft_coefs[i].phase * iscale);
1606  q->fft.complex[ch][q->fft_coefs[i].offset + 0].re += c.re;
1607  q->fft.complex[ch][q->fft_coefs[i].offset + 0].im += c.im;
1608  q->fft.complex[ch][q->fft_coefs[i].offset + 1].re -= c.re;
1609  q->fft.complex[ch][q->fft_coefs[i].offset + 1].im -= c.im;
1610  }
1611 
1612  /* generate existing FFT tones */
1613  for (i = q->fft_tone_end; i != q->fft_tone_start; ) {
1615  q->fft_tone_start = (q->fft_tone_start + 1) % 1000;
1616  }
1617 
1618  /* create and generate new FFT tones with duration 0 (long) to 3 (short) */
1619  for (i = 0; i < 4; i++)
1620  if (q->fft_coefs_min_index[i] >= 0) {
1621  for (j = q->fft_coefs_min_index[i]; j < q->fft_coefs_max_index[i]; j++) {
1622  int offset, four_i;
1623  FFTTone tone;
1624 
1625  if (q->fft_coefs[j].sub_packet != sub_packet)
1626  break;
1627 
1628  four_i = (4 - i);
1629  offset = q->fft_coefs[j].offset >> four_i;
1630  ch = (q->channels == 1) ? 0 : q->fft_coefs[j].channel;
1631 
1632  if (offset < q->frequency_range) {
1633  if (offset < 2)
1634  tone.cutoff = offset;
1635  else
1636  tone.cutoff = (offset >= 60) ? 3 : 2;
1637 
1638  tone.level = (q->fft_coefs[j].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[j].exp & 63];
1639  tone.complex = &q->fft.complex[ch][offset];
1640  tone.table = fft_tone_sample_table[i][q->fft_coefs[j].offset - (offset << four_i)];
1641  tone.phase = 64 * q->fft_coefs[j].phase - (offset << 8) - 128;
1642  tone.phase_shift = (2 * q->fft_coefs[j].offset + 1) << (7 - four_i);
1643  tone.duration = i;
1644  tone.time_index = 0;
1645 
1646  qdm2_fft_generate_tone(q, &tone);
1647  }
1648  }
1649  q->fft_coefs_min_index[i] = j;
1650  }
1651 }
1652 
1653 static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet)
1654 {
1655  const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
1656  float *out = q->output_buffer + channel;
1657  int i;
1658  q->fft.complex[channel][0].re *= 2.0f;
1659  q->fft.complex[channel][0].im = 0.0f;
1660  q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
1661  /* add samples to output buffer */
1662  for (i = 0; i < FFALIGN(q->fft_size, 8); i++) {
1663  out[0] += q->fft.complex[channel][i].re * gain;
1664  out[q->channels] += q->fft.complex[channel][i].im * gain;
1665  out += 2 * q->channels;
1666  }
1667 }
1668 
1674 {
1675  int i, k, ch, sb_used, sub_sampling, dither_state = 0;
1676 
1677  /* copy sb_samples */
1678  sb_used = QDM2_SB_USED(q->sub_sampling);
1679 
1680  for (ch = 0; ch < q->channels; ch++)
1681  for (i = 0; i < 8; i++)
1682  for (k = sb_used; k < SBLIMIT; k++)
1683  q->sb_samples[ch][(8 * index) + i][k] = 0;
1684 
1685  for (ch = 0; ch < q->nb_channels; ch++) {
1686  float *samples_ptr = q->samples + ch;
1687 
1688  for (i = 0; i < 8; i++) {
1690  q->synth_buf[ch], &(q->synth_buf_offset[ch]),
1691  ff_mpa_synth_window_float, &dither_state,
1692  samples_ptr, q->nb_channels,
1693  q->sb_samples[ch][(8 * index) + i]);
1694  samples_ptr += 32 * q->nb_channels;
1695  }
1696  }
1697 
1698  /* add samples to output buffer */
1699  sub_sampling = (4 >> q->sub_sampling);
1700 
1701  for (ch = 0; ch < q->channels; ch++)
1702  for (i = 0; i < q->frame_size; i++)
1703  q->output_buffer[q->channels * i + ch] += (1 << 23) * q->samples[q->nb_channels * sub_sampling * i + ch];
1704 }
1705 
1712  qdm2_init_vlc();
1715  rnd_table_init();
1717 }
1718 
1723 {
1724  QDM2Context *s = avctx->priv_data;
1725  uint8_t *extradata;
1726  int extradata_size;
1727  int tmp_val, tmp, size;
1728 
1729  /* extradata parsing
1730 
1731  Structure:
1732  wave {
1733  frma (QDM2)
1734  QDCA
1735  QDCP
1736  }
1737 
1738  32 size (including this field)
1739  32 tag (=frma)
1740  32 type (=QDM2 or QDMC)
1741 
1742  32 size (including this field, in bytes)
1743  32 tag (=QDCA) // maybe mandatory parameters
1744  32 unknown (=1)
1745  32 channels (=2)
1746  32 samplerate (=44100)
1747  32 bitrate (=96000)
1748  32 block size (=4096)
1749  32 frame size (=256) (for one channel)
1750  32 packet size (=1300)
1751 
1752  32 size (including this field, in bytes)
1753  32 tag (=QDCP) // maybe some tuneable parameters
1754  32 float1 (=1.0)
1755  32 zero ?
1756  32 float2 (=1.0)
1757  32 float3 (=1.0)
1758  32 unknown (27)
1759  32 unknown (8)
1760  32 zero ?
1761  */
1762 
1763  if (!avctx->extradata || (avctx->extradata_size < 48)) {
1764  av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n");
1765  return -1;
1766  }
1767 
1768  extradata = avctx->extradata;
1769  extradata_size = avctx->extradata_size;
1770 
1771  while (extradata_size > 7) {
1772  if (!memcmp(extradata, "frmaQDM", 7))
1773  break;
1774  extradata++;
1775  extradata_size--;
1776  }
1777 
1778  if (extradata_size < 12) {
1779  av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n",
1780  extradata_size);
1781  return -1;
1782  }
1783 
1784  if (memcmp(extradata, "frmaQDM", 7)) {
1785  av_log(avctx, AV_LOG_ERROR, "invalid headers, QDM? not found\n");
1786  return -1;
1787  }
1788 
1789  if (extradata[7] == 'C') {
1790 // s->is_qdmc = 1;
1791  av_log(avctx, AV_LOG_ERROR, "stream is QDMC version 1, which is not supported\n");
1792  return -1;
1793  }
1794 
1795  extradata += 8;
1796  extradata_size -= 8;
1797 
1798  size = AV_RB32(extradata);
1799 
1800  if(size > extradata_size){
1801  av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n",
1802  extradata_size, size);
1803  return -1;
1804  }
1805 
1806  extradata += 4;
1807  av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size);
1808  if (AV_RB32(extradata) != MKBETAG('Q','D','C','A')) {
1809  av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n");
1810  return -1;
1811  }
1812 
1813  extradata += 8;
1814 
1815  avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
1816  extradata += 4;
1817  if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS)
1818  return AVERROR_INVALIDDATA;
1819  avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
1821 
1822  avctx->sample_rate = AV_RB32(extradata);
1823  extradata += 4;
1824 
1825  avctx->bit_rate = AV_RB32(extradata);
1826  extradata += 4;
1827 
1828  s->group_size = AV_RB32(extradata);
1829  extradata += 4;
1830 
1831  s->fft_size = AV_RB32(extradata);
1832  extradata += 4;
1833 
1834  s->checksum_size = AV_RB32(extradata);
1835  if (s->checksum_size >= 1U << 28) {
1836  av_log(avctx, AV_LOG_ERROR, "data block size too large (%u)\n", s->checksum_size);
1837  return AVERROR_INVALIDDATA;
1838  }
1839 
1840  s->fft_order = av_log2(s->fft_size) + 1;
1841 
1842  // something like max decodable tones
1843  s->group_order = av_log2(s->group_size) + 1;
1844  s->frame_size = s->group_size / 16; // 16 iterations per super block
1846  return AVERROR_INVALIDDATA;
1847 
1848  s->sub_sampling = s->fft_order - 7;
1849  s->frequency_range = 255 / (1 << (2 - s->sub_sampling));
1850 
1851  switch ((s->sub_sampling * 2 + s->channels - 1)) {
1852  case 0: tmp = 40; break;
1853  case 1: tmp = 48; break;
1854  case 2: tmp = 56; break;
1855  case 3: tmp = 72; break;
1856  case 4: tmp = 80; break;
1857  case 5: tmp = 100;break;
1858  default: tmp=s->sub_sampling; break;
1859  }
1860  tmp_val = 0;
1861  if ((tmp * 1000) < avctx->bit_rate) tmp_val = 1;
1862  if ((tmp * 1440) < avctx->bit_rate) tmp_val = 2;
1863  if ((tmp * 1760) < avctx->bit_rate) tmp_val = 3;
1864  if ((tmp * 2240) < avctx->bit_rate) tmp_val = 4;
1865  s->cm_table_select = tmp_val;
1866 
1867  if (s->sub_sampling == 0)
1868  tmp = 7999;
1869  else
1870  tmp = ((-(s->sub_sampling -1)) & 8000) + 20000;
1871  /*
1872  0: 7999 -> 0
1873  1: 20000 -> 2
1874  2: 28000 -> 2
1875  */
1876  if (tmp < 8000)
1877  s->coeff_per_sb_select = 0;
1878  else if (tmp <= 16000)
1879  s->coeff_per_sb_select = 1;
1880  else
1881  s->coeff_per_sb_select = 2;
1882 
1883  // Fail on unknown fft order
1884  if ((s->fft_order < 7) || (s->fft_order > 9)) {
1885  av_log(avctx, AV_LOG_ERROR, "Unknown FFT order (%d), contact the developers!\n", s->fft_order);
1886  return -1;
1887  }
1888  if (s->fft_size != (1 << (s->fft_order - 1))) {
1889  av_log(avctx, AV_LOG_ERROR, "FFT size %d not power of 2.\n", s->fft_size);
1890  return AVERROR_INVALIDDATA;
1891  }
1892 
1894  ff_mpadsp_init(&s->mpadsp);
1895 
1896  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
1897 
1898  return 0;
1899 }
1900 
1902 {
1903  QDM2Context *s = avctx->priv_data;
1904 
1905  ff_rdft_end(&s->rdft_ctx);
1906 
1907  return 0;
1908 }
1909 
1910 static int qdm2_decode(QDM2Context *q, const uint8_t *in, int16_t *out)
1911 {
1912  int ch, i;
1913  const int frame_size = (q->frame_size * q->channels);
1914 
1915  /* select input buffer */
1916  q->compressed_data = in;
1918 
1919  /* copy old block, clear new block of output samples */
1920  memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));
1921  memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));
1922 
1923  /* decode block of QDM2 compressed data */
1924  if (q->sub_packet == 0) {
1925  q->has_errors = 0; // zero it for a new super block
1926  av_log(NULL,AV_LOG_DEBUG,"Superblock follows\n");
1928  }
1929 
1930  /* parse subpackets */
1931  if (!q->has_errors) {
1932  if (q->sub_packet == 2)
1934 
1936  }
1937 
1938  /* sound synthesis stage 1 (FFT) */
1939  for (ch = 0; ch < q->channels; ch++) {
1940  qdm2_calculate_fft(q, ch, q->sub_packet);
1941 
1942  if (!q->has_errors && q->sub_packet_list_C[0].packet) {
1943  SAMPLES_NEEDED_2("has errors, and C list is not empty")
1944  return -1;
1945  }
1946  }
1947 
1948  /* sound synthesis stage 2 (MPEG audio like synthesis filter) */
1949  if (!q->has_errors && q->do_synth_filter)
1951 
1952  q->sub_packet = (q->sub_packet + 1) % 16;
1953 
1954  /* clip and convert output float[] to 16bit signed samples */
1955  for (i = 0; i < frame_size; i++) {
1956  int value = (int)q->output_buffer[i];
1957 
1958  if (value > SOFTCLIP_THRESHOLD)
1959  value = (value > HARDCLIP_THRESHOLD) ? 32767 : softclip_table[ value - SOFTCLIP_THRESHOLD];
1960  else if (value < -SOFTCLIP_THRESHOLD)
1961  value = (value < -HARDCLIP_THRESHOLD) ? -32767 : -softclip_table[-value - SOFTCLIP_THRESHOLD];
1962 
1963  out[i] = value;
1964  }
1965 
1966  return 0;
1967 }
1968 
1969 static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
1970  int *got_frame_ptr, AVPacket *avpkt)
1971 {
1972  AVFrame *frame = data;
1973  const uint8_t *buf = avpkt->data;
1974  int buf_size = avpkt->size;
1975  QDM2Context *s = avctx->priv_data;
1976  int16_t *out;
1977  int i, ret;
1978 
1979  if(!buf)
1980  return 0;
1981  if(buf_size < s->checksum_size)
1982  return -1;
1983 
1984  /* get output buffer */
1985  frame->nb_samples = 16 * s->frame_size;
1986  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
1987  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1988  return ret;
1989  }
1990  out = (int16_t *)frame->data[0];
1991 
1992  for (i = 0; i < 16; i++) {
1993  if (qdm2_decode(s, buf, out) < 0)
1994  return -1;
1995  out += s->channels * s->frame_size;
1996  }
1997 
1998  *got_frame_ptr = 1;
1999 
2000  return s->checksum_size;
2001 }
2002 
2004  .name = "qdm2",
2005  .long_name = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
2006  .type = AVMEDIA_TYPE_AUDIO,
2007  .id = AV_CODEC_ID_QDM2,
2008  .priv_data_size = sizeof(QDM2Context),
2010  .init_static_data = qdm2_init_static_data,
2013  .capabilities = CODEC_CAP_DR1,
2014 };
static av_cold void qdm2_init_static_data(AVCodec *codec)
Init static data (does not depend on specific file)
Definition: qdm2.c:1711
Various QDM2 tables.
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:130
static const uint16_t vlc_tab_tone_level_idx_mid_huffcodes[24]
Definition: qdm2data.h:84
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define SBLIMIT
Definition: mpegaudio.h:43
int size
FFTTone fft_tones[1000]
FFT and tones.
Definition: qdm2.c:157
static const uint8_t vlc_tab_level_huffbits[24]
Definition: qdm2data.h:44
A node in the subpacket list.
Definition: qdm2.c:95
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
QDM2FFT fft
Definition: qdm2.c:166
static int fix_coding_method_array(int sb, int channels, sb_int8_array coding_method)
Called while processing data from subpackets 11 and 12.
Definition: qdm2.c:528
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
static const float fft_tone_level_table[2][64]
Definition: qdm2data.h:438
static void average_quantized_coeffs(QDM2Context *q)
Replace 8 elements with their average value.
Definition: qdm2.c:472
Subpacket.
Definition: qdm2.c:86
int acc
Definition: yuv2rgb.c:471
int fft_coefs_index
Definition: qdm2.c:161
static void synthfilt_build_sb_samples(QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max)
Called by process_subpacket_11 to process more data from subpacket 11 with sb 0-8.
Definition: qdm2.c:809
#define QDM2_MAX_FRAME_SIZE
Definition: qdm2.c:79
float synth_buf[MPA_MAX_CHANNELS][512 *2]
Definition: qdm2.c:175
static const uint8_t vlc_tab_type34_huffbits[10]
Definition: qdm2data.h:119
Definition: vf_drawbox.c:37
static const uint8_t fft_level_exp_alt_huffbits[28]
Definition: qdm2data.h:200
int size
Definition: avcodec.h:974
const uint8_t * buffer
Definition: get_bits.h:54
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
static const uint16_t vlc_tab_fft_tone_offset_0_huffcodes[23]
Definition: qdm2data.h:124
int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8]
Definition: qdm2.c:184
static const uint8_t fft_stereo_phase_huffbits[9]
Definition: qdm2data.h:230
const float * table
Definition: qdm2.c:108
int coeff_per_sb_select
selector for "num. of coeffs. per subband" tables. Can be 0, 1, 2
Definition: qdm2.c:145
static av_cold int qdm2_decode_close(AVCodecContext *avctx)
Definition: qdm2.c:1901
#define VLC_TYPE
Definition: get_bits.h:62
short cutoff
Definition: qdm2.c:113
unsigned int size
subpacket size
Definition: qdm2.c:88
int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26]
Definition: qdm2.c:187
#define FF_ARRAY_ELEMS(a)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
int sub_packet
Definition: qdm2.c:196
uint8_t run
Definition: svq3.c:146
float sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]
Definition: qdm2.c:177
#define AV_CH_LAYOUT_STEREO
int frequency_range
Definition: qdm2.c:143
static void qdm2_decode_sub_packet_header(GetBitContext *gb, QDM2SubPacket *sub_packet)
Fill a QDM2SubPacket structure with packet type, size, and data pointer.
Definition: qdm2.c:420
AVCodec.
Definition: avcodec.h:2812
static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD+1]
Definition: qdm2_tablegen.h:39
static void qdm2_fft_init_coefficient(QDM2Context *q, int sub_packet, int offset, int duration, int channel, int exp, int phase)
Definition: qdm2.c:1365
QDM2SubPNode sub_packet_list_C[16]
packets with errors?
Definition: qdm2.c:153
static QDM2SubPNode * qdm2_search_subpacket_type_in_list(QDM2SubPNode *list, int type)
Return node pointer to first packet of requested type in list.
Definition: qdm2.c:455
static int64_t duration
Definition: avplay.c:246
float re
Definition: qdm2.c:101
static VLC vlc_tab_tone_level_idx_hi1
Definition: qdm2.c:208
#define FFALIGN(x, a)
Definition: common.h:62
int phase
Definition: qdm2.c:109
static VLC vlc_tab_type30
Definition: qdm2.c:211
static av_cold int qdm2_decode_init(AVCodecContext *avctx)
Init parameters from codec extradata.
Definition: qdm2.c:1722
QDM2 decoder context.
Definition: qdm2.c:131
static VLC vlc_tab_fft_tone_offset[5]
Definition: qdm2.c:213
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1815
uint8_t
#define av_cold
Definition: attributes.h:66
int fft_order
order of FFT (actually fftorder+1)
Definition: qdm2.c:141
#define AV_RB32
Definition: intreadwrite.h:130
static void qdm2_decode_fft_packets(QDM2Context *q)
Definition: qdm2.c:1462
int sub_sampling
subsampling: 0=25%, 1=50%, 2=100% */
Definition: qdm2.c:144
#define b
Definition: input.c:52
void ff_mpa_synth_init_float(float *window)
#define SOFTCLIP_THRESHOLD
Definition: qdm2_tablegen.h:30
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet)
Definition: qdm2.c:1582
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
static const int16_t fft_level_index_table[256]
Definition: qdm2data.h:238
const char data[16]
Definition: mxf.c:70
static const float fft_tone_envelope_table[4][31]
Definition: qdm2data.h:476
static const uint8_t vlc_tab_tone_level_idx_hi2_huffbits[24]
Definition: qdm2data.h:101
uint8_t * data
Definition: avcodec.h:973
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:194
bitstream reader API header.
static const uint8_t coeff_per_sb_for_dequant[3][30]
Definition: qdm2data.h:300
int checksum_size
size of data block, used also for checksum
Definition: qdm2.c:137
static const uint16_t vlc_tab_fft_tone_offset_1_huffcodes[28]
Definition: qdm2data.h:135
static void process_subpacket_12(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 12.
Definition: qdm2.c:1190
static int qdm2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: qdm2.c:1969
static const uint8_t fft_subpackets[32]
Definition: qdm2data.h:510
static const uint8_t vlc_tab_run_huffbits[6]
Definition: qdm2data.h:68
static const uint8_t vlc_tab_tone_level_idx_mid_huffbits[24]
Definition: qdm2data.h:90
static const uint8_t vlc_tab_type30_huffbits[9]
Definition: qdm2data.h:110
int channels
number of channels
Definition: qdm2.c:134
static void fill_tone_level_array(QDM2Context *q, int flag)
Related to synthesis filter Called by process_subpacket_10.
Definition: qdm2.c:594
static const uint8_t frame_size[4]
Definition: g723_1_data.h:47
static const uint8_t fft_stereo_exp_huffbits[7]
Definition: qdm2data.h:221
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:555
int synth_buf_offset[MPA_MAX_CHANNELS]
Definition: qdm2.c:176
static av_cold void rnd_table_init(void)
Definition: qdm2_tablegen.h:55
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
static uint8_t random_dequant_type24[128][3]
Definition: qdm2_tablegen.h:42
static const uint8_t vlc_tab_fft_tone_offset_4_huffbits[38]
Definition: qdm2data.h:184
int compressed_size
Definition: qdm2.c:170
const uint8_t * data
pointer to subpacket data (points to input data buffer, it&#39;s not a private copy)
Definition: qdm2.c:89
int16_t offset
Definition: qdm2.c:119
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
float output_buffer[QDM2_MAX_FRAME_SIZE *2]
Definition: qdm2.c:171
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:145
static const int switchtable[23]
Definition: qdm2.c:219
int group_size
size of frame group (16 frames per group)
Definition: qdm2.c:135
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
void ff_mpa_synth_filter_float(MPADSPContext *s, float *synth_buf_ptr, int *synth_buf_offset, float *window, int *dither_state, float *samples, int incr, float *sb_samples)
static const uint16_t vlc_tab_level_huffcodes[24]
VLC TABLES.
Definition: qdm2data.h:38
int sub_packets_B
number of packets on &#39;B&#39; list
Definition: qdm2.c:152
QDM2SubPNode sub_packet_list_A[16]
list of all packets
Definition: qdm2.c:150
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
int noise_idx
index for dithering noise table
Definition: qdm2.c:197
Definition: avfft.h:73
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
static VLC fft_level_exp_alt_vlc
Definition: qdm2.c:204
uint8_t channel
Definition: qdm2.c:118
int duration
Definition: qdm2.c:111
Definition: qdm2.c:124
float tone_level[MPA_MAX_CHANNELS][30][64]
Mixed temporary data used in decoding.
Definition: qdm2.c:181
float FFTSample
Definition: avfft.h:35
static const uint16_t vlc_tab_fft_tone_offset_4_huffcodes[38]
Definition: qdm2data.h:176
RDFTContext rdft_ctx
Definition: qdm2.c:165
Definition: get_bits.h:64
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1868
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: get_bits.h:424
int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8]
Definition: qdm2.c:183
static void qdm2_synthesis_filter(QDM2Context *q, int index)
Definition: qdm2.c:1673
static VLC vlc_tab_diff
Definition: qdm2.c:202
static VLC vlc_tab_level
Definition: qdm2.c:201
static void output_buffer(int16_t **samples, int nchan, int blocksize, int32_t **buffer)
Definition: shorten.c:257
#define QDM2_SB_USED(sub_sampling)
Definition: qdm2.c:65
#define MPA_MAX_CHANNELS
Definition: mpegaudio.h:41
int group_order
Parameters built from header parameters, do not change during playback.
Definition: qdm2.c:140
int bit_rate
the average bitrate
Definition: avcodec.h:1114
static const uint8_t vlc_tab_run_huffcodes[6]
Definition: qdm2data.h:64
audio channel layout utility functions
static const uint8_t vlc_tab_fft_tone_offset_1_huffbits[28]
Definition: qdm2data.h:142
static float noise_samples[128]
Definition: qdm2_tablegen.h:43
QDM2SubPNode sub_packet_list_B[16]
FFT packets B are on list.
Definition: qdm2.c:151
static const uint16_t fft_level_exp_alt_huffcodes[28]
FFT TABLES.
Definition: qdm2data.h:193
static const uint8_t vlc_tab_diff_huffbits[37]
Definition: qdm2data.h:57
struct QDM2SubPNode * next
pointer to next packet in the list, NULL if leaf node
Definition: qdm2.c:97
static const int8_t tone_level_idx_offset_table[30][4]
Definition: qdm2data.h:307
static VLC vlc_tab_type34
Definition: qdm2.c:212
float ff_mpa_synth_window_float[]
static VLC fft_stereo_exp_vlc
Definition: qdm2.c:206
static void qdm2_decode_super_block(QDM2Context *q)
Definition: qdm2.c:1241
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:522
#define SAMPLES_NEEDED_2(why)
Definition: qdm2.c:76
static const int8_t coding_method_table[5][30]
Definition: qdm2data.h:342
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:60
static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
QDM2 checksum.
Definition: qdm2.c:404
static const uint16_t vlc_tab_tone_level_idx_hi1_huffcodes[20]
Definition: qdm2data.h:73
#define QDM2_LIST_ADD(list, size, packet)
Definition: qdm2.c:54
static uint8_t random_dequant_index[256][5]
Definition: qdm2_tablegen.h:41
static const float type30_dequant[8]
Definition: qdm2data.h:521
static VLC vlc_tab_tone_level_idx_hi2
Definition: qdm2.c:210
static VLC fft_level_exp_vlc
Definition: qdm2.c:205
#define INIT_VLC_USE_NEW_STATIC
Definition: get_bits.h:441
int fft_tone_end
Definition: qdm2.c:159
QDM2Complex complex[MPA_MAX_CHANNELS][256]
Definition: qdm2.c:125
static const float type34_delta[10]
Definition: qdm2data.h:526
int bits
Definition: get_bits.h:65
if(ac->has_optimized_func)
static const float dequant_1bit[2][3]
Definition: qdm2data.h:516
static const uint8_t fft_stereo_exp_huffcodes[7]
Definition: qdm2data.h:217
int table_allocated
Definition: get_bits.h:67
static void build_sb_samples_from_noise(QDM2Context *q, int sb)
Build subband samples with noise weighted by q->tone_level.
Definition: qdm2.c:501
float samples[MPA_MAX_CHANNELS *MPA_FRAME_SIZE]
Definition: qdm2.c:178
NULL
Definition: eval.c:55
static const uint8_t last_coeff[3]
Definition: qdm2data.h:257
Libavcodec external API header.
static const int fft_cutoff_index_table[4][2]
Definition: qdm2data.h:234
int sample_rate
samples per second
Definition: avcodec.h:1807
#define SAMPLES_NEEDED
Definition: qdm2.c:73
static void qdm2_fft_decode_tones(QDM2Context *q, int duration, GetBitContext *gb, int b)
Definition: qdm2.c:1381
static const uint8_t coeff_per_sb_for_avg[3][30]
Definition: qdm2data.h:261
int8_t tone_level_idx_mid[MPA_MAX_CHANNELS][26][8]
Definition: qdm2.c:186
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:612
AVCodec ff_qdm2_decoder
Definition: qdm2.c:2003
uint8_t phase
Definition: qdm2.c:121
int fft_coefs_min_index[5]
Definition: qdm2.c:162
static void process_subpacket_9(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 9, init quantized_coeffs with data from it.
Definition: qdm2.c:1105
FFTCoefficient fft_coefs[1000]
Definition: qdm2.c:160
int extradata_size
Definition: avcodec.h:1165
#define INIT_VLC_LE
Definition: get_bits.h:440
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
int index
Definition: gxfenc.c:72
int has_errors
packet has errors
Definition: qdm2.c:192
static const uint8_t dequant_table[64]
Definition: 4xm.c:112
int fft_level_exp[6]
Definition: qdm2.c:164
static const uint16_t vlc_tab_fft_tone_offset_2_huffcodes[32]
Definition: qdm2data.h:148
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
static void fill_coding_method_array(sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp, sb_int8_array coding_method, int nb_channels, int c, int superblocktype_2_3, int cm_table_select)
Related to synthesis filter Called by process_subpacket_11 c is built with data from subpacket 11 Mos...
Definition: qdm2.c:683
int16_t sub_packet
Definition: qdm2.c:117
#define HARDCLIP_THRESHOLD
Definition: qdm2_tablegen.h:31
float im
Definition: qdm2.c:102
static VLC vlc_tab_run
Definition: qdm2.c:203
int16_t exp
Definition: qdm2.c:120
static const uint8_t vlc_tab_type34_huffcodes[10]
Definition: qdm2data.h:115
int8_t coding_method[MPA_MAX_CHANNELS][30][64]
Definition: qdm2.c:182
static int qdm2_get_se_vlc(VLC *vlc, GetBitContext *gb, int depth)
Definition: qdm2.c:388
static void process_subpacket_10(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 10 if not null, else.
Definition: qdm2.c:1142
static void init_quantized_coeffs_elem0(int8_t *quantized_coeffs, GetBitContext *gb)
Init the first element of a channel in quantized_coeffs with data from packet 10 (quantized_coeffs[ch...
Definition: qdm2.c:1005
static av_cold void softclip_table_init(void)
Definition: qdm2_tablegen.h:45
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
uint8_t level
Definition: svq3.c:147
int fft_size
size of FFT, in complex numbers
Definition: qdm2.c:136
static const uint8_t vlc_tab_fft_tone_offset_0_huffbits[23]
Definition: qdm2data.h:130
int type
subpacket type
Definition: qdm2.c:87
int fft_coefs_max_index[5]
Definition: qdm2.c:163
int frame_size
size of data frame
Definition: qdm2.c:142
static int qdm2_decode(QDM2Context *q, const uint8_t *in, int16_t *out)
Definition: qdm2.c:1910
#define FIX_NOISE_IDX(noise_idx)
Definition: qdm2.c:67
static const float fft_tone_sample_table[4][16][5]
Definition: qdm2data.h:368
Definition: qdm2.c:105
int8_t tone_level_idx_hi1[MPA_MAX_CHANNELS][3][8][8]
Definition: qdm2.c:185
int nb_channels
Parameters from codec header, do not change during playback.
Definition: qdm2.c:133
int superblocktype_2_3
select fft tables and some algorithm based on superblock type
Definition: qdm2.c:193
static const uint8_t fft_stereo_phase_huffcodes[9]
Definition: qdm2data.h:226
common internal api header.
static const uint16_t vlc_tab_tone_level_idx_hi2_huffcodes[24]
Definition: qdm2data.h:95
static const uint16_t vlc_tab_fft_tone_offset_3_huffcodes[35]
Definition: qdm2data.h:161
int cm_table_select
selector for "coding method" tables. Can be 0, 1 (from init: 0-4)
Definition: qdm2.c:146
signed 16 bits
Definition: samplefmt.h:64
QDM2SubPacket * packet
packet
Definition: qdm2.c:96
QDM2SubPacket sub_packets[16]
Packets and packet lists.
Definition: qdm2.c:149
static const int vlc_stage3_values[60]
Definition: qdm2data.h:360
static const uint8_t vlc_tab_fft_tone_offset_2_huffbits[32]
Definition: qdm2data.h:155
mpeg audio declarations for both encoder and decoder.
static const uint16_t vlc_tab_diff_huffcodes[37]
Definition: qdm2data.h:49
QDM2Complex * complex
Definition: qdm2.c:107
int do_synth_filter
used to perform or skip synthesis filter
Definition: qdm2.c:194
const uint8_t * compressed_data
I/O data.
Definition: qdm2.c:169
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64]
Definition: qdm2.c:189
#define MKBETAG(a, b, c, d)
Definition: common.h:239
static void process_subpacket_11(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 11.
Definition: qdm2.c:1161
static int qdm2_get_vlc(GetBitContext *gb, VLC *vlc, int flag, int depth)
Definition: qdm2.c:366
MPADSPContext mpadsp
Synthesis filter.
Definition: qdm2.c:174
void * priv_data
Definition: avcodec.h:1092
static void init_tone_level_dequantization(QDM2Context *q, GetBitContext *gb)
Related to synthesis filter, process data from packet 10 Init part of quantized_coeffs via function i...
Definition: qdm2.c:1042
static VLC fft_stereo_phase_vlc
Definition: qdm2.c:207
int channels
number of audio channels
Definition: avcodec.h:1808
#define av_log2
Definition: intmath.h:85
static const uint8_t vlc_tab_tone_level_idx_hi1_huffbits[20]
Definition: qdm2data.h:79
static void qdm2_fft_generate_tone(QDM2Context *q, FFTTone *tone)
Definition: qdm2.c:1536
QDM2SubPNode sub_packet_list_D[16]
DCT packets.
Definition: qdm2.c:154
static VLC vlc_tab_tone_level_idx_mid
Definition: qdm2.c:209
int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64]
Definition: qdm2.c:188
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
static const uint16_t qdm2_vlc_offs[]
Definition: qdm2.c:215
static const uint8_t vlc_tab_type30_huffcodes[9]
Definition: qdm2data.h:106
static const uint8_t fft_level_exp_huffbits[20]
Definition: qdm2data.h:212
static const struct twinvq_data tab
static av_cold void qdm2_init_vlc(void)
Definition: qdm2.c:223
short time_index
Definition: qdm2.c:112
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83
int8_t sb_int8_array[2][30][64]
Definition: qdm2.c:81
#define SB_DITHERING_NOISE(sb, noise_idx)
Definition: qdm2.c:71
static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet)
Definition: qdm2.c:1653
static const uint8_t vlc_tab_fft_tone_offset_3_huffbits[35]
Definition: qdm2data.h:169
int nb_channels
int phase_shift
Definition: qdm2.c:110
static void process_synthesis_subpackets(QDM2Context *q, QDM2SubPNode *list)
Definition: qdm2.c:1209
#define AV_CH_LAYOUT_MONO
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
Definition: rdft.c:99
#define MPA_FRAME_SIZE
Definition: mpegaudio.h:36
float min
This structure stores compressed data.
Definition: avcodec.h:950
av_cold void ff_mpadsp_init(MPADSPContext *s)
Definition: mpegaudiodsp.c:27
static const uint16_t fft_level_exp_huffcodes[20]
Definition: qdm2data.h:206
static av_cold void init_noise_samples(void)
Definition: qdm2_tablegen.h:91
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:179
for(j=16;j >0;--j)
float level
Definition: qdm2.c:106
int fft_tone_start
Definition: qdm2.c:158