FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 FFmpeg.
9  *
10  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 /**
26  * @file
27  * QDM2 decoder
28  * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni
29  *
30  * The decoder is not perfect yet, there are still some distortions
31  * especially on files encoded with 16 or 8 subbands.
32  */
33 
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 "qdm2_tablegen.h"
48 
49 #define QDM2_LIST_ADD(list, size, packet) \
50 do { \
51  if (size > 0) { \
52  list[size - 1].next = &list[size]; \
53  } \
54  list[size].packet = packet; \
55  list[size].next = NULL; \
56  size++; \
57 } while(0)
58 
59 // Result is 8, 16 or 30
60 #define QDM2_SB_USED(sub_sampling) (((sub_sampling) >= 2) ? 30 : 8 << (sub_sampling))
61 
62 #define FIX_NOISE_IDX(noise_idx) \
63  if ((noise_idx) >= 3840) \
64  (noise_idx) -= 3840; \
65 
66 #define SB_DITHERING_NOISE(sb,noise_idx) (noise_table[(noise_idx)++] * sb_noise_attenuation[(sb)])
67 
68 #define SAMPLES_NEEDED \
69  av_log (NULL,AV_LOG_INFO,"This file triggers some untested code. Please contact the developers.\n");
70 
71 #define SAMPLES_NEEDED_2(why) \
72  av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
73 
74 #define QDM2_MAX_FRAME_SIZE 512
75 
76 typedef int8_t sb_int8_array[2][30][64];
77 
78 /**
79  * Subpacket
80  */
81 typedef struct QDM2SubPacket {
82  int type; ///< subpacket type
83  unsigned int size; ///< subpacket size
84  const uint8_t *data; ///< pointer to subpacket data (points to input data buffer, it's not a private copy)
86 
87 /**
88  * A node in the subpacket list
89  */
90 typedef struct QDM2SubPNode {
91  QDM2SubPacket *packet; ///< packet
92  struct QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node
93 } QDM2SubPNode;
94 
95 typedef struct QDM2Complex {
96  float re;
97  float im;
98 } QDM2Complex;
99 
100 typedef struct FFTTone {
101  float level;
103  const float *table;
104  int phase;
106  int duration;
107  short time_index;
108  short cutoff;
109 } FFTTone;
110 
111 typedef struct FFTCoefficient {
112  int16_t sub_packet;
114  int16_t offset;
115  int16_t exp;
118 
119 typedef struct QDM2FFT {
121 } QDM2FFT;
122 
123 /**
124  * QDM2 decoder context
125  */
126 typedef struct QDM2Context {
127  /// Parameters from codec header, do not change during playback
128  int nb_channels; ///< number of channels
129  int channels; ///< number of channels
130  int group_size; ///< size of frame group (16 frames per group)
131  int fft_size; ///< size of FFT, in complex numbers
132  int checksum_size; ///< size of data block, used also for checksum
133 
134  /// Parameters built from header parameters, do not change during playback
135  int group_order; ///< order of frame group
136  int fft_order; ///< order of FFT (actually fftorder+1)
137  int frame_size; ///< size of data frame
139  int sub_sampling; ///< subsampling: 0=25%, 1=50%, 2=100% */
140  int coeff_per_sb_select; ///< selector for "num. of coeffs. per subband" tables. Can be 0, 1, 2
141  int cm_table_select; ///< selector for "coding method" tables. Can be 0, 1 (from init: 0-4)
142 
143  /// Packets and packet lists
144  QDM2SubPacket sub_packets[16]; ///< the packets themselves
145  QDM2SubPNode sub_packet_list_A[16]; ///< list of all packets
146  QDM2SubPNode sub_packet_list_B[16]; ///< FFT packets B are on list
147  int sub_packets_B; ///< number of packets on 'B' list
148  QDM2SubPNode sub_packet_list_C[16]; ///< packets with errors?
149  QDM2SubPNode sub_packet_list_D[16]; ///< DCT packets
150 
151  /// FFT and tones
162 
163  /// I/O data
167 
168  /// Synthesis filter
174 
175  /// Mixed temporary data used in decoding
176  float tone_level[MPA_MAX_CHANNELS][30][64];
185 
186  // Flags
187  int has_errors; ///< packet has errors
188  int superblocktype_2_3; ///< select fft tables and some algorithm based on superblock type
189  int do_synth_filter; ///< used to perform or skip synthesis filter
190 
192  int noise_idx; ///< index for dithering noise table
193 } QDM2Context;
194 
195 static const int switchtable[23] = {
196  0, 5, 1, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 4
197 };
198 
199 static int qdm2_get_vlc(GetBitContext *gb, const VLC *vlc, int flag, int depth)
200 {
201  int value;
202 
203  value = get_vlc2(gb, vlc->table, vlc->bits, depth);
204 
205  /* stage-2, 3 bits exponent escape sequence */
206  if (value-- == 0)
207  value = get_bits(gb, get_bits(gb, 3) + 1);
208 
209  /* stage-3, optional */
210  if (flag) {
211  int tmp;
212 
213  if (value >= 60) {
214  av_log(NULL, AV_LOG_ERROR, "value %d in qdm2_get_vlc too large\n", value);
215  return 0;
216  }
217 
218  tmp= vlc_stage3_values[value];
219 
220  if ((value & ~3) > 0)
221  tmp += get_bits(gb, (value >> 2));
222  value = tmp;
223  }
224 
225  return value;
226 }
227 
228 static int qdm2_get_se_vlc(const VLC *vlc, GetBitContext *gb, int depth)
229 {
230  int value = qdm2_get_vlc(gb, vlc, 0, depth);
231 
232  return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
233 }
234 
235 /**
236  * QDM2 checksum
237  *
238  * @param data pointer to data to be checksum'ed
239  * @param length data length
240  * @param value checksum value
241  *
242  * @return 0 if checksum is OK
243  */
244 static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
245 {
246  int i;
247 
248  for (i = 0; i < length; i++)
249  value -= data[i];
250 
251  return (uint16_t)(value & 0xffff);
252 }
253 
254 /**
255  * Fill a QDM2SubPacket structure with packet type, size, and data pointer.
256  *
257  * @param gb bitreader context
258  * @param sub_packet packet under analysis
259  */
261  QDM2SubPacket *sub_packet)
262 {
263  sub_packet->type = get_bits(gb, 8);
264 
265  if (sub_packet->type == 0) {
266  sub_packet->size = 0;
267  sub_packet->data = NULL;
268  } else {
269  sub_packet->size = get_bits(gb, 8);
270 
271  if (sub_packet->type & 0x80) {
272  sub_packet->size <<= 8;
273  sub_packet->size |= get_bits(gb, 8);
274  sub_packet->type &= 0x7f;
275  }
276 
277  if (sub_packet->type == 0x7f)
278  sub_packet->type |= (get_bits(gb, 8) << 8);
279 
280  // FIXME: this depends on bitreader-internal data
281  sub_packet->data = &gb->buffer[get_bits_count(gb) / 8];
282  }
283 
284  av_log(NULL, AV_LOG_DEBUG, "Subpacket: type=%d size=%d start_offs=%x\n",
285  sub_packet->type, sub_packet->size, get_bits_count(gb) / 8);
286 }
287 
288 /**
289  * Return node pointer to first packet of requested type in list.
290  *
291  * @param list list of subpackets to be scanned
292  * @param type type of searched subpacket
293  * @return node pointer for subpacket if found, else NULL
294  */
296  int type)
297 {
298  while (list && list->packet) {
299  if (list->packet->type == type)
300  return list;
301  list = list->next;
302  }
303  return NULL;
304 }
305 
306 /**
307  * Replace 8 elements with their average value.
308  * Called by qdm2_decode_superblock before starting subblock decoding.
309  *
310  * @param q context
311  */
313 {
314  int i, j, n, ch, sum;
315 
317 
318  for (ch = 0; ch < q->nb_channels; ch++)
319  for (i = 0; i < n; i++) {
320  sum = 0;
321 
322  for (j = 0; j < 8; j++)
323  sum += q->quantized_coeffs[ch][i][j];
324 
325  sum /= 8;
326  if (sum > 0)
327  sum--;
328 
329  for (j = 0; j < 8; j++)
330  q->quantized_coeffs[ch][i][j] = sum;
331  }
332 }
333 
334 /**
335  * Build subband samples with noise weighted by q->tone_level.
336  * Called by synthfilt_build_sb_samples.
337  *
338  * @param q context
339  * @param sb subband index
340  */
342 {
343  int ch, j;
344 
346 
347  if (!q->nb_channels)
348  return;
349 
350  for (ch = 0; ch < q->nb_channels; ch++) {
351  for (j = 0; j < 64; j++) {
352  q->sb_samples[ch][j * 2][sb] =
353  SB_DITHERING_NOISE(sb, q->noise_idx) * q->tone_level[ch][sb][j];
354  q->sb_samples[ch][j * 2 + 1][sb] =
355  SB_DITHERING_NOISE(sb, q->noise_idx) * q->tone_level[ch][sb][j];
356  }
357  }
358 }
359 
360 /**
361  * Called while processing data from subpackets 11 and 12.
362  * Used after making changes to coding_method array.
363  *
364  * @param sb subband index
365  * @param channels number of channels
366  * @param coding_method q->coding_method[0][0][0]
367  */
368 static int fix_coding_method_array(int sb, int channels,
369  sb_int8_array coding_method)
370 {
371  int j, k;
372  int ch;
373  int run, case_val;
374 
375  for (ch = 0; ch < channels; ch++) {
376  for (j = 0; j < 64; ) {
377  if (coding_method[ch][sb][j] < 8)
378  return -1;
379  if ((coding_method[ch][sb][j] - 8) > 22) {
380  run = 1;
381  case_val = 8;
382  } else {
383  switch (switchtable[coding_method[ch][sb][j] - 8]) {
384  case 0: run = 10;
385  case_val = 10;
386  break;
387  case 1: run = 1;
388  case_val = 16;
389  break;
390  case 2: run = 5;
391  case_val = 24;
392  break;
393  case 3: run = 3;
394  case_val = 30;
395  break;
396  case 4: run = 1;
397  case_val = 30;
398  break;
399  case 5: run = 1;
400  case_val = 8;
401  break;
402  default: run = 1;
403  case_val = 8;
404  break;
405  }
406  }
407  for (k = 0; k < run; k++) {
408  if (j + k < 128) {
409  int sbjk = sb + (j + k) / 64;
410  if (sbjk > 29) {
412  continue;
413  }
414  if (coding_method[ch][sbjk][(j + k) % 64] > coding_method[ch][sb][j]) {
415  if (k > 0) {
417  //not debugged, almost never used
418  memset(&coding_method[ch][sb][j + k], case_val,
419  k *sizeof(int8_t));
420  memset(&coding_method[ch][sb][j + k], case_val,
421  3 * sizeof(int8_t));
422  }
423  }
424  }
425  }
426  j += run;
427  }
428  }
429  return 0;
430 }
431 
432 /**
433  * Related to synthesis filter
434  * Called by process_subpacket_10
435  *
436  * @param q context
437  * @param flag 1 if called after getting data from subpacket 10, 0 if no subpacket 10
438  */
440 {
441  int i, sb, ch, sb_used;
442  int tmp, tab;
443 
444  for (ch = 0; ch < q->nb_channels; ch++)
445  for (sb = 0; sb < 30; sb++)
446  for (i = 0; i < 8; i++) {
448  tmp = q->quantized_coeffs[ch][tab + 1][i] * dequant_table[q->coeff_per_sb_select][tab + 1][sb]+
450  else
451  tmp = q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];
452  if(tmp < 0)
453  tmp += 0xff;
454  q->tone_level_idx_base[ch][sb][i] = (tmp / 256) & 0xff;
455  }
456 
457  sb_used = QDM2_SB_USED(q->sub_sampling);
458 
459  if ((q->superblocktype_2_3 != 0) && !flag) {
460  for (sb = 0; sb < sb_used; sb++)
461  for (ch = 0; ch < q->nb_channels; ch++)
462  for (i = 0; i < 64; i++) {
463  q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
464  if (q->tone_level_idx[ch][sb][i] < 0)
465  q->tone_level[ch][sb][i] = 0;
466  else
467  q->tone_level[ch][sb][i] = fft_tone_level_table[0][q->tone_level_idx[ch][sb][i] & 0x3f];
468  }
469  } else {
470  tab = q->superblocktype_2_3 ? 0 : 1;
471  for (sb = 0; sb < sb_used; sb++) {
472  if ((sb >= 4) && (sb <= 23)) {
473  for (ch = 0; ch < q->nb_channels; ch++)
474  for (i = 0; i < 64; i++) {
475  tmp = q->tone_level_idx_base[ch][sb][i / 8] -
476  q->tone_level_idx_hi1[ch][sb / 8][i / 8][i % 8] -
477  q->tone_level_idx_mid[ch][sb - 4][i / 8] -
478  q->tone_level_idx_hi2[ch][sb - 4];
479  q->tone_level_idx[ch][sb][i] = tmp & 0xff;
480  if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
481  q->tone_level[ch][sb][i] = 0;
482  else
483  q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
484  }
485  } else {
486  if (sb > 4) {
487  for (ch = 0; ch < q->nb_channels; ch++)
488  for (i = 0; i < 64; i++) {
489  tmp = q->tone_level_idx_base[ch][sb][i / 8] -
490  q->tone_level_idx_hi1[ch][2][i / 8][i % 8] -
491  q->tone_level_idx_hi2[ch][sb - 4];
492  q->tone_level_idx[ch][sb][i] = tmp & 0xff;
493  if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
494  q->tone_level[ch][sb][i] = 0;
495  else
496  q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
497  }
498  } else {
499  for (ch = 0; ch < q->nb_channels; ch++)
500  for (i = 0; i < 64; i++) {
501  tmp = q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
502  if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
503  q->tone_level[ch][sb][i] = 0;
504  else
505  q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
506  }
507  }
508  }
509  }
510  }
511 }
512 
513 /**
514  * Related to synthesis filter
515  * Called by process_subpacket_11
516  * c is built with data from subpacket 11
517  * Most of this function is used only if superblock_type_2_3 == 0,
518  * never seen it in samples.
519  *
520  * @param tone_level_idx
521  * @param tone_level_idx_temp
522  * @param coding_method q->coding_method[0][0][0]
523  * @param nb_channels number of channels
524  * @param c coming from subpacket 11, passed as 8*c
525  * @param superblocktype_2_3 flag based on superblock packet type
526  * @param cm_table_select q->cm_table_select
527  */
528 static void fill_coding_method_array(sb_int8_array tone_level_idx,
529  sb_int8_array tone_level_idx_temp,
530  sb_int8_array coding_method,
531  int nb_channels,
532  int c, int superblocktype_2_3,
533  int cm_table_select)
534 {
535  int ch, sb, j;
536  int tmp, acc, esp_40, comp;
537  int add1, add2, add3, add4;
538  int64_t multres;
539 
540  if (!superblocktype_2_3) {
541  /* This case is untested, no samples available */
542  avpriv_request_sample(NULL, "!superblocktype_2_3");
543  return;
544  for (ch = 0; ch < nb_channels; ch++)
545  for (sb = 0; sb < 30; sb++) {
546  for (j = 1; j < 63; j++) { // The loop only iterates to 63 so the code doesn't overflow the buffer
547  add1 = tone_level_idx[ch][sb][j] - 10;
548  if (add1 < 0)
549  add1 = 0;
550  add2 = add3 = add4 = 0;
551  if (sb > 1) {
552  add2 = tone_level_idx[ch][sb - 2][j] + tone_level_idx_offset_table[sb][0] - 6;
553  if (add2 < 0)
554  add2 = 0;
555  }
556  if (sb > 0) {
557  add3 = tone_level_idx[ch][sb - 1][j] + tone_level_idx_offset_table[sb][1] - 6;
558  if (add3 < 0)
559  add3 = 0;
560  }
561  if (sb < 29) {
562  add4 = tone_level_idx[ch][sb + 1][j] + tone_level_idx_offset_table[sb][3] - 6;
563  if (add4 < 0)
564  add4 = 0;
565  }
566  tmp = tone_level_idx[ch][sb][j + 1] * 2 - add4 - add3 - add2 - add1;
567  if (tmp < 0)
568  tmp = 0;
569  tone_level_idx_temp[ch][sb][j + 1] = tmp & 0xff;
570  }
571  tone_level_idx_temp[ch][sb][0] = tone_level_idx_temp[ch][sb][1];
572  }
573  acc = 0;
574  for (ch = 0; ch < nb_channels; ch++)
575  for (sb = 0; sb < 30; sb++)
576  for (j = 0; j < 64; j++)
577  acc += tone_level_idx_temp[ch][sb][j];
578 
579  multres = 0x66666667LL * (acc * 10);
580  esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31);
581  for (ch = 0; ch < nb_channels; ch++)
582  for (sb = 0; sb < 30; sb++)
583  for (j = 0; j < 64; j++) {
584  comp = tone_level_idx_temp[ch][sb][j]* esp_40 * 10;
585  if (comp < 0)
586  comp += 0xff;
587  comp /= 256; // signed shift
588  switch(sb) {
589  case 0:
590  if (comp < 30)
591  comp = 30;
592  comp += 15;
593  break;
594  case 1:
595  if (comp < 24)
596  comp = 24;
597  comp += 10;
598  break;
599  case 2:
600  case 3:
601  case 4:
602  if (comp < 16)
603  comp = 16;
604  }
605  if (comp <= 5)
606  tmp = 0;
607  else if (comp <= 10)
608  tmp = 10;
609  else if (comp <= 16)
610  tmp = 16;
611  else if (comp <= 24)
612  tmp = -1;
613  else
614  tmp = 0;
615  coding_method[ch][sb][j] = ((tmp & 0xfffa) + 30 )& 0xff;
616  }
617  for (sb = 0; sb < 30; sb++)
618  fix_coding_method_array(sb, nb_channels, coding_method);
619  for (ch = 0; ch < nb_channels; ch++)
620  for (sb = 0; sb < 30; sb++)
621  for (j = 0; j < 64; j++)
622  if (sb >= 10) {
623  if (coding_method[ch][sb][j] < 10)
624  coding_method[ch][sb][j] = 10;
625  } else {
626  if (sb >= 2) {
627  if (coding_method[ch][sb][j] < 16)
628  coding_method[ch][sb][j] = 16;
629  } else {
630  if (coding_method[ch][sb][j] < 30)
631  coding_method[ch][sb][j] = 30;
632  }
633  }
634  } else { // superblocktype_2_3 != 0
635  for (ch = 0; ch < nb_channels; ch++)
636  for (sb = 0; sb < 30; sb++)
637  for (j = 0; j < 64; j++)
638  coding_method[ch][sb][j] = coding_method_table[cm_table_select][sb];
639  }
640 }
641 
642 /**
643  *
644  * Called by process_subpacket_11 to process more data from subpacket 11
645  * with sb 0-8.
646  * Called by process_subpacket_12 to process data from subpacket 12 with
647  * sb 8-sb_used.
648  *
649  * @param q context
650  * @param gb bitreader context
651  * @param length packet length in bits
652  * @param sb_min lower subband processed (sb_min included)
653  * @param sb_max higher subband processed (sb_max excluded)
654  */
656  int length, int sb_min, int sb_max)
657 {
658  int sb, j, k, n, ch, run, channels;
659  int joined_stereo, zero_encoding;
660  int type34_first;
661  float type34_div = 0;
662  float type34_predictor;
663  float samples[10];
664  int sign_bits[16] = {0};
665 
666  if (length == 0) {
667  // If no data use noise
668  for (sb=sb_min; sb < sb_max; sb++)
670 
671  return 0;
672  }
673 
674  for (sb = sb_min; sb < sb_max; sb++) {
675  channels = q->nb_channels;
676 
677  if (q->nb_channels <= 1 || sb < 12)
678  joined_stereo = 0;
679  else if (sb >= 24)
680  joined_stereo = 1;
681  else
682  joined_stereo = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;
683 
684  if (joined_stereo) {
685  if (get_bits_left(gb) >= 16)
686  for (j = 0; j < 16; j++)
687  sign_bits[j] = get_bits1(gb);
688 
689  for (j = 0; j < 64; j++)
690  if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])
691  q->coding_method[0][sb][j] = q->coding_method[1][sb][j];
692 
694  q->coding_method)) {
695  av_log(NULL, AV_LOG_ERROR, "coding method invalid\n");
697  continue;
698  }
699  channels = 1;
700  }
701 
702  for (ch = 0; ch < channels; ch++) {
704  zero_encoding = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;
705  type34_predictor = 0.0;
706  type34_first = 1;
707 
708  for (j = 0; j < 128; ) {
709  switch (q->coding_method[ch][sb][j / 2]) {
710  case 8:
711  if (get_bits_left(gb) >= 10) {
712  if (zero_encoding) {
713  for (k = 0; k < 5; k++) {
714  if ((j + 2 * k) >= 128)
715  break;
716  samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0;
717  }
718  } else {
719  n = get_bits(gb, 8);
720  if (n >= 243) {
721  av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n");
722  return AVERROR_INVALIDDATA;
723  }
724 
725  for (k = 0; k < 5; k++)
726  samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
727  }
728  for (k = 0; k < 5; k++)
729  samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx);
730  } else {
731  for (k = 0; k < 10; k++)
732  samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
733  }
734  run = 10;
735  break;
736 
737  case 10:
738  if (get_bits_left(gb) >= 1) {
739  float f = 0.81;
740 
741  if (get_bits1(gb))
742  f = -f;
743  f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;
744  samples[0] = f;
745  } else {
746  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
747  }
748  run = 1;
749  break;
750 
751  case 16:
752  if (get_bits_left(gb) >= 10) {
753  if (zero_encoding) {
754  for (k = 0; k < 5; k++) {
755  if ((j + k) >= 128)
756  break;
757  samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)];
758  }
759  } else {
760  n = get_bits (gb, 8);
761  if (n >= 243) {
762  av_log(NULL, AV_LOG_ERROR, "Invalid 8bit codeword\n");
763  return AVERROR_INVALIDDATA;
764  }
765 
766  for (k = 0; k < 5; k++)
767  samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
768  }
769  } else {
770  for (k = 0; k < 5; k++)
771  samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
772  }
773  run = 5;
774  break;
775 
776  case 24:
777  if (get_bits_left(gb) >= 7) {
778  n = get_bits(gb, 7);
779  if (n >= 125) {
780  av_log(NULL, AV_LOG_ERROR, "Invalid 7bit codeword\n");
781  return AVERROR_INVALIDDATA;
782  }
783 
784  for (k = 0; k < 3; k++)
785  samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5;
786  } else {
787  for (k = 0; k < 3; k++)
788  samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
789  }
790  run = 3;
791  break;
792 
793  case 30:
794  if (get_bits_left(gb) >= 4) {
795  unsigned index = qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1);
796  if (index >= FF_ARRAY_ELEMS(type30_dequant)) {
797  av_log(NULL, AV_LOG_ERROR, "index %d out of type30_dequant array\n", index);
798  return AVERROR_INVALIDDATA;
799  }
800  samples[0] = type30_dequant[index];
801  } else
802  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
803 
804  run = 1;
805  break;
806 
807  case 34:
808  if (get_bits_left(gb) >= 7) {
809  if (type34_first) {
810  type34_div = (float)(1 << get_bits(gb, 2));
811  samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0;
812  type34_predictor = samples[0];
813  type34_first = 0;
814  } else {
815  unsigned index = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1);
816  if (index >= FF_ARRAY_ELEMS(type34_delta)) {
817  av_log(NULL, AV_LOG_ERROR, "index %d out of type34_delta array\n", index);
818  return AVERROR_INVALIDDATA;
819  }
820  samples[0] = type34_delta[index] / type34_div + type34_predictor;
821  type34_predictor = samples[0];
822  }
823  } else {
824  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
825  }
826  run = 1;
827  break;
828 
829  default:
830  samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
831  run = 1;
832  break;
833  }
834 
835  if (joined_stereo) {
836  for (k = 0; k < run && j + k < 128; k++) {
837  q->sb_samples[0][j + k][sb] =
838  q->tone_level[0][sb][(j + k) / 2] * samples[k];
839  if (q->nb_channels == 2) {
840  if (sign_bits[(j + k) / 8])
841  q->sb_samples[1][j + k][sb] =
842  q->tone_level[1][sb][(j + k) / 2] * -samples[k];
843  else
844  q->sb_samples[1][j + k][sb] =
845  q->tone_level[1][sb][(j + k) / 2] * samples[k];
846  }
847  }
848  } else {
849  for (k = 0; k < run; k++)
850  if ((j + k) < 128)
851  q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k];
852  }
853 
854  j += run;
855  } // j loop
856  } // channel loop
857  } // subband loop
858  return 0;
859 }
860 
861 /**
862  * Init the first element of a channel in quantized_coeffs with data
863  * from packet 10 (quantized_coeffs[ch][0]).
864  * This is similar to process_subpacket_9, but for a single channel
865  * and for element [0]
866  * same VLC tables as process_subpacket_9 are used.
867  *
868  * @param quantized_coeffs pointer to quantized_coeffs[ch][0]
869  * @param gb bitreader context
870  */
871 static int init_quantized_coeffs_elem0(int8_t *quantized_coeffs,
872  GetBitContext *gb)
873 {
874  int i, k, run, level, diff;
875 
876  if (get_bits_left(gb) < 16)
877  return -1;
878  level = qdm2_get_vlc(gb, &vlc_tab_level, 0, 2);
879 
880  quantized_coeffs[0] = level;
881 
882  for (i = 0; i < 7; ) {
883  if (get_bits_left(gb) < 16)
884  return -1;
885  run = qdm2_get_vlc(gb, &vlc_tab_run, 0, 1) + 1;
886 
887  if (i + run >= 8)
888  return -1;
889 
890  if (get_bits_left(gb) < 16)
891  return -1;
892  diff = qdm2_get_se_vlc(&vlc_tab_diff, gb, 2);
893 
894  for (k = 1; k <= run; k++)
895  quantized_coeffs[i + k] = (level + ((k * diff) / run));
896 
897  level += diff;
898  i += run;
899  }
900  return 0;
901 }
902 
903 /**
904  * Related to synthesis filter, process data from packet 10
905  * Init part of quantized_coeffs via function init_quantized_coeffs_elem0
906  * Init tone_level_idx_hi1, tone_level_idx_hi2, tone_level_idx_mid with
907  * data from packet 10
908  *
909  * @param q context
910  * @param gb bitreader context
911  */
913 {
914  int sb, j, k, n, ch;
915 
916  for (ch = 0; ch < q->nb_channels; ch++) {
918 
919  if (get_bits_left(gb) < 16) {
920  memset(q->quantized_coeffs[ch][0], 0, 8);
921  break;
922  }
923  }
924 
925  n = q->sub_sampling + 1;
926 
927  for (sb = 0; sb < n; sb++)
928  for (ch = 0; ch < q->nb_channels; ch++)
929  for (j = 0; j < 8; j++) {
930  if (get_bits_left(gb) < 1)
931  break;
932  if (get_bits1(gb)) {
933  for (k=0; k < 8; k++) {
934  if (get_bits_left(gb) < 16)
935  break;
936  q->tone_level_idx_hi1[ch][sb][j][k] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi1, 0, 2);
937  }
938  } else {
939  for (k=0; k < 8; k++)
940  q->tone_level_idx_hi1[ch][sb][j][k] = 0;
941  }
942  }
943 
944  n = QDM2_SB_USED(q->sub_sampling) - 4;
945 
946  for (sb = 0; sb < n; sb++)
947  for (ch = 0; ch < q->nb_channels; ch++) {
948  if (get_bits_left(gb) < 16)
949  break;
951  if (sb > 19)
952  q->tone_level_idx_hi2[ch][sb] -= 16;
953  else
954  for (j = 0; j < 8; j++)
955  q->tone_level_idx_mid[ch][sb][j] = -16;
956  }
957 
958  n = QDM2_SB_USED(q->sub_sampling) - 5;
959 
960  for (sb = 0; sb < n; sb++)
961  for (ch = 0; ch < q->nb_channels; ch++)
962  for (j = 0; j < 8; j++) {
963  if (get_bits_left(gb) < 16)
964  break;
965  q->tone_level_idx_mid[ch][sb][j] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_mid, 0, 2) - 32;
966  }
967 }
968 
969 /**
970  * Process subpacket 9, init quantized_coeffs with data from it
971  *
972  * @param q context
973  * @param node pointer to node with packet
974  */
976 {
977  GetBitContext gb;
978  int i, j, k, n, ch, run, level, diff;
979 
980  init_get_bits(&gb, node->packet->data, node->packet->size * 8);
981 
983 
984  for (i = 1; i < n; i++)
985  for (ch = 0; ch < q->nb_channels; ch++) {
986  level = qdm2_get_vlc(&gb, &vlc_tab_level, 0, 2);
987  q->quantized_coeffs[ch][i][0] = level;
988 
989  for (j = 0; j < (8 - 1); ) {
990  run = qdm2_get_vlc(&gb, &vlc_tab_run, 0, 1) + 1;
991  diff = qdm2_get_se_vlc(&vlc_tab_diff, &gb, 2);
992 
993  if (j + run >= 8)
994  return -1;
995 
996  for (k = 1; k <= run; k++)
997  q->quantized_coeffs[ch][i][j + k] = (level + ((k * diff) / run));
998 
999  level += diff;
1000  j += run;
1001  }
1002  }
1003 
1004  for (ch = 0; ch < q->nb_channels; ch++)
1005  for (i = 0; i < 8; i++)
1006  q->quantized_coeffs[ch][0][i] = 0;
1007 
1008  return 0;
1009 }
1010 
1011 /**
1012  * Process subpacket 10 if not null, else
1013  *
1014  * @param q context
1015  * @param node pointer to node with packet
1016  */
1018 {
1019  GetBitContext gb;
1020 
1021  if (node) {
1022  init_get_bits(&gb, node->packet->data, node->packet->size * 8);
1024  fill_tone_level_array(q, 1);
1025  } else {
1026  fill_tone_level_array(q, 0);
1027  }
1028 }
1029 
1030 /**
1031  * Process subpacket 11
1032  *
1033  * @param q context
1034  * @param node pointer to node with packet
1035  */
1037 {
1038  GetBitContext gb;
1039  int length = 0;
1040 
1041  if (node) {
1042  length = node->packet->size * 8;
1043  init_get_bits(&gb, node->packet->data, length);
1044  }
1045 
1046  if (length >= 32) {
1047  int c = get_bits(&gb, 13);
1048 
1049  if (c > 3)
1052  q->nb_channels, 8 * c,
1054  }
1055 
1056  synthfilt_build_sb_samples(q, &gb, length, 0, 8);
1057 }
1058 
1059 /**
1060  * Process subpacket 12
1061  *
1062  * @param q context
1063  * @param node pointer to node with packet
1064  */
1066 {
1067  GetBitContext gb;
1068  int length = 0;
1069 
1070  if (node) {
1071  length = node->packet->size * 8;
1072  init_get_bits(&gb, node->packet->data, length);
1073  }
1074 
1075  synthfilt_build_sb_samples(q, &gb, length, 8, QDM2_SB_USED(q->sub_sampling));
1076 }
1077 
1078 /**
1079  * Process new subpackets for synthesis filter
1080  *
1081  * @param q context
1082  * @param list list with synthesis filter packets (list D)
1083  */
1085 {
1086  QDM2SubPNode *nodes[4];
1087 
1088  nodes[0] = qdm2_search_subpacket_type_in_list(list, 9);
1089  if (nodes[0])
1090  process_subpacket_9(q, nodes[0]);
1091 
1092  nodes[1] = qdm2_search_subpacket_type_in_list(list, 10);
1093  if (nodes[1])
1094  process_subpacket_10(q, nodes[1]);
1095  else
1097 
1098  nodes[2] = qdm2_search_subpacket_type_in_list(list, 11);
1099  if (nodes[0] && nodes[1] && nodes[2])
1100  process_subpacket_11(q, nodes[2]);
1101  else
1103 
1104  nodes[3] = qdm2_search_subpacket_type_in_list(list, 12);
1105  if (nodes[0] && nodes[1] && nodes[3])
1106  process_subpacket_12(q, nodes[3]);
1107  else
1109 }
1110 
1111 /**
1112  * Decode superblock, fill packet lists.
1113  *
1114  * @param q context
1115  */
1117 {
1118  GetBitContext gb;
1119  QDM2SubPacket header, *packet;
1120  int i, packet_bytes, sub_packet_size, sub_packets_D;
1121  unsigned int next_index = 0;
1122 
1123  memset(q->tone_level_idx_hi1, 0, sizeof(q->tone_level_idx_hi1));
1124  memset(q->tone_level_idx_mid, 0, sizeof(q->tone_level_idx_mid));
1125  memset(q->tone_level_idx_hi2, 0, sizeof(q->tone_level_idx_hi2));
1126 
1127  q->sub_packets_B = 0;
1128  sub_packets_D = 0;
1129 
1130  average_quantized_coeffs(q); // average elements in quantized_coeffs[max_ch][10][8]
1131 
1133  qdm2_decode_sub_packet_header(&gb, &header);
1134 
1135  if (header.type < 2 || header.type >= 8) {
1136  q->has_errors = 1;
1137  av_log(NULL, AV_LOG_ERROR, "bad superblock type\n");
1138  return;
1139  }
1140 
1141  q->superblocktype_2_3 = (header.type == 2 || header.type == 3);
1142  packet_bytes = (q->compressed_size - get_bits_count(&gb) / 8);
1143 
1144  init_get_bits(&gb, header.data, header.size * 8);
1145 
1146  if (header.type == 2 || header.type == 4 || header.type == 5) {
1147  int csum = 257 * get_bits(&gb, 8);
1148  csum += 2 * get_bits(&gb, 8);
1149 
1150  csum = qdm2_packet_checksum(q->compressed_data, q->checksum_size, csum);
1151 
1152  if (csum != 0) {
1153  q->has_errors = 1;
1154  av_log(NULL, AV_LOG_ERROR, "bad packet checksum\n");
1155  return;
1156  }
1157  }
1158 
1159  q->sub_packet_list_B[0].packet = NULL;
1160  q->sub_packet_list_D[0].packet = NULL;
1161 
1162  for (i = 0; i < 6; i++)
1163  if (--q->fft_level_exp[i] < 0)
1164  q->fft_level_exp[i] = 0;
1165 
1166  for (i = 0; packet_bytes > 0; i++) {
1167  int j;
1168 
1169  if (i >= FF_ARRAY_ELEMS(q->sub_packet_list_A)) {
1170  SAMPLES_NEEDED_2("too many packet bytes");
1171  return;
1172  }
1173 
1174  q->sub_packet_list_A[i].next = NULL;
1175 
1176  if (i > 0) {
1177  q->sub_packet_list_A[i - 1].next = &q->sub_packet_list_A[i];
1178 
1179  /* seek to next block */
1180  init_get_bits(&gb, header.data, header.size * 8);
1181  skip_bits(&gb, next_index * 8);
1182 
1183  if (next_index >= header.size)
1184  break;
1185  }
1186 
1187  /* decode subpacket */
1188  packet = &q->sub_packets[i];
1189  qdm2_decode_sub_packet_header(&gb, packet);
1190  next_index = packet->size + get_bits_count(&gb) / 8;
1191  sub_packet_size = ((packet->size > 0xff) ? 1 : 0) + packet->size + 2;
1192 
1193  if (packet->type == 0)
1194  break;
1195 
1196  if (sub_packet_size > packet_bytes) {
1197  if (packet->type != 10 && packet->type != 11 && packet->type != 12)
1198  break;
1199  packet->size += packet_bytes - sub_packet_size;
1200  }
1201 
1202  packet_bytes -= sub_packet_size;
1203 
1204  /* add subpacket to 'all subpackets' list */
1205  q->sub_packet_list_A[i].packet = packet;
1206 
1207  /* add subpacket to related list */
1208  if (packet->type == 8) {
1209  SAMPLES_NEEDED_2("packet type 8");
1210  return;
1211  } else if (packet->type >= 9 && packet->type <= 12) {
1212  /* packets for MPEG Audio like Synthesis Filter */
1213  QDM2_LIST_ADD(q->sub_packet_list_D, sub_packets_D, packet);
1214  } else if (packet->type == 13) {
1215  for (j = 0; j < 6; j++)
1216  q->fft_level_exp[j] = get_bits(&gb, 6);
1217  } else if (packet->type == 14) {
1218  for (j = 0; j < 6; j++)
1219  q->fft_level_exp[j] = qdm2_get_vlc(&gb, &fft_level_exp_vlc, 0, 2);
1220  } else if (packet->type == 15) {
1221  SAMPLES_NEEDED_2("packet type 15")
1222  return;
1223  } else if (packet->type >= 16 && packet->type < 48 &&
1224  !fft_subpackets[packet->type - 16]) {
1225  /* packets for FFT */
1227  }
1228  } // Packet bytes loop
1229 
1230  if (q->sub_packet_list_D[0].packet) {
1232  q->do_synth_filter = 1;
1233  } else if (q->do_synth_filter) {
1237  }
1238 }
1239 
1240 static void qdm2_fft_init_coefficient(QDM2Context *q, int sub_packet,
1241  int offset, int duration, int channel,
1242  int exp, int phase)
1243 {
1244  if (q->fft_coefs_min_index[duration] < 0)
1246 
1248  ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
1249  q->fft_coefs[q->fft_coefs_index].channel = channel;
1251  q->fft_coefs[q->fft_coefs_index].exp = exp;
1252  q->fft_coefs[q->fft_coefs_index].phase = phase;
1253  q->fft_coefs_index++;
1254 }
1255 
1257  GetBitContext *gb, int b)
1258 {
1259  int channel, stereo, phase, exp;
1260  int local_int_4, local_int_8, stereo_phase, local_int_10;
1261  int local_int_14, stereo_exp, local_int_20, local_int_28;
1262  int n, offset;
1263 
1264  local_int_4 = 0;
1265  local_int_28 = 0;
1266  local_int_20 = 2;
1267  local_int_8 = (4 - duration);
1268  local_int_10 = 1 << (q->group_order - duration - 1);
1269  offset = 1;
1270 
1271  while (get_bits_left(gb)>0) {
1272  if (q->superblocktype_2_3) {
1273  while ((n = qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) {
1274  if (get_bits_left(gb)<0) {
1275  if(local_int_4 < q->group_size)
1276  av_log(NULL, AV_LOG_ERROR, "overread in qdm2_fft_decode_tones()\n");
1277  return;
1278  }
1279  offset = 1;
1280  if (n == 0) {
1281  local_int_4 += local_int_10;
1282  local_int_28 += (1 << local_int_8);
1283  } else {
1284  local_int_4 += 8 * local_int_10;
1285  local_int_28 += (8 << local_int_8);
1286  }
1287  }
1288  offset += (n - 2);
1289  } else {
1290  if (local_int_10 <= 2) {
1291  av_log(NULL, AV_LOG_ERROR, "qdm2_fft_decode_tones() stuck\n");
1292  return;
1293  }
1294  offset += qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2);
1295  while (offset >= (local_int_10 - 1)) {
1296  offset += (1 - (local_int_10 - 1));
1297  local_int_4 += local_int_10;
1298  local_int_28 += (1 << local_int_8);
1299  }
1300  }
1301 
1302  if (local_int_4 >= q->group_size)
1303  return;
1304 
1305  local_int_14 = (offset >> local_int_8);
1306  if (local_int_14 >= FF_ARRAY_ELEMS(fft_level_index_table))
1307  return;
1308 
1309  if (q->nb_channels > 1) {
1310  channel = get_bits1(gb);
1311  stereo = get_bits1(gb);
1312  } else {
1313  channel = 0;
1314  stereo = 0;
1315  }
1316 
1317  exp = qdm2_get_vlc(gb, (b ? &fft_level_exp_vlc : &fft_level_exp_alt_vlc), 0, 2);
1318  exp += q->fft_level_exp[fft_level_index_table[local_int_14]];
1319  exp = (exp < 0) ? 0 : exp;
1320 
1321  phase = get_bits(gb, 3);
1322  stereo_exp = 0;
1323  stereo_phase = 0;
1324 
1325  if (stereo) {
1326  stereo_exp = (exp - qdm2_get_vlc(gb, &fft_stereo_exp_vlc, 0, 1));
1327  stereo_phase = (phase - qdm2_get_vlc(gb, &fft_stereo_phase_vlc, 0, 1));
1328  if (stereo_phase < 0)
1329  stereo_phase += 8;
1330  }
1331 
1332  if (q->frequency_range > (local_int_14 + 1)) {
1333  int sub_packet = (local_int_20 + local_int_28);
1334 
1335  if (q->fft_coefs_index + stereo >= FF_ARRAY_ELEMS(q->fft_coefs))
1336  return;
1337 
1338  qdm2_fft_init_coefficient(q, sub_packet, offset, duration,
1339  channel, exp, phase);
1340  if (stereo)
1341  qdm2_fft_init_coefficient(q, sub_packet, offset, duration,
1342  1 - channel,
1343  stereo_exp, stereo_phase);
1344  }
1345  offset++;
1346  }
1347 }
1348 
1350 {
1351  int i, j, min, max, value, type, unknown_flag;
1352  GetBitContext gb;
1353 
1354  if (!q->sub_packet_list_B[0].packet)
1355  return;
1356 
1357  /* reset minimum indexes for FFT coefficients */
1358  q->fft_coefs_index = 0;
1359  for (i = 0; i < 5; i++)
1360  q->fft_coefs_min_index[i] = -1;
1361 
1362  /* process subpackets ordered by type, largest type first */
1363  for (i = 0, max = 256; i < q->sub_packets_B; i++) {
1364  QDM2SubPacket *packet = NULL;
1365 
1366  /* find subpacket with largest type less than max */
1367  for (j = 0, min = 0; j < q->sub_packets_B; j++) {
1368  value = q->sub_packet_list_B[j].packet->type;
1369  if (value > min && value < max) {
1370  min = value;
1371  packet = q->sub_packet_list_B[j].packet;
1372  }
1373  }
1374 
1375  max = min;
1376 
1377  /* check for errors (?) */
1378  if (!packet)
1379  return;
1380 
1381  if (i == 0 &&
1382  (packet->type < 16 || packet->type >= 48 ||
1383  fft_subpackets[packet->type - 16]))
1384  return;
1385 
1386  /* decode FFT tones */
1387  init_get_bits(&gb, packet->data, packet->size * 8);
1388 
1389  if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])
1390  unknown_flag = 1;
1391  else
1392  unknown_flag = 0;
1393 
1394  type = packet->type;
1395 
1396  if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {
1397  int duration = q->sub_sampling + 5 - (type & 15);
1398 
1399  if (duration >= 0 && duration < 4)
1400  qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);
1401  } else if (type == 31) {
1402  for (j = 0; j < 4; j++)
1403  qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
1404  } else if (type == 46) {
1405  for (j = 0; j < 6; j++)
1406  q->fft_level_exp[j] = get_bits(&gb, 6);
1407  for (j = 0; j < 4; j++)
1408  qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
1409  }
1410  } // Loop on B packets
1411 
1412  /* calculate maximum indexes for FFT coefficients */
1413  for (i = 0, j = -1; i < 5; i++)
1414  if (q->fft_coefs_min_index[i] >= 0) {
1415  if (j >= 0)
1417  j = i;
1418  }
1419  if (j >= 0)
1421 }
1422 
1424 {
1425  float level, f[6];
1426  int i;
1427  QDM2Complex c;
1428  const double iscale = 2.0 * M_PI / 512.0;
1429 
1430  tone->phase += tone->phase_shift;
1431 
1432  /* calculate current level (maximum amplitude) of tone */
1433  level = fft_tone_envelope_table[tone->duration][tone->time_index] * tone->level;
1434  c.im = level * sin(tone->phase * iscale);
1435  c.re = level * cos(tone->phase * iscale);
1436 
1437  /* generate FFT coefficients for tone */
1438  if (tone->duration >= 3 || tone->cutoff >= 3) {
1439  tone->complex[0].im += c.im;
1440  tone->complex[0].re += c.re;
1441  tone->complex[1].im -= c.im;
1442  tone->complex[1].re -= c.re;
1443  } else {
1444  f[1] = -tone->table[4];
1445  f[0] = tone->table[3] - tone->table[0];
1446  f[2] = 1.0 - tone->table[2] - tone->table[3];
1447  f[3] = tone->table[1] + tone->table[4] - 1.0;
1448  f[4] = tone->table[0] - tone->table[1];
1449  f[5] = tone->table[2];
1450  for (i = 0; i < 2; i++) {
1451  tone->complex[fft_cutoff_index_table[tone->cutoff][i]].re +=
1452  c.re * f[i];
1453  tone->complex[fft_cutoff_index_table[tone->cutoff][i]].im +=
1454  c.im * ((tone->cutoff <= i) ? -f[i] : f[i]);
1455  }
1456  for (i = 0; i < 4; i++) {
1457  tone->complex[i].re += c.re * f[i + 2];
1458  tone->complex[i].im += c.im * f[i + 2];
1459  }
1460  }
1461 
1462  /* copy the tone if it has not yet died out */
1463  if (++tone->time_index < ((1 << (5 - tone->duration)) - 1)) {
1464  memcpy(&q->fft_tones[q->fft_tone_end], tone, sizeof(FFTTone));
1465  q->fft_tone_end = (q->fft_tone_end + 1) % 1000;
1466  }
1467 }
1468 
1469 static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet)
1470 {
1471  int i, j, ch;
1472  const double iscale = 0.25 * M_PI;
1473 
1474  for (ch = 0; ch < q->channels; ch++) {
1475  memset(q->fft.complex[ch], 0, q->fft_size * sizeof(QDM2Complex));
1476  }
1477 
1478 
1479  /* apply FFT tones with duration 4 (1 FFT period) */
1480  if (q->fft_coefs_min_index[4] >= 0)
1481  for (i = q->fft_coefs_min_index[4]; i < q->fft_coefs_max_index[4]; i++) {
1482  float level;
1483  QDM2Complex c;
1484 
1485  if (q->fft_coefs[i].sub_packet != sub_packet)
1486  break;
1487 
1488  ch = (q->channels == 1) ? 0 : q->fft_coefs[i].channel;
1489  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];
1490 
1491  c.re = level * cos(q->fft_coefs[i].phase * iscale);
1492  c.im = level * sin(q->fft_coefs[i].phase * iscale);
1493  q->fft.complex[ch][q->fft_coefs[i].offset + 0].re += c.re;
1494  q->fft.complex[ch][q->fft_coefs[i].offset + 0].im += c.im;
1495  q->fft.complex[ch][q->fft_coefs[i].offset + 1].re -= c.re;
1496  q->fft.complex[ch][q->fft_coefs[i].offset + 1].im -= c.im;
1497  }
1498 
1499  /* generate existing FFT tones */
1500  for (i = q->fft_tone_end; i != q->fft_tone_start; ) {
1502  q->fft_tone_start = (q->fft_tone_start + 1) % 1000;
1503  }
1504 
1505  /* create and generate new FFT tones with duration 0 (long) to 3 (short) */
1506  for (i = 0; i < 4; i++)
1507  if (q->fft_coefs_min_index[i] >= 0) {
1508  for (j = q->fft_coefs_min_index[i]; j < q->fft_coefs_max_index[i]; j++) {
1509  int offset, four_i;
1510  FFTTone tone;
1511 
1512  if (q->fft_coefs[j].sub_packet != sub_packet)
1513  break;
1514 
1515  four_i = (4 - i);
1516  offset = q->fft_coefs[j].offset >> four_i;
1517  ch = (q->channels == 1) ? 0 : q->fft_coefs[j].channel;
1518 
1519  if (offset < q->frequency_range) {
1520  if (offset < 2)
1521  tone.cutoff = offset;
1522  else
1523  tone.cutoff = (offset >= 60) ? 3 : 2;
1524 
1525  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];
1526  tone.complex = &q->fft.complex[ch][offset];
1527  tone.table = fft_tone_sample_table[i][q->fft_coefs[j].offset - (offset << four_i)];
1528  tone.phase = 64 * q->fft_coefs[j].phase - (offset << 8) - 128;
1529  tone.phase_shift = (2 * q->fft_coefs[j].offset + 1) << (7 - four_i);
1530  tone.duration = i;
1531  tone.time_index = 0;
1532 
1533  qdm2_fft_generate_tone(q, &tone);
1534  }
1535  }
1536  q->fft_coefs_min_index[i] = j;
1537  }
1538 }
1539 
1540 static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet)
1541 {
1542  const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
1543  float *out = q->output_buffer + channel;
1544  int i;
1545  q->fft.complex[channel][0].re *= 2.0f;
1546  q->fft.complex[channel][0].im = 0.0f;
1547  q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
1548  /* add samples to output buffer */
1549  for (i = 0; i < FFALIGN(q->fft_size, 8); i++) {
1550  out[0] += q->fft.complex[channel][i].re * gain;
1551  out[q->channels] += q->fft.complex[channel][i].im * gain;
1552  out += 2 * q->channels;
1553  }
1554 }
1555 
1556 /**
1557  * @param q context
1558  * @param index subpacket number
1559  */
1561 {
1562  int i, k, ch, sb_used, sub_sampling, dither_state = 0;
1563 
1564  /* copy sb_samples */
1565  sb_used = QDM2_SB_USED(q->sub_sampling);
1566 
1567  for (ch = 0; ch < q->channels; ch++)
1568  for (i = 0; i < 8; i++)
1569  for (k = sb_used; k < SBLIMIT; k++)
1570  q->sb_samples[ch][(8 * index) + i][k] = 0;
1571 
1572  for (ch = 0; ch < q->nb_channels; ch++) {
1573  float *samples_ptr = q->samples + ch;
1574 
1575  for (i = 0; i < 8; i++) {
1577  q->synth_buf[ch], &(q->synth_buf_offset[ch]),
1578  ff_mpa_synth_window_float, &dither_state,
1579  samples_ptr, q->nb_channels,
1580  q->sb_samples[ch][(8 * index) + i]);
1581  samples_ptr += 32 * q->nb_channels;
1582  }
1583  }
1584 
1585  /* add samples to output buffer */
1586  sub_sampling = (4 >> q->sub_sampling);
1587 
1588  for (ch = 0; ch < q->channels; ch++)
1589  for (i = 0; i < q->frame_size; i++)
1590  q->output_buffer[q->channels * i + ch] += (1 << 23) * q->samples[q->nb_channels * sub_sampling * i + ch];
1591 }
1592 
1593 /**
1594  * Init static data (does not depend on specific file)
1595  *
1596  * @param q context
1597  */
1598 static av_cold void qdm2_init_static_data(void) {
1599  static int done;
1600 
1601  if(done)
1602  return;
1603 
1604  qdm2_init_vlc();
1607  rnd_table_init();
1609 
1610  done = 1;
1611 }
1612 
1613 /**
1614  * Init parameters from codec extradata
1615  */
1617 {
1618  QDM2Context *s = avctx->priv_data;
1619  uint8_t *extradata;
1620  int extradata_size;
1621  int tmp_val, tmp, size;
1622 
1624 
1625  /* extradata parsing
1626 
1627  Structure:
1628  wave {
1629  frma (QDM2)
1630  QDCA
1631  QDCP
1632  }
1633 
1634  32 size (including this field)
1635  32 tag (=frma)
1636  32 type (=QDM2 or QDMC)
1637 
1638  32 size (including this field, in bytes)
1639  32 tag (=QDCA) // maybe mandatory parameters
1640  32 unknown (=1)
1641  32 channels (=2)
1642  32 samplerate (=44100)
1643  32 bitrate (=96000)
1644  32 block size (=4096)
1645  32 frame size (=256) (for one channel)
1646  32 packet size (=1300)
1647 
1648  32 size (including this field, in bytes)
1649  32 tag (=QDCP) // maybe some tuneable parameters
1650  32 float1 (=1.0)
1651  32 zero ?
1652  32 float2 (=1.0)
1653  32 float3 (=1.0)
1654  32 unknown (27)
1655  32 unknown (8)
1656  32 zero ?
1657  */
1658 
1659  if (!avctx->extradata || (avctx->extradata_size < 48)) {
1660  av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n");
1661  return AVERROR_INVALIDDATA;
1662  }
1663 
1664  extradata = avctx->extradata;
1665  extradata_size = avctx->extradata_size;
1666 
1667  while (extradata_size > 7) {
1668  if (!memcmp(extradata, "frmaQDM", 7))
1669  break;
1670  extradata++;
1671  extradata_size--;
1672  }
1673 
1674  if (extradata_size < 12) {
1675  av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n",
1676  extradata_size);
1677  return AVERROR_INVALIDDATA;
1678  }
1679 
1680  if (memcmp(extradata, "frmaQDM", 7)) {
1681  av_log(avctx, AV_LOG_ERROR, "invalid headers, QDM? not found\n");
1682  return AVERROR_INVALIDDATA;
1683  }
1684 
1685  if (extradata[7] == 'C') {
1686 // s->is_qdmc = 1;
1687  avpriv_report_missing_feature(avctx, "QDMC version 1");
1688  return AVERROR_PATCHWELCOME;
1689  }
1690 
1691  extradata += 8;
1692  extradata_size -= 8;
1693 
1694  size = AV_RB32(extradata);
1695 
1696  if(size > extradata_size){
1697  av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n",
1698  extradata_size, size);
1699  return AVERROR_INVALIDDATA;
1700  }
1701 
1702  extradata += 4;
1703  av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size);
1704  if (AV_RB32(extradata) != MKBETAG('Q','D','C','A')) {
1705  av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n");
1706  return AVERROR_INVALIDDATA;
1707  }
1708 
1709  extradata += 8;
1710 
1711  avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
1712  extradata += 4;
1713  if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS) {
1714  av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
1715  return AVERROR_INVALIDDATA;
1716  }
1717  avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
1719 
1720  avctx->sample_rate = AV_RB32(extradata);
1721  extradata += 4;
1722 
1723  avctx->bit_rate = AV_RB32(extradata);
1724  extradata += 4;
1725 
1726  s->group_size = AV_RB32(extradata);
1727  extradata += 4;
1728 
1729  s->fft_size = AV_RB32(extradata);
1730  extradata += 4;
1731 
1732  s->checksum_size = AV_RB32(extradata);
1733  if (s->checksum_size >= 1U << 28 || !s->checksum_size) {
1734  av_log(avctx, AV_LOG_ERROR, "data block size invalid (%u)\n", s->checksum_size);
1735  return AVERROR_INVALIDDATA;
1736  }
1737 
1738  s->fft_order = av_log2(s->fft_size) + 1;
1739 
1740  // Fail on unknown fft order
1741  if ((s->fft_order < 7) || (s->fft_order > 9)) {
1742  avpriv_request_sample(avctx, "Unknown FFT order %d", s->fft_order);
1743  return AVERROR_PATCHWELCOME;
1744  }
1745 
1746  // something like max decodable tones
1747  s->group_order = av_log2(s->group_size) + 1;
1748  s->frame_size = s->group_size / 16; // 16 iterations per super block
1749 
1751  return AVERROR_INVALIDDATA;
1752 
1753  s->sub_sampling = s->fft_order - 7;
1754  s->frequency_range = 255 / (1 << (2 - s->sub_sampling));
1755 
1756  if (s->frame_size * 4 >> s->sub_sampling > MPA_FRAME_SIZE) {
1757  avpriv_request_sample(avctx, "large frames");
1758  return AVERROR_PATCHWELCOME;
1759  }
1760 
1761  switch ((s->sub_sampling * 2 + s->channels - 1)) {
1762  case 0: tmp = 40; break;
1763  case 1: tmp = 48; break;
1764  case 2: tmp = 56; break;
1765  case 3: tmp = 72; break;
1766  case 4: tmp = 80; break;
1767  case 5: tmp = 100;break;
1768  default: tmp=s->sub_sampling; break;
1769  }
1770  tmp_val = 0;
1771  if ((tmp * 1000) < avctx->bit_rate) tmp_val = 1;
1772  if ((tmp * 1440) < avctx->bit_rate) tmp_val = 2;
1773  if ((tmp * 1760) < avctx->bit_rate) tmp_val = 3;
1774  if ((tmp * 2240) < avctx->bit_rate) tmp_val = 4;
1775  s->cm_table_select = tmp_val;
1776 
1777  if (avctx->bit_rate <= 8000)
1778  s->coeff_per_sb_select = 0;
1779  else if (avctx->bit_rate < 16000)
1780  s->coeff_per_sb_select = 1;
1781  else
1782  s->coeff_per_sb_select = 2;
1783 
1784  if (s->fft_size != (1 << (s->fft_order - 1))) {
1785  av_log(avctx, AV_LOG_ERROR, "FFT size %d not power of 2.\n", s->fft_size);
1786  return AVERROR_INVALIDDATA;
1787  }
1788 
1790  ff_mpadsp_init(&s->mpadsp);
1791 
1792  avctx->sample_fmt = AV_SAMPLE_FMT_S16;
1793 
1794  return 0;
1795 }
1796 
1798 {
1799  QDM2Context *s = avctx->priv_data;
1800 
1801  ff_rdft_end(&s->rdft_ctx);
1802 
1803  return 0;
1804 }
1805 
1806 static int qdm2_decode(QDM2Context *q, const uint8_t *in, int16_t *out)
1807 {
1808  int ch, i;
1809  const int frame_size = (q->frame_size * q->channels);
1810 
1811  if((unsigned)frame_size > FF_ARRAY_ELEMS(q->output_buffer)/2)
1812  return -1;
1813 
1814  /* select input buffer */
1815  q->compressed_data = in;
1817 
1818  /* copy old block, clear new block of output samples */
1819  memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));
1820  memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));
1821 
1822  /* decode block of QDM2 compressed data */
1823  if (q->sub_packet == 0) {
1824  q->has_errors = 0; // zero it for a new super block
1825  av_log(NULL,AV_LOG_DEBUG,"Superblock follows\n");
1827  }
1828 
1829  /* parse subpackets */
1830  if (!q->has_errors) {
1831  if (q->sub_packet == 2)
1833 
1835  }
1836 
1837  /* sound synthesis stage 1 (FFT) */
1838  for (ch = 0; ch < q->channels; ch++) {
1839  qdm2_calculate_fft(q, ch, q->sub_packet);
1840 
1841  if (!q->has_errors && q->sub_packet_list_C[0].packet) {
1842  SAMPLES_NEEDED_2("has errors, and C list is not empty")
1843  return -1;
1844  }
1845  }
1846 
1847  /* sound synthesis stage 2 (MPEG audio like synthesis filter) */
1848  if (!q->has_errors && q->do_synth_filter)
1850 
1851  q->sub_packet = (q->sub_packet + 1) % 16;
1852 
1853  /* clip and convert output float[] to 16bit signed samples */
1854  for (i = 0; i < frame_size; i++) {
1855  int value = (int)q->output_buffer[i];
1856 
1857  if (value > SOFTCLIP_THRESHOLD)
1858  value = (value > HARDCLIP_THRESHOLD) ? 32767 : softclip_table[ value - SOFTCLIP_THRESHOLD];
1859  else if (value < -SOFTCLIP_THRESHOLD)
1860  value = (value < -HARDCLIP_THRESHOLD) ? -32767 : -softclip_table[-value - SOFTCLIP_THRESHOLD];
1861 
1862  out[i] = value;
1863  }
1864 
1865  return 0;
1866 }
1867 
1868 static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
1869  int *got_frame_ptr, AVPacket *avpkt)
1870 {
1871  AVFrame *frame = data;
1872  const uint8_t *buf = avpkt->data;
1873  int buf_size = avpkt->size;
1874  QDM2Context *s = avctx->priv_data;
1875  int16_t *out;
1876  int i, ret;
1877 
1878  if(!buf)
1879  return 0;
1880  if(buf_size < s->checksum_size)
1881  return -1;
1882 
1883  /* get output buffer */
1884  frame->nb_samples = 16 * s->frame_size;
1885  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1886  return ret;
1887  out = (int16_t *)frame->data[0];
1888 
1889  for (i = 0; i < 16; i++) {
1890  if ((ret = qdm2_decode(s, buf, out)) < 0)
1891  return ret;
1892  out += s->channels * s->frame_size;
1893  }
1894 
1895  *got_frame_ptr = 1;
1896 
1897  return s->checksum_size;
1898 }
1899 
1901  .name = "qdm2",
1902  .long_name = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
1903  .type = AVMEDIA_TYPE_AUDIO,
1904  .id = AV_CODEC_ID_QDM2,
1905  .priv_data_size = sizeof(QDM2Context),
1907  .close = qdm2_decode_close,
1909  .capabilities = AV_CODEC_CAP_DR1,
1910 };
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:132
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define SBLIMIT
Definition: mpegaudio.h:43
FFTTone fft_tones[1000]
FFT and tones.
Definition: qdm2.c:152
A node in the subpacket list.
Definition: qdm2.c:90
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
QDM2FFT fft
Definition: qdm2.c:161
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:368
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static int 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:871
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
static const float fft_tone_level_table[2][64]
Definition: qdm2data.h:438
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static void average_quantized_coeffs(QDM2Context *q)
Replace 8 elements with their average value.
Definition: qdm2.c:312
Subpacket.
Definition: qdm2.c:81
int acc
Definition: yuv2rgb.c:533
int fft_coefs_index
Definition: qdm2.c:156
#define avpriv_request_sample(...)
static VLC vlc_tab_tone_level_idx_hi2
#define QDM2_MAX_FRAME_SIZE
Definition: qdm2.c:74
float synth_buf[MPA_MAX_CHANNELS][512 *2]
Definition: qdm2.c:170
int size
Definition: avcodec.h:1434
const char * b
Definition: vf_curves.c:109
const uint8_t * buffer
Definition: get_bits.h:56
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:53
int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8]
Definition: qdm2.c:179
const float * table
Definition: qdm2.c:103
int coeff_per_sb_select
selector for "num. of coeffs. per subband" tables. Can be 0, 1, 2
Definition: qdm2.c:140
static av_cold int qdm2_decode_close(AVCodecContext *avctx)
Definition: qdm2.c:1797
short cutoff
Definition: qdm2.c:108
unsigned int size
subpacket size
Definition: qdm2.c:83
int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26]
Definition: qdm2.c:182
int sub_packet
Definition: qdm2.c:191
uint8_t run
Definition: svq3.c:149
float sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]
Definition: qdm2.c:172
#define AV_CH_LAYOUT_STEREO
int frequency_range
Definition: qdm2.c:138
static VLC fft_stereo_exp_vlc
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:260
AVCodec.
Definition: avcodec.h:3482
static void qdm2_fft_init_coefficient(QDM2Context *q, int sub_packet, int offset, int duration, int channel, int exp, int phase)
Definition: qdm2.c:1240
QDM2SubPNode sub_packet_list_C[16]
packets with errors?
Definition: qdm2.c:148
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:295
static VLC vlc_tab_type30
float re
Definition: qdm2.c:96
#define FFALIGN(x, a)
Definition: common.h:97
int phase
Definition: qdm2.c:104
static av_cold int qdm2_decode_init(AVCodecContext *avctx)
Init parameters from codec extradata.
Definition: qdm2.c:1616
QDM2 decoder context.
Definition: qdm2.c:126
static int qdm2_get_vlc(GetBitContext *gb, const VLC *vlc, int flag, int depth)
Definition: qdm2.c:199
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2280
uint8_t
#define av_cold
Definition: attributes.h:74
int fft_order
order of FFT (actually fftorder+1)
Definition: qdm2.c:136
#define AV_RB32
Definition: intreadwrite.h:130
static void qdm2_decode_fft_packets(QDM2Context *q)
Definition: qdm2.c:1349
int sub_sampling
subsampling: 0=25%, 1=50%, 2=100% */
Definition: qdm2.c:139
void ff_mpa_synth_init_float(float *window)
#define SOFTCLIP_THRESHOLD
Definition: qdm2_tablegen.h:31
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1627
static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet)
Definition: qdm2.c:1469
static AVFrame * frame
static const int16_t fft_level_index_table[256]
Definition: qdm2data.h:238
static const float fft_tone_envelope_table[4][31]
Definition: qdm2data.h:476
uint8_t * data
Definition: avcodec.h:1433
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:213
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:132
ptrdiff_t size
Definition: opengl_enc.c:101
static const uint8_t header[24]
Definition: sdr2.c:67
static int64_t duration
Definition: ffplay.c:326
static void process_subpacket_12(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 12.
Definition: qdm2.c:1065
static int qdm2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: qdm2.c:1868
static const uint8_t fft_subpackets[32]
Definition: qdm2data.h:510
#define av_log(a,...)
int flag
Definition: checkasm.c:76
static av_cold void qdm2_init_static_data(void)
Init static data (does not depend on specific file)
Definition: qdm2.c:1598
int channels
number of channels
Definition: qdm2.c:129
static void fill_tone_level_array(QDM2Context *q, int flag)
Related to synthesis filter Called by process_subpacket_10.
Definition: qdm2.c:439
static int 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:655
#define U(x)
Definition: vp56_arith.h:37
static av_cold void qdm2_init_vlc(void)
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:594
int synth_buf_offset[MPA_MAX_CHANNELS]
Definition: qdm2.c:171
static VLC fft_level_exp_vlc
static av_cold void rnd_table_init(void)
Definition: qdm2_tablegen.h:57
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static uint8_t random_dequant_type24[128][3]
Definition: qdm2_tablegen.h:44
int compressed_size
Definition: qdm2.c:165
const uint8_t * data
pointer to subpacket data (points to input data buffer, it's not a private copy)
Definition: qdm2.c:84
static VLC vlc_tab_tone_level_idx_mid
int16_t offset
Definition: qdm2.c:114
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:178
static const int switchtable[23]
Definition: qdm2.c:195
int group_size
size of frame group (16 frames per group)
Definition: qdm2.c:130
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
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)
int sub_packets_B
number of packets on 'B' list
Definition: qdm2.c:147
QDM2SubPNode sub_packet_list_A[16]
list of all packets
Definition: qdm2.c:145
int noise_idx
index for dithering noise table
Definition: qdm2.c:192
GLsizei GLsizei * length
Definition: opengl_enc.c:115
Definition: avfft.h:73
const char * name
Name of the codec implementation.
Definition: avcodec.h:3489
uint8_t channel
Definition: qdm2.c:113
int duration
Definition: qdm2.c:106
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
Definition: qdm2.c:119
float tone_level[MPA_MAX_CHANNELS][30][64]
Mixed temporary data used in decoding.
Definition: qdm2.c:176
float FFTSample
Definition: avfft.h:35
Libavcodec external API header.
int depth
Definition: v4l.c:62
RDFTContext rdft_ctx
Definition: qdm2.c:160
Definition: get_bits.h:64
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2333
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:60
int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8]
Definition: qdm2.c:178
static void qdm2_synthesis_filter(QDM2Context *q, int index)
Definition: qdm2.c:1560
static VLC vlc_tab_tone_level_idx_hi1
#define QDM2_SB_USED(sub_sampling)
Definition: qdm2.c:60
#define MPA_MAX_CHANNELS
Definition: mpegaudio.h:41
int group_order
Parameters built from header parameters, do not change during playback.
Definition: qdm2.c:135
static VLC fft_level_exp_alt_vlc
int bit_rate
the average bitrate
Definition: avcodec.h:1577
audio channel layout utility functions
static float noise_samples[128]
Definition: qdm2_tablegen.h:45
QDM2SubPNode sub_packet_list_B[16]
FFT packets B are on list.
Definition: qdm2.c:146
struct QDM2SubPNode * next
pointer to next packet in the list, NULL if leaf node
Definition: qdm2.c:92
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
static const int8_t tone_level_idx_offset_table[30][4]
Definition: qdm2data.h:307
float ff_mpa_synth_window_float[]
static void qdm2_decode_super_block(QDM2Context *q)
Decode superblock, fill packet lists.
Definition: qdm2.c:1116
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:561
#define SAMPLES_NEEDED_2(why)
Definition: qdm2.c:71
static const int8_t coding_method_table[5][30]
Definition: qdm2data.h:342
static VLC fft_stereo_phase_vlc
int n
Definition: avisynth_c.h:547
static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
QDM2 checksum.
Definition: qdm2.c:244
#define QDM2_LIST_ADD(list, size, packet)
Definition: qdm2.c:49
static uint8_t random_dequant_index[256][5]
Definition: qdm2_tablegen.h:43
static const float type30_dequant[8]
Definition: qdm2data.h:521
int fft_tone_end
Definition: qdm2.c:154
static uint16_t softclip_table[HARDCLIP_THRESHOLD-SOFTCLIP_THRESHOLD+1]
Definition: qdm2_tablegen.h:41
#define FF_ARRAY_ELEMS(a)
QDM2Complex complex[MPA_MAX_CHANNELS][256]
Definition: qdm2.c:120
#define av_log2
Definition: intmath.h:100
static const float type34_delta[10]
Definition: qdm2data.h:526
static VLC vlc_tab_fft_tone_offset[5]
int bits
Definition: get_bits.h:65
static const float dequant_1bit[2][3]
Definition: qdm2data.h:516
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static void build_sb_samples_from_noise(QDM2Context *q, int sb)
Build subband samples with noise weighted by q->tone_level.
Definition: qdm2.c:341
float samples[MPA_MAX_CHANNELS *MPA_FRAME_SIZE]
Definition: qdm2.c:173
static const uint8_t last_coeff[3]
Definition: qdm2data.h:257
int frame_size
Definition: mxfenc.c:1819
static const int fft_cutoff_index_table[4][2]
Definition: qdm2data.h:234
int sample_rate
samples per second
Definition: avcodec.h:2272
#define SAMPLES_NEEDED
Definition: qdm2.c:68
static void qdm2_fft_decode_tones(QDM2Context *q, int duration, GetBitContext *gb, int b)
Definition: qdm2.c:1256
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:181
main external API structure.
Definition: avcodec.h:1512
static int qdm2_get_se_vlc(const VLC *vlc, GetBitContext *gb, int depth)
Definition: qdm2.c:228
float output_buffer[QDM2_MAX_FRAME_SIZE *MPA_MAX_CHANNELS *2]
Definition: qdm2.c:166
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:1048
AVCodec ff_qdm2_decoder
Definition: qdm2.c:1900
uint8_t phase
Definition: qdm2.c:116
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int fft_coefs_min_index[5]
Definition: qdm2.c:157
void * buf
Definition: avisynth_c.h:553
GLint GLenum type
Definition: opengl_enc.c:105
FFTCoefficient fft_coefs[1000]
Definition: qdm2.c:155
int extradata_size
Definition: avcodec.h:1628
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:305
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:298
int index
Definition: gxfenc.c:89
int has_errors
packet has errors
Definition: qdm2.c:187
static const uint8_t dequant_table[64]
Definition: 4xm.c:114
int fft_level_exp[6]
Definition: qdm2.c:159
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:415
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:528
int16_t sub_packet
Definition: qdm2.c:112
#define HARDCLIP_THRESHOLD
Definition: qdm2_tablegen.h:32
float im
Definition: qdm2.c:97
int16_t exp
Definition: qdm2.c:115
int8_t coding_method[MPA_MAX_CHANNELS][30][64]
Definition: qdm2.c:177
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static void process_subpacket_10(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 10 if not null, else.
Definition: qdm2.c:1017
static av_cold void softclip_table_init(void)
Definition: qdm2_tablegen.h:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
uint8_t level
Definition: svq3.c:150
int fft_size
size of FFT, in complex numbers
Definition: qdm2.c:131
int type
subpacket type
Definition: qdm2.c:82
int fft_coefs_max_index[5]
Definition: qdm2.c:158
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:521
int frame_size
size of data frame
Definition: qdm2.c:137
static int qdm2_decode(QDM2Context *q, const uint8_t *in, int16_t *out)
Definition: qdm2.c:1806
#define FIX_NOISE_IDX(noise_idx)
Definition: qdm2.c:62
static const float fft_tone_sample_table[4][16][5]
Definition: qdm2data.h:368
Definition: qdm2.c:100
int8_t tone_level_idx_hi1[MPA_MAX_CHANNELS][3][8][8]
Definition: qdm2.c:180
int nb_channels
Parameters from codec header, do not change during playback.
Definition: qdm2.c:128
int superblocktype_2_3
select fft tables and some algorithm based on superblock type
Definition: qdm2.c:188
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:280
static VLC vlc_tab_diff
Definition: qdm2_tablegen.h:99
int cm_table_select
selector for "coding method" tables. Can be 0, 1 (from init: 0-4)
Definition: qdm2.c:141
signed 16 bits
Definition: samplefmt.h:62
static double c[64]
QDM2SubPacket * packet
packet
Definition: qdm2.c:91
QDM2SubPacket sub_packets[16]
Packets and packet lists.
Definition: qdm2.c:144
static const int vlc_stage3_values[60]
Definition: qdm2data.h:360
mpeg audio declarations for both encoder and decoder.
QDM2Complex * complex
Definition: qdm2.c:102
int do_synth_filter
used to perform or skip synthesis filter
Definition: qdm2.c:189
const uint8_t * compressed_data
I/O data.
Definition: qdm2.c:164
int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64]
Definition: qdm2.c:184
static int process_subpacket_9(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 9, init quantized_coeffs with data from it.
Definition: qdm2.c:975
#define MKBETAG(a, b, c, d)
Definition: common.h:342
static void process_subpacket_11(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 11.
Definition: qdm2.c:1036
MPADSPContext mpadsp
Synthesis filter.
Definition: qdm2.c:169
void * priv_data
Definition: avcodec.h:1554
static VLC vlc_tab_level
Definition: qdm2_tablegen.h:98
static VLC vlc_tab_run
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:912
static av_always_inline int diff(const uint32_t a, const uint32_t b)
int channels
number of audio channels
Definition: avcodec.h:2273
static void qdm2_fft_generate_tone(QDM2Context *q, FFTTone *tone)
Definition: qdm2.c:1423
QDM2SubPNode sub_packet_list_D[16]
DCT packets.
Definition: qdm2.c:149
int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64]
Definition: qdm2.c:183
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
static const struct twinvq_data tab
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
short time_index
Definition: qdm2.c:107
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:76
#define M_PI
Definition: mathematics.h:46
#define SB_DITHERING_NOISE(sb, noise_idx)
Definition: qdm2.c:66
static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet)
Definition: qdm2.c:1540
int nb_channels
int phase_shift
Definition: qdm2.c:105
static void process_synthesis_subpackets(QDM2Context *q, QDM2SubPNode *list)
Process new subpackets for synthesis filter.
Definition: qdm2.c:1084
#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:1410
av_cold void ff_mpadsp_init(MPADSPContext *s)
Definition: mpegaudiodsp.c:27
static av_cold void init_noise_samples(void)
Definition: qdm2_tablegen.h:88
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857
static VLC vlc_tab_type34
for(j=16;j >0;--j)
float level
Definition: qdm2.c:101
int fft_tone_start
Definition: qdm2.c:153