FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
atrac3plus.c
Go to the documentation of this file.
1 /*
2  * ATRAC3+ compatible decoder
3  *
4  * Copyright (c) 2010-2013 Maxim Poliakovski
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * Bitstream parser for ATRAC3+ decoder.
26  */
27 
28 #include "libavutil/avassert.h"
29 #include "avcodec.h"
30 #include "get_bits.h"
31 #include "atrac3plus.h"
32 #include "atrac3plus_data.h"
33 
34 static VLC_TYPE tables_data[154276][2];
35 static VLC wl_vlc_tabs[4];
36 static VLC sf_vlc_tabs[8];
37 static VLC ct_vlc_tabs[4];
38 static VLC spec_vlc_tabs[112];
39 static VLC gain_vlc_tabs[11];
40 static VLC tone_vlc_tabs[7];
41 
42 #define GET_DELTA(gb, delta_bits) \
43  ((delta_bits) ? get_bits((gb), (delta_bits)) : 0)
44 
45 /**
46  * Generate canonical VLC table from given descriptor.
47  *
48  * @param[in] cb ptr to codebook descriptor
49  * @param[in] xlat ptr to translation table or NULL
50  * @param[in,out] tab_offset starting offset to the generated vlc table
51  * @param[out] out_vlc ptr to vlc table to be generated
52  */
53 static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t *xlat,
54  int *tab_offset, VLC *out_vlc)
55 {
56  int i, b;
57  uint16_t codes[256];
58  uint8_t bits[256];
59  unsigned code = 0;
60  int index = 0;
61  int min_len = *cb++; // get shortest codeword length
62  int max_len = *cb++; // get longest codeword length
63 
64  for (b = min_len; b <= max_len; b++) {
65  for (i = *cb++; i > 0; i--) {
66  av_assert0(index < 256);
67  bits[index] = b;
68  codes[index] = code++;
69  index++;
70  }
71  code <<= 1;
72  }
73 
74  out_vlc->table = &tables_data[*tab_offset];
75  out_vlc->table_allocated = 1 << max_len;
76 
77  ff_init_vlc_sparse(out_vlc, max_len, index, bits, 1, 1, codes, 2, 2,
78  xlat, 1, 1, INIT_VLC_USE_NEW_STATIC);
79 
80  *tab_offset += 1 << max_len;
81 }
82 
84 {
85  int i, wl_vlc_offs, ct_vlc_offs, sf_vlc_offs, tab_offset;
86 
87  static const int wl_nb_bits[4] = { 2, 3, 5, 5 };
88  static const int wl_nb_codes[4] = { 3, 5, 8, 8 };
89  static const uint8_t * const wl_bits[4] = {
92  };
93  static const uint8_t * const wl_codes[4] = {
96  };
97  static const uint8_t * const wl_xlats[4] = {
99  };
100 
101  static const int ct_nb_bits[4] = { 3, 4, 4, 4 };
102  static const int ct_nb_codes[4] = { 4, 8, 8, 8 };
103  static const uint8_t * const ct_bits[4] = {
106  };
107  static const uint8_t * const ct_codes[4] = {
110  };
111  static const uint8_t * const ct_xlats[4] = {
113  };
114 
115  static const int sf_nb_bits[8] = { 9, 9, 9, 9, 6, 6, 7, 7 };
116  static const int sf_nb_codes[8] = { 64, 64, 64, 64, 16, 16, 16, 16 };
117  static const uint8_t * const sf_bits[8] = {
121  };
122  static const uint16_t * const sf_codes[8] = {
126  };
127  static const uint8_t * const sf_xlats[8] = {
130  };
131 
132  static const uint8_t * const gain_cbs[11] = {
139  };
140  static const uint8_t * const gain_xlats[11] = {
146  };
147 
148  static const uint8_t * const tone_cbs[7] = {
153  };
154  static const uint8_t * const tone_xlats[7] = {
158  };
159 
160  for (i = 0, wl_vlc_offs = 0, ct_vlc_offs = 2508; i < 4; i++) {
161  wl_vlc_tabs[i].table = &tables_data[wl_vlc_offs];
162  wl_vlc_tabs[i].table_allocated = 1 << wl_nb_bits[i];
163  ct_vlc_tabs[i].table = &tables_data[ct_vlc_offs];
164  ct_vlc_tabs[i].table_allocated = 1 << ct_nb_bits[i];
165 
166  ff_init_vlc_sparse(&wl_vlc_tabs[i], wl_nb_bits[i], wl_nb_codes[i],
167  wl_bits[i], 1, 1,
168  wl_codes[i], 1, 1,
169  wl_xlats[i], 1, 1,
171 
172  ff_init_vlc_sparse(&ct_vlc_tabs[i], ct_nb_bits[i], ct_nb_codes[i],
173  ct_bits[i], 1, 1,
174  ct_codes[i], 1, 1,
175  ct_xlats[i], 1, 1,
177 
178  wl_vlc_offs += wl_vlc_tabs[i].table_allocated;
179  ct_vlc_offs += ct_vlc_tabs[i].table_allocated;
180  }
181 
182  for (i = 0, sf_vlc_offs = 76; i < 8; i++) {
183  sf_vlc_tabs[i].table = &tables_data[sf_vlc_offs];
184  sf_vlc_tabs[i].table_allocated = 1 << sf_nb_bits[i];
185 
186  ff_init_vlc_sparse(&sf_vlc_tabs[i], sf_nb_bits[i], sf_nb_codes[i],
187  sf_bits[i], 1, 1,
188  sf_codes[i], 2, 2,
189  sf_xlats[i], 1, 1,
191  sf_vlc_offs += sf_vlc_tabs[i].table_allocated;
192  }
193 
194  tab_offset = 2564;
195 
196  /* build huffman tables for spectrum decoding */
197  for (i = 0; i < 112; i++) {
198  if (atrac3p_spectra_tabs[i].cb)
200  atrac3p_spectra_tabs[i].xlat,
201  &tab_offset, &spec_vlc_tabs[i]);
202  else
203  spec_vlc_tabs[i].table = 0;
204  }
205 
206  /* build huffman tables for gain data decoding */
207  for (i = 0; i < 11; i++)
208  build_canonical_huff(gain_cbs[i], gain_xlats[i], &tab_offset, &gain_vlc_tabs[i]);
209 
210  /* build huffman tables for tone decoding */
211  for (i = 0; i < 7; i++)
212  build_canonical_huff(tone_cbs[i], tone_xlats[i], &tab_offset, &tone_vlc_tabs[i]);
213 }
214 
215 /**
216  * Decode number of coded quantization units.
217  *
218  * @param[in] gb the GetBit context
219  * @param[in,out] chan ptr to the channel parameters
220  * @param[in,out] ctx ptr to the channel unit context
221  * @param[in] avctx ptr to the AVCodecContext
222  * @return result code: 0 = OK, otherwise - error code
223  */
225  Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx)
226 {
227  chan->fill_mode = get_bits(gb, 2);
228  if (!chan->fill_mode) {
229  chan->num_coded_vals = ctx->num_quant_units;
230  } else {
231  chan->num_coded_vals = get_bits(gb, 5);
232  if (chan->num_coded_vals > ctx->num_quant_units) {
233  av_log(avctx, AV_LOG_ERROR,
234  "Invalid number of transmitted units!\n");
235  return AVERROR_INVALIDDATA;
236  }
237 
238  if (chan->fill_mode == 3)
239  chan->split_point = get_bits(gb, 2) + (chan->ch_num << 1) + 1;
240  }
241 
242  return 0;
243 }
244 
245 /**
246  * Add weighting coefficients to the decoded word-length information.
247  *
248  * @param[in,out] ctx ptr to the channel unit context
249  * @param[in,out] chan ptr to the channel parameters
250  * @param[in] wtab_idx index of the table of weights
251  * @param[in] avctx ptr to the AVCodecContext
252  * @return result code: 0 = OK, otherwise - error code
253  */
255  Atrac3pChanParams *chan, int wtab_idx,
256  AVCodecContext *avctx)
257 {
258  int i;
259  const int8_t *weights_tab =
260  &atrac3p_wl_weights[chan->ch_num * 3 + wtab_idx - 1][0];
261 
262  for (i = 0; i < ctx->num_quant_units; i++) {
263  chan->qu_wordlen[i] += weights_tab[i];
264  if (chan->qu_wordlen[i] < 0 || chan->qu_wordlen[i] > 7) {
265  av_log(avctx, AV_LOG_ERROR,
266  "WL index out of range: pos=%d, val=%d!\n",
267  i, chan->qu_wordlen[i]);
268  return AVERROR_INVALIDDATA;
269  }
270  }
271 
272  return 0;
273 }
274 
275 /**
276  * Subtract weighting coefficients from decoded scalefactors.
277  *
278  * @param[in,out] ctx ptr to the channel unit context
279  * @param[in,out] chan ptr to the channel parameters
280  * @param[in] wtab_idx index of table of weights
281  * @param[in] avctx ptr to the AVCodecContext
282  * @return result code: 0 = OK, otherwise - error code
283  */
285  Atrac3pChanParams *chan, int wtab_idx,
286  AVCodecContext *avctx)
287 {
288  int i;
289  const int8_t *weights_tab = &atrac3p_sf_weights[wtab_idx - 1][0];
290 
291  for (i = 0; i < ctx->used_quant_units; i++) {
292  chan->qu_sf_idx[i] -= weights_tab[i];
293  if (chan->qu_sf_idx[i] < 0 || chan->qu_sf_idx[i] > 63) {
294  av_log(avctx, AV_LOG_ERROR,
295  "SF index out of range: pos=%d, val=%d!\n",
296  i, chan->qu_sf_idx[i]);
297  return AVERROR_INVALIDDATA;
298  }
299  }
300 
301  return 0;
302 }
303 
304 /**
305  * Unpack vector quantization tables.
306  *
307  * @param[in] start_val start value for the unpacked table
308  * @param[in] shape_vec ptr to table to unpack
309  * @param[out] dst ptr to output array
310  * @param[in] num_values number of values to unpack
311  */
312 static inline void unpack_vq_shape(int start_val, const int8_t *shape_vec,
313  int *dst, int num_values)
314 {
315  int i;
316 
317  if (num_values) {
318  dst[0] = dst[1] = dst[2] = start_val;
319  for (i = 3; i < num_values; i++)
320  dst[i] = start_val - shape_vec[atrac3p_qu_num_to_seg[i] - 1];
321  }
322 }
323 
324 #define UNPACK_SF_VQ_SHAPE(gb, dst, num_vals) \
325  start_val = get_bits((gb), 6); \
326  unpack_vq_shape(start_val, &atrac3p_sf_shapes[get_bits((gb), 6)][0], \
327  (dst), (num_vals))
328 
329 /**
330  * Decode word length for each quantization unit of a channel.
331  *
332  * @param[in] gb the GetBit context
333  * @param[in,out] ctx ptr to the channel unit context
334  * @param[in] ch_num channel to process
335  * @param[in] avctx ptr to the AVCodecContext
336  * @return result code: 0 = OK, otherwise - error code
337  */
339  int ch_num, AVCodecContext *avctx)
340 {
341  int i, weight_idx = 0, delta, diff, pos, delta_bits, min_val, flag,
342  ret, start_val;
343  VLC *vlc_tab;
344  Atrac3pChanParams *chan = &ctx->channels[ch_num];
345  Atrac3pChanParams *ref_chan = &ctx->channels[0];
346 
347  chan->fill_mode = 0;
348 
349  switch (get_bits(gb, 2)) { /* switch according to coding mode */
350  case 0: /* coded using constant number of bits */
351  for (i = 0; i < ctx->num_quant_units; i++)
352  chan->qu_wordlen[i] = get_bits(gb, 3);
353  break;
354  case 1:
355  if (ch_num) {
356  if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
357  return ret;
358 
359  if (chan->num_coded_vals) {
360  vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)];
361 
362  for (i = 0; i < chan->num_coded_vals; i++) {
363  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
364  chan->qu_wordlen[i] = (ref_chan->qu_wordlen[i] + delta) & 7;
365  }
366  }
367  } else {
368  weight_idx = get_bits(gb, 2);
369  if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
370  return ret;
371 
372  if (chan->num_coded_vals) {
373  pos = get_bits(gb, 5);
374  if (pos > chan->num_coded_vals) {
375  av_log(avctx, AV_LOG_ERROR,
376  "WL mode 1: invalid position!\n");
377  return AVERROR_INVALIDDATA;
378  }
379 
380  delta_bits = get_bits(gb, 2);
381  min_val = get_bits(gb, 3);
382 
383  for (i = 0; i < pos; i++)
384  chan->qu_wordlen[i] = get_bits(gb, 3);
385 
386  for (i = pos; i < chan->num_coded_vals; i++)
387  chan->qu_wordlen[i] = (min_val + GET_DELTA(gb, delta_bits)) & 7;
388  }
389  }
390  break;
391  case 2:
392  if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
393  return ret;
394 
395  if (ch_num && chan->num_coded_vals) {
396  vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)];
397  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
398  chan->qu_wordlen[0] = (ref_chan->qu_wordlen[0] + delta) & 7;
399 
400  for (i = 1; i < chan->num_coded_vals; i++) {
401  diff = ref_chan->qu_wordlen[i] - ref_chan->qu_wordlen[i - 1];
402  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
403  chan->qu_wordlen[i] = (chan->qu_wordlen[i - 1] + diff + delta) & 7;
404  }
405  } else if (chan->num_coded_vals) {
406  flag = get_bits(gb, 1);
407  vlc_tab = &wl_vlc_tabs[get_bits(gb, 1)];
408 
409  start_val = get_bits(gb, 3);
410  unpack_vq_shape(start_val,
411  &atrac3p_wl_shapes[start_val][get_bits(gb, 4)][0],
412  chan->qu_wordlen, chan->num_coded_vals);
413 
414  if (!flag) {
415  for (i = 0; i < chan->num_coded_vals; i++) {
416  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
417  chan->qu_wordlen[i] = (chan->qu_wordlen[i] + delta) & 7;
418  }
419  } else {
420  for (i = 0; i < (chan->num_coded_vals & - 2); i += 2)
421  if (!get_bits1(gb)) {
422  chan->qu_wordlen[i] = (chan->qu_wordlen[i] +
423  get_vlc2(gb, vlc_tab->table,
424  vlc_tab->bits, 1)) & 7;
425  chan->qu_wordlen[i + 1] = (chan->qu_wordlen[i + 1] +
426  get_vlc2(gb, vlc_tab->table,
427  vlc_tab->bits, 1)) & 7;
428  }
429 
430  if (chan->num_coded_vals & 1)
431  chan->qu_wordlen[i] = (chan->qu_wordlen[i] +
432  get_vlc2(gb, vlc_tab->table,
433  vlc_tab->bits, 1)) & 7;
434  }
435  }
436  break;
437  case 3:
438  weight_idx = get_bits(gb, 2);
439  if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
440  return ret;
441 
442  if (chan->num_coded_vals) {
443  vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)];
444 
445  /* first coefficient is coded directly */
446  chan->qu_wordlen[0] = get_bits(gb, 3);
447 
448  for (i = 1; i < chan->num_coded_vals; i++) {
449  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
450  chan->qu_wordlen[i] = (chan->qu_wordlen[i - 1] + delta) & 7;
451  }
452  }
453  break;
454  }
455 
456  if (chan->fill_mode == 2) {
457  for (i = chan->num_coded_vals; i < ctx->num_quant_units; i++)
458  chan->qu_wordlen[i] = ch_num ? get_bits1(gb) : 1;
459  } else if (chan->fill_mode == 3) {
460  pos = ch_num ? chan->num_coded_vals + chan->split_point
461  : ctx->num_quant_units - chan->split_point;
462  if (pos > FF_ARRAY_ELEMS(chan->qu_wordlen)) {
463  av_log(avctx, AV_LOG_ERROR, "Split point beyond array\n");
464  pos = FF_ARRAY_ELEMS(chan->qu_wordlen);
465  }
466  for (i = chan->num_coded_vals; i < pos; i++)
467  chan->qu_wordlen[i] = 1;
468  }
469 
470  if (weight_idx)
471  return add_wordlen_weights(ctx, chan, weight_idx, avctx);
472 
473  return 0;
474 }
475 
476 /**
477  * Decode scale factor indexes for each quant unit of a channel.
478  *
479  * @param[in] gb the GetBit context
480  * @param[in,out] ctx ptr to the channel unit context
481  * @param[in] ch_num channel to process
482  * @param[in] avctx ptr to the AVCodecContext
483  * @return result code: 0 = OK, otherwise - error code
484  */
486  int ch_num, AVCodecContext *avctx)
487 {
488  int i, weight_idx = 0, delta, diff, num_long_vals,
489  delta_bits, min_val, vlc_sel, start_val;
490  VLC *vlc_tab;
491  Atrac3pChanParams *chan = &ctx->channels[ch_num];
492  Atrac3pChanParams *ref_chan = &ctx->channels[0];
493 
494  switch (get_bits(gb, 2)) { /* switch according to coding mode */
495  case 0: /* coded using constant number of bits */
496  for (i = 0; i < ctx->used_quant_units; i++)
497  chan->qu_sf_idx[i] = get_bits(gb, 6);
498  break;
499  case 1:
500  if (ch_num) {
501  vlc_tab = &sf_vlc_tabs[get_bits(gb, 2)];
502 
503  for (i = 0; i < ctx->used_quant_units; i++) {
504  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
505  chan->qu_sf_idx[i] = (ref_chan->qu_sf_idx[i] + delta) & 0x3F;
506  }
507  } else {
508  weight_idx = get_bits(gb, 2);
509  if (weight_idx == 3) {
511 
512  num_long_vals = get_bits(gb, 5);
513  delta_bits = get_bits(gb, 2);
514  min_val = get_bits(gb, 4) - 7;
515 
516  for (i = 0; i < num_long_vals; i++)
517  chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] +
518  get_bits(gb, 4) - 7) & 0x3F;
519 
520  /* all others are: min_val + delta */
521  for (i = num_long_vals; i < ctx->used_quant_units; i++)
522  chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] + min_val +
523  GET_DELTA(gb, delta_bits)) & 0x3F;
524  } else {
525  num_long_vals = get_bits(gb, 5);
526  delta_bits = get_bits(gb, 3);
527  min_val = get_bits(gb, 6);
528  if (num_long_vals > ctx->used_quant_units || delta_bits == 7) {
529  av_log(avctx, AV_LOG_ERROR,
530  "SF mode 1: invalid parameters!\n");
531  return AVERROR_INVALIDDATA;
532  }
533 
534  /* read full-precision SF indexes */
535  for (i = 0; i < num_long_vals; i++)
536  chan->qu_sf_idx[i] = get_bits(gb, 6);
537 
538  /* all others are: min_val + delta */
539  for (i = num_long_vals; i < ctx->used_quant_units; i++)
540  chan->qu_sf_idx[i] = (min_val +
541  GET_DELTA(gb, delta_bits)) & 0x3F;
542  }
543  }
544  break;
545  case 2:
546  if (ch_num) {
547  vlc_tab = &sf_vlc_tabs[get_bits(gb, 2)];
548 
549  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
550  chan->qu_sf_idx[0] = (ref_chan->qu_sf_idx[0] + delta) & 0x3F;
551 
552  for (i = 1; i < ctx->used_quant_units; i++) {
553  diff = ref_chan->qu_sf_idx[i] - ref_chan->qu_sf_idx[i - 1];
554  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
555  chan->qu_sf_idx[i] = (chan->qu_sf_idx[i - 1] + diff + delta) & 0x3F;
556  }
557  } else {
558  vlc_tab = &sf_vlc_tabs[get_bits(gb, 2) + 4];
559 
561 
562  for (i = 0; i < ctx->used_quant_units; i++) {
563  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
564  chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] +
565  sign_extend(delta, 4)) & 0x3F;
566  }
567  }
568  break;
569  case 3:
570  if (ch_num) {
571  /* copy coefficients from reference channel */
572  for (i = 0; i < ctx->used_quant_units; i++)
573  chan->qu_sf_idx[i] = ref_chan->qu_sf_idx[i];
574  } else {
575  weight_idx = get_bits(gb, 2);
576  vlc_sel = get_bits(gb, 2);
577  vlc_tab = &sf_vlc_tabs[vlc_sel];
578 
579  if (weight_idx == 3) {
580  vlc_tab = &sf_vlc_tabs[vlc_sel + 4];
581 
583 
584  diff = (get_bits(gb, 4) + 56) & 0x3F;
585  chan->qu_sf_idx[0] = (chan->qu_sf_idx[0] + diff) & 0x3F;
586 
587  for (i = 1; i < ctx->used_quant_units; i++) {
588  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
589  diff = (diff + sign_extend(delta, 4)) & 0x3F;
590  chan->qu_sf_idx[i] = (diff + chan->qu_sf_idx[i]) & 0x3F;
591  }
592  } else {
593  /* 1st coefficient is coded directly */
594  chan->qu_sf_idx[0] = get_bits(gb, 6);
595 
596  for (i = 1; i < ctx->used_quant_units; i++) {
597  delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
598  chan->qu_sf_idx[i] = (chan->qu_sf_idx[i - 1] + delta) & 0x3F;
599  }
600  }
601  }
602  break;
603  }
604 
605  if (weight_idx && weight_idx < 3)
606  return subtract_sf_weights(ctx, chan, weight_idx, avctx);
607 
608  return 0;
609 }
610 
611 /**
612  * Decode word length information for each channel.
613  *
614  * @param[in] gb the GetBit context
615  * @param[in,out] ctx ptr to the channel unit context
616  * @param[in] num_channels number of channels to process
617  * @param[in] avctx ptr to the AVCodecContext
618  * @return result code: 0 = OK, otherwise - error code
619  */
621  int num_channels, AVCodecContext *avctx)
622 {
623  int ch_num, i, ret;
624 
625  for (ch_num = 0; ch_num < num_channels; ch_num++) {
626  memset(ctx->channels[ch_num].qu_wordlen, 0,
627  sizeof(ctx->channels[ch_num].qu_wordlen));
628 
629  if ((ret = decode_channel_wordlen(gb, ctx, ch_num, avctx)) < 0)
630  return ret;
631  }
632 
633  /* scan for last non-zero coeff in both channels and
634  * set number of quant units having coded spectrum */
635  for (i = ctx->num_quant_units - 1; i >= 0; i--)
636  if (ctx->channels[0].qu_wordlen[i] ||
637  (num_channels == 2 && ctx->channels[1].qu_wordlen[i]))
638  break;
639  ctx->used_quant_units = i + 1;
640 
641  return 0;
642 }
643 
644 /**
645  * Decode scale factor indexes for each channel.
646  *
647  * @param[in] gb the GetBit context
648  * @param[in,out] ctx ptr to the channel unit context
649  * @param[in] num_channels number of channels to process
650  * @param[in] avctx ptr to the AVCodecContext
651  * @return result code: 0 = OK, otherwise - error code
652  */
654  int num_channels, AVCodecContext *avctx)
655 {
656  int ch_num, ret;
657 
658  if (!ctx->used_quant_units)
659  return 0;
660 
661  for (ch_num = 0; ch_num < num_channels; ch_num++) {
662  memset(ctx->channels[ch_num].qu_sf_idx, 0,
663  sizeof(ctx->channels[ch_num].qu_sf_idx));
664 
665  if ((ret = decode_channel_sf_idx(gb, ctx, ch_num, avctx)) < 0)
666  return ret;
667  }
668 
669  return 0;
670 }
671 
672 /**
673  * Decode number of code table values.
674  *
675  * @param[in] gb the GetBit context
676  * @param[in,out] ctx ptr to the channel unit context
677  * @param[in] avctx ptr to the AVCodecContext
678  * @return result code: 0 = OK, otherwise - error code
679  */
681  AVCodecContext *avctx)
682 {
683  int num_coded_vals;
684 
685  if (get_bits1(gb)) {
686  num_coded_vals = get_bits(gb, 5);
687  if (num_coded_vals > ctx->used_quant_units) {
688  av_log(avctx, AV_LOG_ERROR,
689  "Invalid number of code table indexes: %d!\n", num_coded_vals);
690  return AVERROR_INVALIDDATA;
691  }
692  return num_coded_vals;
693  } else
694  return ctx->used_quant_units;
695 }
696 
697 #define DEC_CT_IDX_COMMON(OP) \
698  num_vals = get_num_ct_values(gb, ctx, avctx); \
699  if (num_vals < 0) \
700  return num_vals; \
701  \
702  for (i = 0; i < num_vals; i++) { \
703  if (chan->qu_wordlen[i]) { \
704  chan->qu_tab_idx[i] = OP; \
705  } else if (ch_num && ref_chan->qu_wordlen[i]) \
706  /* get clone master flag */ \
707  chan->qu_tab_idx[i] = get_bits1(gb); \
708  }
709 
710 #define CODING_DIRECT get_bits(gb, num_bits)
711 
712 #define CODING_VLC get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)
713 
714 #define CODING_VLC_DELTA \
715  (!i) ? CODING_VLC \
716  : (pred + get_vlc2(gb, delta_vlc->table, \
717  delta_vlc->bits, 1)) & mask; \
718  pred = chan->qu_tab_idx[i]
719 
720 #define CODING_VLC_DIFF \
721  (ref_chan->qu_tab_idx[i] + \
722  get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)) & mask
723 
724 /**
725  * Decode code table indexes for each quant unit of a channel.
726  *
727  * @param[in] gb the GetBit context
728  * @param[in,out] ctx ptr to the channel unit context
729  * @param[in] ch_num channel to process
730  * @param[in] avctx ptr to the AVCodecContext
731  * @return result code: 0 = OK, otherwise - error code
732  */
734  int ch_num, AVCodecContext *avctx)
735 {
736  int i, num_vals, num_bits, pred;
737  int mask = ctx->use_full_table ? 7 : 3; /* mask for modular arithmetic */
738  VLC *vlc_tab, *delta_vlc;
739  Atrac3pChanParams *chan = &ctx->channels[ch_num];
740  Atrac3pChanParams *ref_chan = &ctx->channels[0];
741 
742  chan->table_type = get_bits1(gb);
743 
744  switch (get_bits(gb, 2)) { /* switch according to coding mode */
745  case 0: /* directly coded */
746  num_bits = ctx->use_full_table + 2;
748  break;
749  case 1: /* entropy-coded */
750  vlc_tab = ctx->use_full_table ? &ct_vlc_tabs[1]
751  : ct_vlc_tabs;
753  break;
754  case 2: /* entropy-coded delta */
755  if (ctx->use_full_table) {
756  vlc_tab = &ct_vlc_tabs[1];
757  delta_vlc = &ct_vlc_tabs[2];
758  } else {
759  vlc_tab = ct_vlc_tabs;
760  delta_vlc = ct_vlc_tabs;
761  }
762  pred = 0;
764  break;
765  case 3: /* entropy-coded difference to master */
766  if (ch_num) {
767  vlc_tab = ctx->use_full_table ? &ct_vlc_tabs[3]
768  : ct_vlc_tabs;
770  }
771  break;
772  }
773 
774  return 0;
775 }
776 
777 /**
778  * Decode code table indexes for each channel.
779  *
780  * @param[in] gb the GetBit context
781  * @param[in,out] ctx ptr to the channel unit context
782  * @param[in] num_channels number of channels to process
783  * @param[in] avctx ptr to the AVCodecContext
784  * @return result code: 0 = OK, otherwise - error code
785  */
787  int num_channels, AVCodecContext *avctx)
788 {
789  int ch_num, ret;
790 
791  if (!ctx->used_quant_units)
792  return 0;
793 
794  ctx->use_full_table = get_bits1(gb);
795 
796  for (ch_num = 0; ch_num < num_channels; ch_num++) {
797  memset(ctx->channels[ch_num].qu_tab_idx, 0,
798  sizeof(ctx->channels[ch_num].qu_tab_idx));
799 
800  if ((ret = decode_channel_code_tab(gb, ctx, ch_num, avctx)) < 0)
801  return ret;
802  }
803 
804  return 0;
805 }
806 
807 /**
808  * Decode huffman-coded spectral lines for a given quant unit.
809  *
810  * This is a generalized version for all known coding modes.
811  * Its speed can be improved by creating separate functions for each mode.
812  *
813  * @param[in] gb the GetBit context
814  * @param[in] tab code table telling how to decode spectral lines
815  * @param[in] vlc_tab ptr to the huffman table associated with the code table
816  * @param[out] out pointer to buffer where decoded data should be stored
817  * @param[in] num_specs number of spectral lines to decode
818  */
820  VLC *vlc_tab, int16_t *out, const int num_specs)
821 {
822  int i, j, pos, cf;
823  int group_size = tab->group_size;
824  int num_coeffs = tab->num_coeffs;
825  int bits = tab->bits;
826  int is_signed = tab->is_signed;
827  unsigned val;
828 
829  for (pos = 0; pos < num_specs;) {
830  if (group_size == 1 || get_bits1(gb)) {
831  for (j = 0; j < group_size; j++) {
832  val = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
833 
834  for (i = 0; i < num_coeffs; i++) {
835  cf = av_mod_uintp2(val, bits);
836  if (is_signed)
837  cf = sign_extend(cf, bits);
838  else if (cf && get_bits1(gb))
839  cf = -cf;
840 
841  out[pos++] = cf;
842  val >>= bits;
843  }
844  }
845  } else /* group skipped */
846  pos += group_size * num_coeffs;
847  }
848 }
849 
850 /**
851  * Decode huffman-coded IMDCT spectrum for all channels.
852  *
853  * @param[in] gb the GetBit context
854  * @param[in,out] ctx ptr to the channel unit context
855  * @param[in] num_channels number of channels to process
856  * @param[in] avctx ptr to the AVCodecContext
857  */
859  int num_channels, AVCodecContext *avctx)
860 {
861  int i, ch_num, qu, wordlen, codetab, tab_index, num_specs;
862  const Atrac3pSpecCodeTab *tab;
863  Atrac3pChanParams *chan;
864 
865  for (ch_num = 0; ch_num < num_channels; ch_num++) {
866  chan = &ctx->channels[ch_num];
867 
868  memset(chan->spectrum, 0, sizeof(chan->spectrum));
869 
870  /* set power compensation level to disabled */
871  memset(chan->power_levs, ATRAC3P_POWER_COMP_OFF, sizeof(chan->power_levs));
872 
873  for (qu = 0; qu < ctx->used_quant_units; qu++) {
874  num_specs = ff_atrac3p_qu_to_spec_pos[qu + 1] -
876 
877  wordlen = chan->qu_wordlen[qu];
878  codetab = chan->qu_tab_idx[qu];
879  if (wordlen) {
880  if (!ctx->use_full_table)
881  codetab = atrac3p_ct_restricted_to_full[chan->table_type][wordlen - 1][codetab];
882 
883  tab_index = (chan->table_type * 8 + codetab) * 7 + wordlen - 1;
884  tab = &atrac3p_spectra_tabs[tab_index];
885 
886  /* this allows reusing VLC tables */
887  if (tab->redirect >= 0)
888  tab_index = tab->redirect;
889 
890  decode_qu_spectra(gb, tab, &spec_vlc_tabs[tab_index],
891  &chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
892  num_specs);
893  } else if (ch_num && ctx->channels[0].qu_wordlen[qu] && !codetab) {
894  /* copy coefficients from master */
895  memcpy(&chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
896  &ctx->channels[0].spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
897  num_specs *
898  sizeof(chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]]));
899  chan->qu_wordlen[qu] = ctx->channels[0].qu_wordlen[qu];
900  }
901  }
902 
903  /* Power compensation levels only present in the bitstream
904  * if there are more than 2 quant units. The lowest two units
905  * correspond to the frequencies 0...351 Hz, whose shouldn't
906  * be affected by the power compensation. */
907  if (ctx->used_quant_units > 2) {
909  for (i = 0; i < num_specs; i++)
910  chan->power_levs[i] = get_bits(gb, 4);
911  }
912  }
913 }
914 
915 /**
916  * Retrieve specified amount of flag bits from the input bitstream.
917  * The data can be shortened in the case of the following two common conditions:
918  * if all bits are zero then only one signal bit = 0 will be stored,
919  * if all bits are ones then two signal bits = 1,0 will be stored.
920  * Otherwise, all necessary bits will be directly stored
921  * prefixed by two signal bits = 1,1.
922  *
923  * @param[in] gb ptr to the GetBitContext
924  * @param[out] out where to place decoded flags
925  * @param[in] num_flags number of flags to process
926  * @return: 0 = all flag bits are zero, 1 = there is at least one non-zero flag bit
927  */
928 static int get_subband_flags(GetBitContext *gb, uint8_t *out, int num_flags)
929 {
930  int i, result;
931 
932  memset(out, 0, num_flags);
933 
934  result = get_bits1(gb);
935  if (result) {
936  if (get_bits1(gb))
937  for (i = 0; i < num_flags; i++)
938  out[i] = get_bits1(gb);
939  else
940  memset(out, 1, num_flags);
941  }
942 
943  return result;
944 }
945 
946 /**
947  * Decode mdct window shape flags for all channels.
948  *
949  * @param[in] gb the GetBit context
950  * @param[in,out] ctx ptr to the channel unit context
951  * @param[in] num_channels number of channels to process
952  */
954  int num_channels)
955 {
956  int ch_num;
957 
958  for (ch_num = 0; ch_num < num_channels; ch_num++)
959  get_subband_flags(gb, ctx->channels[ch_num].wnd_shape,
960  ctx->num_subbands);
961 }
962 
963 /**
964  * Decode number of gain control points.
965  *
966  * @param[in] gb the GetBit context
967  * @param[in,out] ctx ptr to the channel unit context
968  * @param[in] ch_num channel to process
969  * @param[in] coded_subbands number of subbands to process
970  * @return result code: 0 = OK, otherwise - error code
971  */
973  int ch_num, int coded_subbands)
974 {
975  int i, delta, delta_bits, min_val;
976  Atrac3pChanParams *chan = &ctx->channels[ch_num];
977  Atrac3pChanParams *ref_chan = &ctx->channels[0];
978 
979  switch (get_bits(gb, 2)) { /* switch according to coding mode */
980  case 0: /* fixed-length coding */
981  for (i = 0; i < coded_subbands; i++)
982  chan->gain_data[i].num_points = get_bits(gb, 3);
983  break;
984  case 1: /* variable-length coding */
985  for (i = 0; i < coded_subbands; i++)
986  chan->gain_data[i].num_points =
987  get_vlc2(gb, gain_vlc_tabs[0].table,
988  gain_vlc_tabs[0].bits, 1);
989  break;
990  case 2:
991  if (ch_num) { /* VLC modulo delta to master channel */
992  for (i = 0; i < coded_subbands; i++) {
993  delta = get_vlc2(gb, gain_vlc_tabs[1].table,
994  gain_vlc_tabs[1].bits, 1);
995  chan->gain_data[i].num_points =
996  (ref_chan->gain_data[i].num_points + delta) & 7;
997  }
998  } else { /* VLC modulo delta to previous */
999  chan->gain_data[0].num_points =
1000  get_vlc2(gb, gain_vlc_tabs[0].table,
1001  gain_vlc_tabs[0].bits, 1);
1002 
1003  for (i = 1; i < coded_subbands; i++) {
1004  delta = get_vlc2(gb, gain_vlc_tabs[1].table,
1005  gain_vlc_tabs[1].bits, 1);
1006  chan->gain_data[i].num_points =
1007  (chan->gain_data[i - 1].num_points + delta) & 7;
1008  }
1009  }
1010  break;
1011  case 3:
1012  if (ch_num) { /* copy data from master channel */
1013  for (i = 0; i < coded_subbands; i++)
1014  chan->gain_data[i].num_points =
1015  ref_chan->gain_data[i].num_points;
1016  } else { /* shorter delta to min */
1017  delta_bits = get_bits(gb, 2);
1018  min_val = get_bits(gb, 3);
1019 
1020  for (i = 0; i < coded_subbands; i++) {
1021  chan->gain_data[i].num_points = min_val + GET_DELTA(gb, delta_bits);
1022  if (chan->gain_data[i].num_points > 7)
1023  return AVERROR_INVALIDDATA;
1024  }
1025  }
1026  }
1027 
1028  return 0;
1029 }
1030 
1031 /**
1032  * Implements coding mode 3 (slave) for gain compensation levels.
1033  *
1034  * @param[out] dst ptr to the output array
1035  * @param[in] ref ptr to the reference channel
1036  */
1037 static inline void gainc_level_mode3s(AtracGainInfo *dst, AtracGainInfo *ref)
1038 {
1039  int i;
1040 
1041  for (i = 0; i < dst->num_points; i++)
1042  dst->lev_code[i] = (i >= ref->num_points) ? 7 : ref->lev_code[i];
1043 }
1044 
1045 /**
1046  * Implements coding mode 1 (master) for gain compensation levels.
1047  *
1048  * @param[in] gb the GetBit context
1049  * @param[in] ctx ptr to the channel unit context
1050  * @param[out] dst ptr to the output array
1051  */
1052 static inline void gainc_level_mode1m(GetBitContext *gb,
1053  Atrac3pChanUnitCtx *ctx,
1054  AtracGainInfo *dst)
1055 {
1056  int i, delta;
1057 
1058  if (dst->num_points > 0)
1059  dst->lev_code[0] = get_vlc2(gb, gain_vlc_tabs[2].table,
1060  gain_vlc_tabs[2].bits, 1);
1061 
1062  for (i = 1; i < dst->num_points; i++) {
1063  delta = get_vlc2(gb, gain_vlc_tabs[3].table,
1064  gain_vlc_tabs[3].bits, 1);
1065  dst->lev_code[i] = (dst->lev_code[i - 1] + delta) & 0xF;
1066  }
1067 }
1068 
1069 /**
1070  * Decode level code for each gain control point.
1071  *
1072  * @param[in] gb the GetBit context
1073  * @param[in,out] ctx ptr to the channel unit context
1074  * @param[in] ch_num channel to process
1075  * @param[in] coded_subbands number of subbands to process
1076  * @return result code: 0 = OK, otherwise - error code
1077  */
1079  int ch_num, int coded_subbands)
1080 {
1081  int sb, i, delta, delta_bits, min_val, pred;
1082  Atrac3pChanParams *chan = &ctx->channels[ch_num];
1083  Atrac3pChanParams *ref_chan = &ctx->channels[0];
1084 
1085  switch (get_bits(gb, 2)) { /* switch according to coding mode */
1086  case 0: /* fixed-length coding */
1087  for (sb = 0; sb < coded_subbands; sb++)
1088  for (i = 0; i < chan->gain_data[sb].num_points; i++)
1089  chan->gain_data[sb].lev_code[i] = get_bits(gb, 4);
1090  break;
1091  case 1:
1092  if (ch_num) { /* VLC modulo delta to master channel */
1093  for (sb = 0; sb < coded_subbands; sb++)
1094  for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1095  delta = get_vlc2(gb, gain_vlc_tabs[5].table,
1096  gain_vlc_tabs[5].bits, 1);
1097  pred = (i >= ref_chan->gain_data[sb].num_points)
1098  ? 7 : ref_chan->gain_data[sb].lev_code[i];
1099  chan->gain_data[sb].lev_code[i] = (pred + delta) & 0xF;
1100  }
1101  } else { /* VLC modulo delta to previous */
1102  for (sb = 0; sb < coded_subbands; sb++)
1103  gainc_level_mode1m(gb, ctx, &chan->gain_data[sb]);
1104  }
1105  break;
1106  case 2:
1107  if (ch_num) { /* VLC modulo delta to previous or clone master */
1108  for (sb = 0; sb < coded_subbands; sb++)
1109  if (chan->gain_data[sb].num_points > 0) {
1110  if (get_bits1(gb))
1111  gainc_level_mode1m(gb, ctx, &chan->gain_data[sb]);
1112  else
1113  gainc_level_mode3s(&chan->gain_data[sb],
1114  &ref_chan->gain_data[sb]);
1115  }
1116  } else { /* VLC modulo delta to lev_codes of previous subband */
1117  if (chan->gain_data[0].num_points > 0)
1118  gainc_level_mode1m(gb, ctx, &chan->gain_data[0]);
1119 
1120  for (sb = 1; sb < coded_subbands; sb++)
1121  for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1122  delta = get_vlc2(gb, gain_vlc_tabs[4].table,
1123  gain_vlc_tabs[4].bits, 1);
1124  pred = (i >= chan->gain_data[sb - 1].num_points)
1125  ? 7 : chan->gain_data[sb - 1].lev_code[i];
1126  chan->gain_data[sb].lev_code[i] = (pred + delta) & 0xF;
1127  }
1128  }
1129  break;
1130  case 3:
1131  if (ch_num) { /* clone master */
1132  for (sb = 0; sb < coded_subbands; sb++)
1133  gainc_level_mode3s(&chan->gain_data[sb],
1134  &ref_chan->gain_data[sb]);
1135  } else { /* shorter delta to min */
1136  delta_bits = get_bits(gb, 2);
1137  min_val = get_bits(gb, 4);
1138 
1139  for (sb = 0; sb < coded_subbands; sb++)
1140  for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1141  chan->gain_data[sb].lev_code[i] = min_val + GET_DELTA(gb, delta_bits);
1142  if (chan->gain_data[sb].lev_code[i] > 15)
1143  return AVERROR_INVALIDDATA;
1144  }
1145  }
1146  break;
1147  }
1148 
1149  return 0;
1150 }
1151 
1152 /**
1153  * Implements coding mode 0 for gain compensation locations.
1154  *
1155  * @param[in] gb the GetBit context
1156  * @param[in] ctx ptr to the channel unit context
1157  * @param[out] dst ptr to the output array
1158  * @param[in] pos position of the value to be processed
1159  */
1160 static inline void gainc_loc_mode0(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1161  AtracGainInfo *dst, int pos)
1162 {
1163  int delta_bits;
1164 
1165  if (!pos || dst->loc_code[pos - 1] < 15)
1166  dst->loc_code[pos] = get_bits(gb, 5);
1167  else if (dst->loc_code[pos - 1] >= 30)
1168  dst->loc_code[pos] = 31;
1169  else {
1170  delta_bits = av_log2(30 - dst->loc_code[pos - 1]) + 1;
1171  dst->loc_code[pos] = dst->loc_code[pos - 1] +
1172  get_bits(gb, delta_bits) + 1;
1173  }
1174 }
1175 
1176 /**
1177  * Implements coding mode 1 for gain compensation locations.
1178  *
1179  * @param[in] gb the GetBit context
1180  * @param[in] ctx ptr to the channel unit context
1181  * @param[out] dst ptr to the output array
1182  */
1183 static inline void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1184  AtracGainInfo *dst)
1185 {
1186  int i;
1187  VLC *tab;
1188 
1189  if (dst->num_points > 0) {
1190  /* 1st coefficient is stored directly */
1191  dst->loc_code[0] = get_bits(gb, 5);
1192 
1193  for (i = 1; i < dst->num_points; i++) {
1194  /* switch VLC according to the curve direction
1195  * (ascending/descending) */
1196  tab = (dst->lev_code[i] <= dst->lev_code[i - 1])
1197  ? &gain_vlc_tabs[7]
1198  : &gain_vlc_tabs[9];
1199  dst->loc_code[i] = dst->loc_code[i - 1] +
1200  get_vlc2(gb, tab->table, tab->bits, 1);
1201  }
1202  }
1203 }
1204 
1205 /**
1206  * Decode location code for each gain control point.
1207  *
1208  * @param[in] gb the GetBit context
1209  * @param[in,out] ctx ptr to the channel unit context
1210  * @param[in] ch_num channel to process
1211  * @param[in] coded_subbands number of subbands to process
1212  * @param[in] avctx ptr to the AVCodecContext
1213  * @return result code: 0 = OK, otherwise - error code
1214  */
1216  int ch_num, int coded_subbands,
1217  AVCodecContext *avctx)
1218 {
1219  int sb, i, delta, delta_bits, min_val, pred, more_than_ref;
1220  AtracGainInfo *dst, *ref;
1221  VLC *tab;
1222  Atrac3pChanParams *chan = &ctx->channels[ch_num];
1223  Atrac3pChanParams *ref_chan = &ctx->channels[0];
1224 
1225  switch (get_bits(gb, 2)) { /* switch according to coding mode */
1226  case 0: /* sequence of numbers in ascending order */
1227  for (sb = 0; sb < coded_subbands; sb++)
1228  for (i = 0; i < chan->gain_data[sb].num_points; i++)
1229  gainc_loc_mode0(gb, ctx, &chan->gain_data[sb], i);
1230  break;
1231  case 1:
1232  if (ch_num) {
1233  for (sb = 0; sb < coded_subbands; sb++) {
1234  if (chan->gain_data[sb].num_points <= 0)
1235  continue;
1236  dst = &chan->gain_data[sb];
1237  ref = &ref_chan->gain_data[sb];
1238 
1239  /* 1st value is vlc-coded modulo delta to master */
1240  delta = get_vlc2(gb, gain_vlc_tabs[10].table,
1241  gain_vlc_tabs[10].bits, 1);
1242  pred = ref->num_points > 0 ? ref->loc_code[0] : 0;
1243  dst->loc_code[0] = (pred + delta) & 0x1F;
1244 
1245  for (i = 1; i < dst->num_points; i++) {
1246  more_than_ref = i >= ref->num_points;
1247  if (dst->lev_code[i] > dst->lev_code[i - 1]) {
1248  /* ascending curve */
1249  if (more_than_ref) {
1250  delta =
1251  get_vlc2(gb, gain_vlc_tabs[9].table,
1252  gain_vlc_tabs[9].bits, 1);
1253  dst->loc_code[i] = dst->loc_code[i - 1] + delta;
1254  } else {
1255  if (get_bits1(gb))
1256  gainc_loc_mode0(gb, ctx, dst, i); // direct coding
1257  else
1258  dst->loc_code[i] = ref->loc_code[i]; // clone master
1259  }
1260  } else { /* descending curve */
1261  tab = more_than_ref ? &gain_vlc_tabs[7]
1262  : &gain_vlc_tabs[10];
1263  delta = get_vlc2(gb, tab->table, tab->bits, 1);
1264  if (more_than_ref)
1265  dst->loc_code[i] = dst->loc_code[i - 1] + delta;
1266  else
1267  dst->loc_code[i] = (ref->loc_code[i] + delta) & 0x1F;
1268  }
1269  }
1270  }
1271  } else /* VLC delta to previous */
1272  for (sb = 0; sb < coded_subbands; sb++)
1273  gainc_loc_mode1(gb, ctx, &chan->gain_data[sb]);
1274  break;
1275  case 2:
1276  if (ch_num) {
1277  for (sb = 0; sb < coded_subbands; sb++) {
1278  if (chan->gain_data[sb].num_points <= 0)
1279  continue;
1280  dst = &chan->gain_data[sb];
1281  ref = &ref_chan->gain_data[sb];
1282  if (dst->num_points > ref->num_points || get_bits1(gb))
1283  gainc_loc_mode1(gb, ctx, dst);
1284  else /* clone master for the whole subband */
1285  for (i = 0; i < chan->gain_data[sb].num_points; i++)
1286  dst->loc_code[i] = ref->loc_code[i];
1287  }
1288  } else {
1289  /* data for the first subband is coded directly */
1290  for (i = 0; i < chan->gain_data[0].num_points; i++)
1291  gainc_loc_mode0(gb, ctx, &chan->gain_data[0], i);
1292 
1293  for (sb = 1; sb < coded_subbands; sb++) {
1294  if (chan->gain_data[sb].num_points <= 0)
1295  continue;
1296  dst = &chan->gain_data[sb];
1297 
1298  /* 1st value is vlc-coded modulo delta to the corresponding
1299  * value of the previous subband if any or zero */
1300  delta = get_vlc2(gb, gain_vlc_tabs[6].table,
1301  gain_vlc_tabs[6].bits, 1);
1302  pred = dst[-1].num_points > 0
1303  ? dst[-1].loc_code[0] : 0;
1304  dst->loc_code[0] = (pred + delta) & 0x1F;
1305 
1306  for (i = 1; i < dst->num_points; i++) {
1307  more_than_ref = i >= dst[-1].num_points;
1308  /* Select VLC table according to curve direction and
1309  * presence of prediction. */
1310  tab = &gain_vlc_tabs[(dst->lev_code[i] > dst->lev_code[i - 1]) *
1311  2 + more_than_ref + 6];
1312  delta = get_vlc2(gb, tab->table, tab->bits, 1);
1313  if (more_than_ref)
1314  dst->loc_code[i] = dst->loc_code[i - 1] + delta;
1315  else
1316  dst->loc_code[i] = (dst[-1].loc_code[i] + delta) & 0x1F;
1317  }
1318  }
1319  }
1320  break;
1321  case 3:
1322  if (ch_num) { /* clone master or direct or direct coding */
1323  for (sb = 0; sb < coded_subbands; sb++)
1324  for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1325  if (i >= ref_chan->gain_data[sb].num_points)
1326  gainc_loc_mode0(gb, ctx, &chan->gain_data[sb], i);
1327  else
1328  chan->gain_data[sb].loc_code[i] =
1329  ref_chan->gain_data[sb].loc_code[i];
1330  }
1331  } else { /* shorter delta to min */
1332  delta_bits = get_bits(gb, 2) + 1;
1333  min_val = get_bits(gb, 5);
1334 
1335  for (sb = 0; sb < coded_subbands; sb++)
1336  for (i = 0; i < chan->gain_data[sb].num_points; i++)
1337  chan->gain_data[sb].loc_code[i] = min_val + i +
1338  get_bits(gb, delta_bits);
1339  }
1340  break;
1341  }
1342 
1343  /* Validate decoded information */
1344  for (sb = 0; sb < coded_subbands; sb++) {
1345  dst = &chan->gain_data[sb];
1346  for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1347  if (dst->loc_code[i] < 0 || dst->loc_code[i] > 31 ||
1348  (i && dst->loc_code[i] <= dst->loc_code[i - 1])) {
1349  av_log(avctx, AV_LOG_ERROR,
1350  "Invalid gain location: ch=%d, sb=%d, pos=%d, val=%d\n",
1351  ch_num, sb, i, dst->loc_code[i]);
1352  return AVERROR_INVALIDDATA;
1353  }
1354  }
1355  }
1356 
1357  return 0;
1358 }
1359 
1360 /**
1361  * Decode gain control data for all channels.
1362  *
1363  * @param[in] gb the GetBit context
1364  * @param[in,out] ctx ptr to the channel unit context
1365  * @param[in] num_channels number of channels to process
1366  * @param[in] avctx ptr to the AVCodecContext
1367  * @return result code: 0 = OK, otherwise - error code
1368  */
1370  int num_channels, AVCodecContext *avctx)
1371 {
1372  int ch_num, coded_subbands, sb, ret;
1373 
1374  for (ch_num = 0; ch_num < num_channels; ch_num++) {
1375  memset(ctx->channels[ch_num].gain_data, 0,
1376  sizeof(*ctx->channels[ch_num].gain_data) * ATRAC3P_SUBBANDS);
1377 
1378  if (get_bits1(gb)) { /* gain control data present? */
1379  coded_subbands = get_bits(gb, 4) + 1;
1380  if (get_bits1(gb)) /* is high band gain data replication on? */
1381  ctx->channels[ch_num].num_gain_subbands = get_bits(gb, 4) + 1;
1382  else
1383  ctx->channels[ch_num].num_gain_subbands = coded_subbands;
1384 
1385  if ((ret = decode_gainc_npoints(gb, ctx, ch_num, coded_subbands)) < 0 ||
1386  (ret = decode_gainc_levels(gb, ctx, ch_num, coded_subbands)) < 0 ||
1387  (ret = decode_gainc_loc_codes(gb, ctx, ch_num, coded_subbands, avctx)) < 0)
1388  return ret;
1389 
1390  if (coded_subbands > 0) { /* propagate gain data if requested */
1391  for (sb = coded_subbands; sb < ctx->channels[ch_num].num_gain_subbands; sb++)
1392  ctx->channels[ch_num].gain_data[sb] =
1393  ctx->channels[ch_num].gain_data[sb - 1];
1394  }
1395  } else {
1396  ctx->channels[ch_num].num_gain_subbands = 0;
1397  }
1398  }
1399 
1400  return 0;
1401 }
1402 
1403 /**
1404  * Decode envelope for all tones of a channel.
1405  *
1406  * @param[in] gb the GetBit context
1407  * @param[in,out] ctx ptr to the channel unit context
1408  * @param[in] ch_num channel to process
1409  * @param[in] band_has_tones ptr to an array of per-band-flags:
1410  * 1 - tone data present
1411  */
1413  int ch_num, int band_has_tones[])
1414 {
1415  int sb;
1416  Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1417  Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1418 
1419  if (!ch_num || !get_bits1(gb)) { /* mode 0: fixed-length coding */
1420  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1421  if (!band_has_tones[sb])
1422  continue;
1423  dst[sb].pend_env.has_start_point = get_bits1(gb);
1424  dst[sb].pend_env.start_pos = dst[sb].pend_env.has_start_point
1425  ? get_bits(gb, 5) : -1;
1426  dst[sb].pend_env.has_stop_point = get_bits1(gb);
1427  dst[sb].pend_env.stop_pos = dst[sb].pend_env.has_stop_point
1428  ? get_bits(gb, 5) : 32;
1429  }
1430  } else { /* mode 1(slave only): copy master */
1431  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1432  if (!band_has_tones[sb])
1433  continue;
1435  dst[sb].pend_env.has_stop_point = ref[sb].pend_env.has_stop_point;
1436  dst[sb].pend_env.start_pos = ref[sb].pend_env.start_pos;
1437  dst[sb].pend_env.stop_pos = ref[sb].pend_env.stop_pos;
1438  }
1439  }
1440 }
1441 
1442 /**
1443  * Decode number of tones for each subband of a channel.
1444  *
1445  * @param[in] gb the GetBit context
1446  * @param[in,out] ctx ptr to the channel unit context
1447  * @param[in] ch_num channel to process
1448  * @param[in] band_has_tones ptr to an array of per-band-flags:
1449  * 1 - tone data present
1450  * @param[in] avctx ptr to the AVCodecContext
1451  * @return result code: 0 = OK, otherwise - error code
1452  */
1454  int ch_num, int band_has_tones[],
1455  AVCodecContext *avctx)
1456 {
1457  int mode, sb, delta;
1458  Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1459  Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1460 
1461  mode = get_bits(gb, ch_num + 1);
1462  switch (mode) {
1463  case 0: /** fixed-length coding */
1464  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1465  if (band_has_tones[sb])
1466  dst[sb].num_wavs = get_bits(gb, 4);
1467  break;
1468  case 1: /** variable-length coding */
1469  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1470  if (band_has_tones[sb])
1471  dst[sb].num_wavs =
1472  get_vlc2(gb, tone_vlc_tabs[1].table,
1473  tone_vlc_tabs[1].bits, 1);
1474  break;
1475  case 2: /** VLC modulo delta to master (slave only) */
1476  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1477  if (band_has_tones[sb]) {
1478  delta = get_vlc2(gb, tone_vlc_tabs[2].table,
1479  tone_vlc_tabs[2].bits, 1);
1480  delta = sign_extend(delta, 3);
1481  dst[sb].num_wavs = (ref[sb].num_wavs + delta) & 0xF;
1482  }
1483  break;
1484  case 3: /** copy master (slave only) */
1485  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1486  if (band_has_tones[sb])
1487  dst[sb].num_wavs = ref[sb].num_wavs;
1488  break;
1489  }
1490 
1491  /** initialize start tone index for each subband */
1492  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1493  if (band_has_tones[sb]) {
1494  if (ctx->waves_info->tones_index + dst[sb].num_wavs > 48) {
1495  av_log(avctx, AV_LOG_ERROR,
1496  "Too many tones: %d (max. 48), frame: %d!\n",
1497  ctx->waves_info->tones_index + dst[sb].num_wavs,
1498  avctx->frame_number);
1499  return AVERROR_INVALIDDATA;
1500  }
1501  dst[sb].start_index = ctx->waves_info->tones_index;
1502  ctx->waves_info->tones_index += dst[sb].num_wavs;
1503  }
1504 
1505  return 0;
1506 }
1507 
1508 /**
1509  * Decode frequency information for each subband of a channel.
1510  *
1511  * @param[in] gb the GetBit context
1512  * @param[in,out] ctx ptr to the channel unit context
1513  * @param[in] ch_num channel to process
1514  * @param[in] band_has_tones ptr to an array of per-band-flags:
1515  * 1 - tone data present
1516  */
1518  int ch_num, int band_has_tones[])
1519 {
1520  int sb, i, direction, nbits, pred, delta;
1521  Atrac3pWaveParam *iwav, *owav;
1522  Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1523  Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1524 
1525  if (!ch_num || !get_bits1(gb)) { /* mode 0: fixed-length coding */
1526  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1527  if (!band_has_tones[sb] || !dst[sb].num_wavs)
1528  continue;
1529  iwav = &ctx->waves_info->waves[dst[sb].start_index];
1530  direction = (dst[sb].num_wavs > 1) ? get_bits1(gb) : 0;
1531  if (direction) { /** packed numbers in descending order */
1532  if (dst[sb].num_wavs)
1533  iwav[dst[sb].num_wavs - 1].freq_index = get_bits(gb, 10);
1534  for (i = dst[sb].num_wavs - 2; i >= 0 ; i--) {
1535  nbits = av_log2(iwav[i+1].freq_index) + 1;
1536  iwav[i].freq_index = get_bits(gb, nbits);
1537  }
1538  } else { /** packed numbers in ascending order */
1539  for (i = 0; i < dst[sb].num_wavs; i++) {
1540  if (!i || iwav[i - 1].freq_index < 512)
1541  iwav[i].freq_index = get_bits(gb, 10);
1542  else {
1543  nbits = av_log2(1023 - iwav[i - 1].freq_index) + 1;
1544  iwav[i].freq_index = get_bits(gb, nbits) +
1545  1024 - (1 << nbits);
1546  }
1547  }
1548  }
1549  }
1550  } else { /* mode 1: VLC modulo delta to master (slave only) */
1551  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1552  if (!band_has_tones[sb] || !dst[sb].num_wavs)
1553  continue;
1554  iwav = &ctx->waves_info->waves[ref[sb].start_index];
1555  owav = &ctx->waves_info->waves[dst[sb].start_index];
1556  for (i = 0; i < dst[sb].num_wavs; i++) {
1557  delta = get_vlc2(gb, tone_vlc_tabs[6].table,
1558  tone_vlc_tabs[6].bits, 1);
1559  delta = sign_extend(delta, 8);
1560  pred = (i < ref[sb].num_wavs) ? iwav[i].freq_index :
1561  (ref[sb].num_wavs ? iwav[ref[sb].num_wavs - 1].freq_index : 0);
1562  owav[i].freq_index = (pred + delta) & 0x3FF;
1563  }
1564  }
1565  }
1566 }
1567 
1568 /**
1569  * Decode amplitude information for each subband of a channel.
1570  *
1571  * @param[in] gb the GetBit context
1572  * @param[in,out] ctx ptr to the channel unit context
1573  * @param[in] ch_num channel to process
1574  * @param[in] band_has_tones ptr to an array of per-band-flags:
1575  * 1 - tone data present
1576  */
1578  int ch_num, int band_has_tones[])
1579 {
1580  int mode, sb, j, i, diff, maxdiff, fi, delta, pred;
1581  Atrac3pWaveParam *wsrc, *wref;
1582  int refwaves[48] = { 0 };
1583  Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1584  Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1585 
1586  if (ch_num) {
1587  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1588  if (!band_has_tones[sb] || !dst[sb].num_wavs)
1589  continue;
1590  wsrc = &ctx->waves_info->waves[dst[sb].start_index];
1591  wref = &ctx->waves_info->waves[ref[sb].start_index];
1592  for (j = 0; j < dst[sb].num_wavs; j++) {
1593  for (i = 0, fi = 0, maxdiff = 1024; i < ref[sb].num_wavs; i++) {
1594  diff = FFABS(wsrc[j].freq_index - wref[i].freq_index);
1595  if (diff < maxdiff) {
1596  maxdiff = diff;
1597  fi = i;
1598  }
1599  }
1600 
1601  if (maxdiff < 8)
1602  refwaves[dst[sb].start_index + j] = fi + ref[sb].start_index;
1603  else if (j < ref[sb].num_wavs)
1604  refwaves[dst[sb].start_index + j] = j + ref[sb].start_index;
1605  else
1606  refwaves[dst[sb].start_index + j] = -1;
1607  }
1608  }
1609  }
1610 
1611  mode = get_bits(gb, ch_num + 1);
1612 
1613  switch (mode) {
1614  case 0: /** fixed-length coding */
1615  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1616  if (!band_has_tones[sb] || !dst[sb].num_wavs)
1617  continue;
1618  if (ctx->waves_info->amplitude_mode)
1619  for (i = 0; i < dst[sb].num_wavs; i++)
1620  ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = get_bits(gb, 6);
1621  else
1622  ctx->waves_info->waves[dst[sb].start_index].amp_sf = get_bits(gb, 6);
1623  }
1624  break;
1625  case 1: /** min + VLC delta */
1626  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1627  if (!band_has_tones[sb] || !dst[sb].num_wavs)
1628  continue;
1629  if (ctx->waves_info->amplitude_mode)
1630  for (i = 0; i < dst[sb].num_wavs; i++)
1631  ctx->waves_info->waves[dst[sb].start_index + i].amp_sf =
1632  get_vlc2(gb, tone_vlc_tabs[3].table,
1633  tone_vlc_tabs[3].bits, 1) + 20;
1634  else
1635  ctx->waves_info->waves[dst[sb].start_index].amp_sf =
1636  get_vlc2(gb, tone_vlc_tabs[4].table,
1637  tone_vlc_tabs[4].bits, 1) + 24;
1638  }
1639  break;
1640  case 2: /** VLC modulo delta to master (slave only) */
1641  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1642  if (!band_has_tones[sb] || !dst[sb].num_wavs)
1643  continue;
1644  for (i = 0; i < dst[sb].num_wavs; i++) {
1645  delta = get_vlc2(gb, tone_vlc_tabs[5].table,
1646  tone_vlc_tabs[5].bits, 1);
1647  delta = sign_extend(delta, 5);
1648  pred = refwaves[dst[sb].start_index + i] >= 0 ?
1649  ctx->waves_info->waves[refwaves[dst[sb].start_index + i]].amp_sf : 34;
1650  ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = (pred + delta) & 0x3F;
1651  }
1652  }
1653  break;
1654  case 3: /** clone master (slave only) */
1655  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1656  if (!band_has_tones[sb])
1657  continue;
1658  for (i = 0; i < dst[sb].num_wavs; i++)
1659  ctx->waves_info->waves[dst[sb].start_index + i].amp_sf =
1660  refwaves[dst[sb].start_index + i] >= 0
1661  ? ctx->waves_info->waves[refwaves[dst[sb].start_index + i]].amp_sf
1662  : 32;
1663  }
1664  break;
1665  }
1666 }
1667 
1668 /**
1669  * Decode phase information for each subband of a channel.
1670  *
1671  * @param[in] gb the GetBit context
1672  * @param[in,out] ctx ptr to the channel unit context
1673  * @param[in] ch_num channel to process
1674  * @param[in] band_has_tones ptr to an array of per-band-flags:
1675  * 1 - tone data present
1676  */
1678  int ch_num, int band_has_tones[])
1679 {
1680  int sb, i;
1681  Atrac3pWaveParam *wparam;
1682  Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1683 
1684  for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1685  if (!band_has_tones[sb])
1686  continue;
1687  wparam = &ctx->waves_info->waves[dst[sb].start_index];
1688  for (i = 0; i < dst[sb].num_wavs; i++)
1689  wparam[i].phase_index = get_bits(gb, 5);
1690  }
1691 }
1692 
1693 /**
1694  * Decode tones info for all channels.
1695  *
1696  * @param[in] gb the GetBit context
1697  * @param[in,out] ctx ptr to the channel unit context
1698  * @param[in] num_channels number of channels to process
1699  * @param[in] avctx ptr to the AVCodecContext
1700  * @return result code: 0 = OK, otherwise - error code
1701  */
1703  int num_channels, AVCodecContext *avctx)
1704 {
1705  int ch_num, i, ret;
1706  int band_has_tones[16];
1707 
1708  for (ch_num = 0; ch_num < num_channels; ch_num++)
1709  memset(ctx->channels[ch_num].tones_info, 0,
1710  sizeof(*ctx->channels[ch_num].tones_info) * ATRAC3P_SUBBANDS);
1711 
1712  ctx->waves_info->tones_present = get_bits1(gb);
1713  if (!ctx->waves_info->tones_present)
1714  return 0;
1715 
1716  memset(ctx->waves_info->waves, 0, sizeof(ctx->waves_info->waves));
1717 
1718  ctx->waves_info->amplitude_mode = get_bits1(gb);
1719  if (!ctx->waves_info->amplitude_mode) {
1720  avpriv_report_missing_feature(avctx, "GHA amplitude mode 0");
1721  return AVERROR_PATCHWELCOME;
1722  }
1723 
1724  ctx->waves_info->num_tone_bands =
1725  get_vlc2(gb, tone_vlc_tabs[0].table,
1726  tone_vlc_tabs[0].bits, 1) + 1;
1727 
1728  if (num_channels == 2) {
1732  }
1733 
1734  ctx->waves_info->tones_index = 0;
1735 
1736  for (ch_num = 0; ch_num < num_channels; ch_num++) {
1737  for (i = 0; i < ctx->waves_info->num_tone_bands; i++)
1738  band_has_tones[i] = !ch_num ? 1 : !ctx->waves_info->tone_sharing[i];
1739 
1740  decode_tones_envelope(gb, ctx, ch_num, band_has_tones);
1741  if ((ret = decode_band_numwavs(gb, ctx, ch_num, band_has_tones,
1742  avctx)) < 0)
1743  return ret;
1744 
1745  decode_tones_frequency(gb, ctx, ch_num, band_has_tones);
1746  decode_tones_amplitude(gb, ctx, ch_num, band_has_tones);
1747  decode_tones_phase(gb, ctx, ch_num, band_has_tones);
1748  }
1749 
1750  if (num_channels == 2) {
1751  for (i = 0; i < ctx->waves_info->num_tone_bands; i++) {
1752  if (ctx->waves_info->tone_sharing[i])
1753  ctx->channels[1].tones_info[i] = ctx->channels[0].tones_info[i];
1754 
1755  if (ctx->waves_info->tone_master[i])
1757  ctx->channels[1].tones_info[i]);
1758  }
1759  }
1760 
1761  return 0;
1762 }
1763 
1765  int num_channels, AVCodecContext *avctx)
1766 {
1767  int ret;
1768 
1769  /* parse sound header */
1770  ctx->num_quant_units = get_bits(gb, 5) + 1;
1771  if (ctx->num_quant_units > 28 && ctx->num_quant_units < 32) {
1772  av_log(avctx, AV_LOG_ERROR,
1773  "Invalid number of quantization units: %d!\n",
1774  ctx->num_quant_units);
1775  return AVERROR_INVALIDDATA;
1776  }
1777 
1778  ctx->mute_flag = get_bits1(gb);
1779 
1780  /* decode various sound parameters */
1781  if ((ret = decode_quant_wordlen(gb, ctx, num_channels, avctx)) < 0)
1782  return ret;
1783 
1784  ctx->num_subbands = atrac3p_qu_to_subband[ctx->num_quant_units - 1] + 1;
1786  ? atrac3p_qu_to_subband[ctx->used_quant_units - 1] + 1
1787  : 0;
1788 
1789  if ((ret = decode_scale_factors(gb, ctx, num_channels, avctx)) < 0)
1790  return ret;
1791 
1792  if ((ret = decode_code_table_indexes(gb, ctx, num_channels, avctx)) < 0)
1793  return ret;
1794 
1795  decode_spectrum(gb, ctx, num_channels, avctx);
1796 
1797  if (num_channels == 2) {
1800  }
1801 
1802  decode_window_shape(gb, ctx, num_channels);
1803 
1804  if ((ret = decode_gainc_data(gb, ctx, num_channels, avctx)) < 0)
1805  return ret;
1806 
1807  if ((ret = decode_tones_info(gb, ctx, num_channels, avctx)) < 0)
1808  return ret;
1809 
1810  /* decode global noise info */
1811  ctx->noise_present = get_bits1(gb);
1812  if (ctx->noise_present) {
1813  ctx->noise_level_index = get_bits(gb, 4);
1814  ctx->noise_table_index = get_bits(gb, 4);
1815  }
1816 
1817  return 0;
1818 }
static void unpack_vq_shape(int start_val, const int8_t *shape_vec, int *dst, int num_values)
Unpack vector quantization tables.
Definition: atrac3plus.c:312
static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t *xlat, int *tab_offset, VLC *out_vlc)
Generate canonical VLC table from given descriptor.
Definition: atrac3plus.c:53
static int get_num_ct_values(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx)
Decode number of code table values.
Definition: atrac3plus.c:680
static const uint8_t atrac3p_ct_huff_bits2[8]
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
#define GET_DELTA(gb, delta_bits)
Definition: atrac3plus.c:42
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static void decode_tones_phase(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[])
Decode phase information for each subband of a channel.
Definition: atrac3plus.c:1677
uint8_t bits
number of bits a single coefficient occupy
Atrac3pWaveParam waves[48]
Definition: atrac3plus.h:127
static const uint8_t atrac3p_huff_gain_loc2_xlat[31]
static const uint8_t atrac3p_huff_freq_cb[13]
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
Definition: atrac3plusdsp.c:41
static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int coded_subbands, AVCodecContext *avctx)
Decode location code for each gain control point.
Definition: atrac3plus.c:1215
uint8_t is_signed
1 - values in that table are signed ones, otherwise - absolute ones
static const uint8_t atrac3p_huff_wav_ampsf2_cb[7]
static const uint8_t atrac3p_ct_huff_code2[8]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
static const Atrac3pSpecCodeTab atrac3p_spectra_tabs[112]
static const uint8_t atrac3p_sf_huff_bits2[64]
static int decode_code_table_indexes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode code table indexes for each channel.
Definition: atrac3plus.c:786
int num_tone_bands
number of PQF bands with tones
Definition: atrac3plus.h:122
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:279
static const uint8_t atrac3p_ct_huff_bits3[8]
int num_coded_subbands
number of subbands with coded spectrum
Definition: atrac3plus.h:137
int table_type
table type: 0 - tone?, 1- noise?
Definition: atrac3plus.h:94
const char * b
Definition: vf_curves.c:109
static const uint8_t atrac3p_huff_gain_loc2_cb[8]
#define VLC_TYPE
Definition: get_bits.h:62
int num_wavs
number of sine waves in the group
Definition: atrac3plus.h:76
static const uint8_t atrac3p_huff_gain_loc1_xlat[31]
int used_quant_units
number of quant units with coded spectrum
Definition: atrac3plus.h:136
static const uint8_t atrac3p_huff_gain_npoints2_xlat[8]
static const uint8_t atrac3p_huff_gain_lev4_cb[11]
int lev_code[7]
level at corresponding control point
Definition: atrac.h:37
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
Definition: atrac3plus.h:144
static const uint8_t atrac3p_ct_huff_xlat1[8]
#define ATRAC3P_SUBBANDS
Global unit sizes.
Definition: atrac3plus.h:40
static const uint8_t atrac3p_wl_huff_code4[8]
#define CODING_VLC_DIFF
Definition: atrac3plus.c:720
static const uint16_t atrac3p_sf_huff_code2[64]
static VLC_TYPE tables_data[154276][2]
Definition: atrac3plus.c:34
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static const uint8_t atrac3p_sf_huff_xlat2[64]
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
static const uint8_t atrac3p_huff_gain_loc4_xlat[32]
uint8_t bits
Definition: crc.c:295
uint8_t
static const uint8_t atrac3p_wl_huff_xlat2[5]
#define av_cold
Definition: attributes.h:74
static const uint8_t atrac3p_huff_wav_ampsf2_xlat[32]
static const uint8_t atrac3p_huff_gain_loc4_cb[5]
static void gainc_level_mode3s(AtracGainInfo *dst, AtracGainInfo *ref)
Implements coding mode 3 (slave) for gain compensation levels.
Definition: atrac3plus.c:1037
int16_t spectrum[2048]
decoded IMDCT spectrum
Definition: atrac3plus.h:98
static const uint8_t atrac3p_wl_huff_bits1[3]
float delta
mode
Definition: f_perms.c:27
static const uint8_t atrac3p_huff_gain_lev1_cb[9]
int stop_pos
stop position expressed in n*4 samples
Definition: atrac3plus.h:69
static void decode_window_shape(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels)
Decode mdct window shape flags for all channels.
Definition: atrac3plus.c:953
static const uint8_t atrac3p_wl_huff_bits3[8]
static int decode_gainc_levels(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int coded_subbands)
Decode level code for each gain control point.
Definition: atrac3plus.c:1078
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode bitstream data of a channel unit.
Definition: atrac3plus.c:1764
uint8_t num_coeffs
1 - map index to a single value, > 1 - map index to a vector of values
Parameters of a single sine wave.
Definition: atrac3plus.h:81
Atrac3pWaveEnvelope pend_env
pending envelope from the previous frame
Definition: atrac3plus.h:74
static const int atrac3p_subband_to_num_powgrps[16]
Map subband number to number of power compensation groups.
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
Definition: atrac3plus.h:96
bitstream reader API header.
static void decode_spectrum(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode huffman-coded IMDCT spectrum for all channels.
Definition: atrac3plus.c:858
int tones_index
total sum of tones in this unit
Definition: atrac3plus.h:126
static const uint8_t atrac3p_huff_gain_lev3_cb[11]
int loc_code[7]
location of gain control points
Definition: atrac.h:38
static const uint8_t atrac3p_sf_huff_bits6[16]
uint8_t invert_phase[ATRAC3P_SUBBANDS]
1 - subband-wise phase inversion
Definition: atrac3plus.h:125
static const uint16_t atrac3p_sf_huff_code1[64]
VLC tables for scale factor indexes.
uint8_t * wnd_shape
IMDCT window shape for current frame.
Definition: atrac3plus.h:103
#define av_log(a,...)
int noise_level_index
global noise level index
Definition: atrac3plus.h:141
int flag
Definition: checkasm.c:76
static const uint8_t atrac3p_qu_to_subband[32]
Map quant unit number to subband number.
AVS_FilterInfo ** fi
Definition: avisynth_c.h:594
static const uint8_t atrac3p_huff_freq_xlat[256]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static const uint16_t mask[17]
Definition: lzw.c:38
static const int8_t atrac3p_sf_weights[2][32]
static void decode_tones_envelope(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[])
Decode envelope for all tones of a channel.
Definition: atrac3plus.c:1412
static const uint8_t atrac3p_ct_huff_code1[4]
VLC tables for code table indexes.
static const uint8_t atrac3p_huff_gain_loc1_cb[9]
static const uint16_t atrac3p_sf_huff_code4[16]
static const struct endianess table[]
static const uint8_t atrac3p_huff_wav_ampsf3_cb[9]
#define CODING_VLC_DELTA
Definition: atrac3plus.c:714
Tables for spectrum coding.
Parameters of a group of sine waves.
Definition: atrac3plus.h:73
static const uint8_t atrac3p_huff_gain_loc3_cb[7]
int noise_table_index
global noise RNG table index
Definition: atrac3plus.h:142
static VLC wl_vlc_tabs[4]
Definition: atrac3plus.c:35
simple assert() macros that are a bit more flexible than ISO C assert().
static VLC tone_vlc_tabs[7]
Definition: atrac3plus.c:40
static const float qu[2]
Definition: sipr16kdata.h:28
Libavcodec external API header.
int qu_wordlen[32]
array of word lengths for each quant unit
Definition: atrac3plus.h:95
static void gainc_level_mode1m(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, AtracGainInfo *dst)
Implements coding mode 1 (master) for gain compensation levels.
Definition: atrac3plus.c:1052
int amplitude_mode
1 - low range, 0 - high range
Definition: atrac3plus.h:121
Definition: get_bits.h:64
static const uint8_t atrac3p_sf_huff_xlat1[64]
#define ATRAC3P_POWER_COMP_OFF
Global constants.
Definition: atrac3plus.h:47
static int decode_band_numwavs(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[], AVCodecContext *avctx)
Decode number of tones for each subband of a channel.
Definition: atrac3plus.c:1453
static int get_subband_flags(GetBitContext *gb, uint8_t *out, int num_flags)
Retrieve specified amount of flag bits from the input bitstream.
Definition: atrac3plus.c:928
static const uint8_t atrac3p_huff_gain_npoints1_cb[9]
static int decode_quant_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode word length information for each channel.
Definition: atrac3plus.c:620
uint8_t group_size
number of coefficients grouped together
static const uint8_t atrac3p_sf_huff_xlat5[16]
static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab, VLC *vlc_tab, int16_t *out, const int num_specs)
Decode huffman-coded spectral lines for a given quant unit.
Definition: atrac3plus.c:819
static const uint8_t atrac3p_qu_num_to_seg[32]
Ungroup table for word length segments.
static const uint8_t atrac3p_huff_gain_lev3_xlat[16]
static VLC ct_vlc_tabs[4]
Definition: atrac3plus.c:37
static const uint8_t atrac3p_wl_huff_xlat1[3]
Atrac3pWavesData * tones_info
Definition: atrac3plus.h:114
#define DEC_CT_IDX_COMMON(OP)
Definition: atrac3plus.c:697
int use_full_table
1 - full table list, 0 - restricted one
Definition: atrac3plus.h:139
static const uint8_t atrac3p_wl_huff_code1[3]
VLC tables for wordlen.
static const uint8_t atrac3p_ct_restricted_to_full[2][7][4]
static const uint8_t atrac3p_huff_numwavs1_cb[9]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:68
int num_gain_subbands
number of subbands with gain control data
Definition: atrac3plus.h:110
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
Definition: atrac3plus.h:143
uint8_t tone_sharing[ATRAC3P_SUBBANDS]
1 - subband-wise tone sharing flags
Definition: atrac3plus.h:123
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
int num_coded_vals
number of transmitted quant unit values
Definition: atrac3plus.h:91
static const uint8_t atrac3p_sf_huff_bits1[64]
static const uint8_t atrac3p_huff_gain_loc5_xlat[32]
static const uint8_t atrac3p_huff_wav_ampsf1_xlat[32]
av_cold void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
Definition: atrac3plus.c:83
static const uint8_t atrac3p_huff_gain_lev2_xlat[15]
#define CODING_VLC
Definition: atrac3plus.c:712
#define INIT_VLC_USE_NEW_STATIC
Definition: get_bits.h:479
#define FF_ARRAY_ELEMS(a)
static VLC sf_vlc_tabs[8]
Definition: atrac3plus.c:36
static int decode_gainc_data(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode gain control data for all channels.
Definition: atrac3plus.c:1369
#define av_log2
Definition: intmath.h:100
int bits
Definition: get_bits.h:65
static const float pred[4]
Definition: siprdata.h:259
static const uint8_t atrac3p_huff_gain_loc5_cb[9]
static const uint8_t atrac3p_huff_gain_lev2_cb[11]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int table_allocated
Definition: get_bits.h:67
static const uint8_t atrac3p_sf_huff_bits5[16]
int start_index
start index into global tones table for that subband
Definition: atrac3plus.h:77
int freq_index
wave frequency index
Definition: atrac3plus.h:82
Gain control parameters for one subband.
Definition: atrac.h:35
static void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, AtracGainInfo *dst)
Implements coding mode 1 for gain compensation locations.
Definition: atrac3plus.c:1183
static const uint8_t atrac3p_huff_wav_ampsf3_xlat[32]
main external API structure.
Definition: avcodec.h:1512
Channel unit parameters.
Definition: atrac3plus.h:131
static const uint8_t atrac3p_sf_huff_xlat4[16]
static const int8_t atrac3p_wl_weights[6][32]
static const uint8_t atrac3p_ct_huff_code3[8]
int amp_sf
quantized amplitude scale factor
Definition: atrac3plus.h:83
Sound channel parameters.
Definition: atrac3plus.h:89
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:305
int index
Definition: gxfenc.c:89
static const uint16_t atrac3p_sf_huff_code6[16]
static const uint8_t atrac3p_huff_gain_lev4_xlat[16]
#define UNPACK_SF_VQ_SHAPE(gb, dst, num_vals)
Definition: atrac3plus.c:324
static int decode_channel_code_tab(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, AVCodecContext *avctx)
Decode code table indexes for each quant unit of a channel.
Definition: atrac3plus.c:733
static int subtract_sf_weights(Atrac3pChanUnitCtx *ctx, Atrac3pChanParams *chan, int wtab_idx, AVCodecContext *avctx)
Subtract weighting coefficients from decoded scalefactors.
Definition: atrac3plus.c:284
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:138
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, AVCodecContext *avctx)
Decode word length for each quantization unit of a channel.
Definition: atrac3plus.c:338
static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, AVCodecContext *avctx)
Decode scale factor indexes for each quant unit of a channel.
Definition: atrac3plus.c:485
int num_points
number of gain control points
Definition: atrac.h:36
static int num_coded_units(GetBitContext *gb, Atrac3pChanParams *chan, Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx)
Decode number of coded quantization units.
Definition: atrac3plus.c:224
static const uint8_t atrac3p_huff_tonebands_cb[8]
static const uint8_t atrac3p_huff_numwavs2_cb[8]
int redirect
if >= 0: tells which huffman table must be reused
int has_start_point
indicates start point within the GHA window
Definition: atrac3plus.h:66
static const uint8_t atrac3p_huff_gain_loc3_xlat[32]
AtracGainInfo * gain_data
gain control data for next frame
Definition: atrac3plus.h:108
static void decode_tones_frequency(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[])
Decode frequency information for each subband of a channel.
Definition: atrac3plus.c:1517
int has_stop_point
indicates stop point within the GHA window
Definition: atrac3plus.h:67
static VLC spec_vlc_tabs[112]
Definition: atrac3plus.c:38
Atrac3pWaveSynthParams * waves_info
Definition: atrac3plus.h:149
int qu_tab_idx[32]
array of code table indexes for each quant unit
Definition: atrac3plus.h:97
int noise_present
1 - global noise info present
Definition: atrac3plus.h:140
static const uint8_t atrac3p_wl_huff_bits2[5]
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const uint8_t atrac3p_huff_numwavs2_xlat[8]
static const int8_t atrac3p_wl_shapes[8][16][9]
3D base shape tables.
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
Atrac3pChanParams channels[2]
Definition: atrac3plus.h:145
static int decode_scale_factors(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode scale factor indexes for each channel.
Definition: atrac3plus.c:653
static const uint8_t atrac3p_sf_huff_bits4[16]
static const uint8_t atrac3p_sf_huff_bits3[64]
int start_pos
start position expressed in n*4 samples
Definition: atrac3plus.h:68
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
static const uint8_t atrac3p_huff_wav_ampsf1_cb[7]
static const uint16_t atrac3p_sf_huff_code5[16]
static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode tones info for all channels.
Definition: atrac3plus.c:1702
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2303
static const uint8_t atrac3p_ct_huff_bits1[4]
static const uint8_t atrac3p_huff_gain_lev1_xlat[16]
static void gainc_loc_mode0(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, AtracGainInfo *dst, int pos)
Implements coding mode 0 for gain compensation locations.
Definition: atrac3plus.c:1160
int mute_flag
mute flag
Definition: atrac3plus.h:138
#define FFSWAP(type, a, b)
Definition: common.h:95
static const uint8_t atrac3p_wl_huff_code2[5]
int tones_present
1 - tones info present
Definition: atrac3plus.h:120
static int decode_gainc_npoints(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int coded_subbands)
Decode number of gain control points.
Definition: atrac3plus.c:972
#define CODING_DIRECT
Definition: atrac3plus.c:710
uint8_t tone_master[ATRAC3P_SUBBANDS]
1 - subband-wise tone channel swapping
Definition: atrac3plus.h:124
static const uint8_t atrac3p_wl_huff_code3[8]
Global structures, constants and data for ATRAC3+ decoder.
static VLC gain_vlc_tabs[11]
Definition: atrac3plus.c:39
static int add_wordlen_weights(Atrac3pChanUnitCtx *ctx, Atrac3pChanParams *chan, int wtab_idx, AVCodecContext *avctx)
Add weighting coefficients to the decoded word-length information.
Definition: atrac3plus.c:254
static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int ch_num, int band_has_tones[])
Decode amplitude information for each subband of a channel.
Definition: atrac3plus.c:1577
static const uint16_t atrac3p_sf_huff_code3[64]
uint8_t power_levs[5]
power compensation levels
Definition: atrac3plus.h:99
static const uint8_t atrac3p_wl_huff_bits4[8]