FFmpeg
atrac3.c
Go to the documentation of this file.
1 /*
2  * ATRAC3 compatible decoder
3  * Copyright (c) 2006-2008 Maxim Poliakovski
4  * Copyright (c) 2006-2008 Benjamin Larsson
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  * ATRAC3 compatible decoder.
26  * This decoder handles Sony's ATRAC3 data.
27  *
28  * Container formats used to store ATRAC3 data:
29  * RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3).
30  *
31  * To use this decoder, a calling application must supply the extradata
32  * bytes provided in the containers above.
33  */
34 
35 #include <math.h>
36 #include <stddef.h>
37 #include <stdio.h>
38 
39 #include "libavutil/attributes.h"
40 #include "libavutil/float_dsp.h"
41 #include "libavutil/libm.h"
42 #include "avcodec.h"
43 #include "bytestream.h"
44 #include "fft.h"
45 #include "get_bits.h"
46 #include "internal.h"
47 
48 #include "atrac.h"
49 #include "atrac3data.h"
50 
51 #define MIN_CHANNELS 1
52 #define MAX_CHANNELS 8
53 #define MAX_JS_PAIRS 8 / 2
54 
55 #define JOINT_STEREO 0x12
56 #define SINGLE 0x2
57 
58 #define SAMPLES_PER_FRAME 1024
59 #define MDCT_SIZE 512
60 
61 #define ATRAC3_VLC_BITS 8
62 
63 typedef struct GainBlock {
65 } GainBlock;
66 
67 typedef struct TonalComponent {
68  int pos;
69  int num_coefs;
70  float coef[8];
72 
73 typedef struct ChannelUnit {
76  float prev_frame[SAMPLES_PER_FRAME];
78  TonalComponent components[64];
79  GainBlock gain_block[2];
80 
81  DECLARE_ALIGNED(32, float, spectrum)[SAMPLES_PER_FRAME];
82  DECLARE_ALIGNED(32, float, imdct_buf)[SAMPLES_PER_FRAME];
83 
84  float delay_buf1[46]; ///<qmf delay buffers
85  float delay_buf2[46];
86  float delay_buf3[46];
87 } ChannelUnit;
88 
89 typedef struct ATRAC3Context {
91  //@{
92  /** stream data */
94 
96  //@}
97  //@{
98  /** joint-stereo related variables */
99  int matrix_coeff_index_prev[MAX_JS_PAIRS][4];
100  int matrix_coeff_index_now[MAX_JS_PAIRS][4];
101  int matrix_coeff_index_next[MAX_JS_PAIRS][4];
102  int weighting_delay[MAX_JS_PAIRS][6];
103  //@}
104  //@{
105  /** data buffers */
107  float temp_buf[1070];
108  //@}
109  //@{
110  /** extradata */
112  //@}
113 
116  void (*vector_fmul)(float *dst, const float *src0, const float *src1,
117  int len);
118 } ATRAC3Context;
119 
123 
124 /**
125  * Regular 512 points IMDCT without overlapping, with the exception of the
126  * swapping of odd bands caused by the reverse spectra of the QMF.
127  *
128  * @param odd_band 1 if the band is an odd band
129  */
130 static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band)
131 {
132  int i;
133 
134  if (odd_band) {
135  /**
136  * Reverse the odd bands before IMDCT, this is an effect of the QMF
137  * transform or it gives better compression to do it this way.
138  * FIXME: It should be possible to handle this in imdct_calc
139  * for that to happen a modification of the prerotation step of
140  * all SIMD code and C code is needed.
141  * Or fix the functions before so they generate a pre reversed spectrum.
142  */
143  for (i = 0; i < 128; i++)
144  FFSWAP(float, input[i], input[255 - i]);
145  }
146 
147  q->mdct_ctx.imdct_calc(&q->mdct_ctx, output, input);
148 
149  /* Perform windowing on the output. */
150  q->vector_fmul(output, output, mdct_window, MDCT_SIZE);
151 }
152 
153 /*
154  * indata descrambling, only used for data coming from the rm container
155  */
156 static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
157 {
158  int i, off;
159  uint32_t c;
160  const uint32_t *buf;
161  uint32_t *output = (uint32_t *)out;
162 
163  off = (intptr_t)input & 3;
164  buf = (const uint32_t *)(input - off);
165  if (off)
166  c = av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
167  else
168  c = av_be2ne32(0x537F6103U);
169  bytes += 3 + off;
170  for (i = 0; i < bytes / 4; i++)
171  output[i] = c ^ buf[i];
172 
173  if (off)
174  avpriv_request_sample(NULL, "Offset of %d", off);
175 
176  return off;
177 }
178 
179 static av_cold void init_imdct_window(void)
180 {
181  int i, j;
182 
183  /* generate the mdct window, for details see
184  * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */
185  for (i = 0, j = 255; i < 128; i++, j--) {
186  float wi = sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
187  float wj = sin(((j + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
188  float w = 0.5 * (wi * wi + wj * wj);
189  mdct_window[i] = mdct_window[511 - i] = wi / w;
190  mdct_window[j] = mdct_window[511 - j] = wj / w;
191  }
192 }
193 
195 {
196  ATRAC3Context *q = avctx->priv_data;
197 
198  av_freep(&q->units);
200 
201  ff_mdct_end(&q->mdct_ctx);
202 
203  return 0;
204 }
205 
206 /**
207  * Mantissa decoding
208  *
209  * @param selector which table the output values are coded with
210  * @param coding_flag constant length coding or variable length coding
211  * @param mantissas mantissa output table
212  * @param num_codes number of values to get
213  */
214 static void read_quant_spectral_coeffs(GetBitContext *gb, int selector,
215  int coding_flag, int *mantissas,
216  int num_codes)
217 {
218  int i, code, huff_symb;
219 
220  if (selector == 1)
221  num_codes /= 2;
222 
223  if (coding_flag != 0) {
224  /* constant length coding (CLC) */
225  int num_bits = clc_length_tab[selector];
226 
227  if (selector > 1) {
228  for (i = 0; i < num_codes; i++) {
229  if (num_bits)
230  code = get_sbits(gb, num_bits);
231  else
232  code = 0;
233  mantissas[i] = code;
234  }
235  } else {
236  for (i = 0; i < num_codes; i++) {
237  if (num_bits)
238  code = get_bits(gb, num_bits); // num_bits is always 4 in this case
239  else
240  code = 0;
241  mantissas[i * 2 ] = mantissa_clc_tab[code >> 2];
242  mantissas[i * 2 + 1] = mantissa_clc_tab[code & 3];
243  }
244  }
245  } else {
246  /* variable length coding (VLC) */
247  if (selector != 1) {
248  for (i = 0; i < num_codes; i++) {
249  huff_symb = get_vlc2(gb, spectral_coeff_tab[selector-1].table,
250  ATRAC3_VLC_BITS, 1);
251  huff_symb += 1;
252  code = huff_symb >> 1;
253  if (huff_symb & 1)
254  code = -code;
255  mantissas[i] = code;
256  }
257  } else {
258  for (i = 0; i < num_codes; i++) {
259  huff_symb = get_vlc2(gb, spectral_coeff_tab[selector - 1].table,
260  ATRAC3_VLC_BITS, 1);
261  mantissas[i * 2 ] = mantissa_vlc_tab[huff_symb * 2 ];
262  mantissas[i * 2 + 1] = mantissa_vlc_tab[huff_symb * 2 + 1];
263  }
264  }
265  }
266 }
267 
268 /**
269  * Restore the quantized band spectrum coefficients
270  *
271  * @return subband count, fix for broken specification/files
272  */
273 static int decode_spectrum(GetBitContext *gb, float *output)
274 {
275  int num_subbands, coding_mode, i, j, first, last, subband_size;
276  int subband_vlc_index[32], sf_index[32];
277  int mantissas[128];
278  float scale_factor;
279 
280  num_subbands = get_bits(gb, 5); // number of coded subbands
281  coding_mode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC
282 
283  /* get the VLC selector table for the subbands, 0 means not coded */
284  for (i = 0; i <= num_subbands; i++)
285  subband_vlc_index[i] = get_bits(gb, 3);
286 
287  /* read the scale factor indexes from the stream */
288  for (i = 0; i <= num_subbands; i++) {
289  if (subband_vlc_index[i] != 0)
290  sf_index[i] = get_bits(gb, 6);
291  }
292 
293  for (i = 0; i <= num_subbands; i++) {
294  first = subband_tab[i ];
295  last = subband_tab[i + 1];
296 
297  subband_size = last - first;
298 
299  if (subband_vlc_index[i] != 0) {
300  /* decode spectral coefficients for this subband */
301  /* TODO: This can be done faster is several blocks share the
302  * same VLC selector (subband_vlc_index) */
303  read_quant_spectral_coeffs(gb, subband_vlc_index[i], coding_mode,
304  mantissas, subband_size);
305 
306  /* decode the scale factor for this subband */
307  scale_factor = ff_atrac_sf_table[sf_index[i]] *
308  inv_max_quant[subband_vlc_index[i]];
309 
310  /* inverse quantize the coefficients */
311  for (j = 0; first < last; first++, j++)
312  output[first] = mantissas[j] * scale_factor;
313  } else {
314  /* this subband was not coded, so zero the entire subband */
315  memset(output + first, 0, subband_size * sizeof(*output));
316  }
317  }
318 
319  /* clear the subbands that were not coded */
320  first = subband_tab[i];
321  memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(*output));
322  return num_subbands;
323 }
324 
325 /**
326  * Restore the quantized tonal components
327  *
328  * @param components tonal components
329  * @param num_bands number of coded bands
330  */
332  TonalComponent *components, int num_bands)
333 {
334  int i, b, c, m;
335  int nb_components, coding_mode_selector, coding_mode;
336  int band_flags[4], mantissa[8];
337  int component_count = 0;
338 
339  nb_components = get_bits(gb, 5);
340 
341  /* no tonal components */
342  if (nb_components == 0)
343  return 0;
344 
345  coding_mode_selector = get_bits(gb, 2);
346  if (coding_mode_selector == 2)
347  return AVERROR_INVALIDDATA;
348 
349  coding_mode = coding_mode_selector & 1;
350 
351  for (i = 0; i < nb_components; i++) {
352  int coded_values_per_component, quant_step_index;
353 
354  for (b = 0; b <= num_bands; b++)
355  band_flags[b] = get_bits1(gb);
356 
357  coded_values_per_component = get_bits(gb, 3);
358 
359  quant_step_index = get_bits(gb, 3);
360  if (quant_step_index <= 1)
361  return AVERROR_INVALIDDATA;
362 
363  if (coding_mode_selector == 3)
364  coding_mode = get_bits1(gb);
365 
366  for (b = 0; b < (num_bands + 1) * 4; b++) {
367  int coded_components;
368 
369  if (band_flags[b >> 2] == 0)
370  continue;
371 
372  coded_components = get_bits(gb, 3);
373 
374  for (c = 0; c < coded_components; c++) {
375  TonalComponent *cmp = &components[component_count];
376  int sf_index, coded_values, max_coded_values;
377  float scale_factor;
378 
379  sf_index = get_bits(gb, 6);
380  if (component_count >= 64)
381  return AVERROR_INVALIDDATA;
382 
383  cmp->pos = b * 64 + get_bits(gb, 6);
384 
385  max_coded_values = SAMPLES_PER_FRAME - cmp->pos;
386  coded_values = coded_values_per_component + 1;
387  coded_values = FFMIN(max_coded_values, coded_values);
388 
389  scale_factor = ff_atrac_sf_table[sf_index] *
390  inv_max_quant[quant_step_index];
391 
392  read_quant_spectral_coeffs(gb, quant_step_index, coding_mode,
393  mantissa, coded_values);
394 
395  cmp->num_coefs = coded_values;
396 
397  /* inverse quant */
398  for (m = 0; m < coded_values; m++)
399  cmp->coef[m] = mantissa[m] * scale_factor;
400 
401  component_count++;
402  }
403  }
404  }
405 
406  return component_count;
407 }
408 
409 /**
410  * Decode gain parameters for the coded bands
411  *
412  * @param block the gainblock for the current band
413  * @param num_bands amount of coded bands
414  */
416  int num_bands)
417 {
418  int b, j;
419  int *level, *loc;
420 
421  AtracGainInfo *gain = block->g_block;
422 
423  for (b = 0; b <= num_bands; b++) {
424  gain[b].num_points = get_bits(gb, 3);
425  level = gain[b].lev_code;
426  loc = gain[b].loc_code;
427 
428  for (j = 0; j < gain[b].num_points; j++) {
429  level[j] = get_bits(gb, 4);
430  loc[j] = get_bits(gb, 5);
431  if (j && loc[j] <= loc[j - 1])
432  return AVERROR_INVALIDDATA;
433  }
434  }
435 
436  /* Clear the unused blocks. */
437  for (; b < 4 ; b++)
438  gain[b].num_points = 0;
439 
440  return 0;
441 }
442 
443 /**
444  * Combine the tonal band spectrum and regular band spectrum
445  *
446  * @param spectrum output spectrum buffer
447  * @param num_components number of tonal components
448  * @param components tonal components for this band
449  * @return position of the last tonal coefficient
450  */
451 static int add_tonal_components(float *spectrum, int num_components,
452  TonalComponent *components)
453 {
454  int i, j, last_pos = -1;
455  float *input, *output;
456 
457  for (i = 0; i < num_components; i++) {
458  last_pos = FFMAX(components[i].pos + components[i].num_coefs, last_pos);
459  input = components[i].coef;
460  output = &spectrum[components[i].pos];
461 
462  for (j = 0; j < components[i].num_coefs; j++)
463  output[j] += input[j];
464  }
465 
466  return last_pos;
467 }
468 
469 #define INTERPOLATE(old, new, nsample) \
470  ((old) + (nsample) * 0.125 * ((new) - (old)))
471 
472 static void reverse_matrixing(float *su1, float *su2, int *prev_code,
473  int *curr_code)
474 {
475  int i, nsample, band;
476  float mc1_l, mc1_r, mc2_l, mc2_r;
477 
478  for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
479  int s1 = prev_code[i];
480  int s2 = curr_code[i];
481  nsample = band;
482 
483  if (s1 != s2) {
484  /* Selector value changed, interpolation needed. */
485  mc1_l = matrix_coeffs[s1 * 2 ];
486  mc1_r = matrix_coeffs[s1 * 2 + 1];
487  mc2_l = matrix_coeffs[s2 * 2 ];
488  mc2_r = matrix_coeffs[s2 * 2 + 1];
489 
490  /* Interpolation is done over the first eight samples. */
491  for (; nsample < band + 8; nsample++) {
492  float c1 = su1[nsample];
493  float c2 = su2[nsample];
494  c2 = c1 * INTERPOLATE(mc1_l, mc2_l, nsample - band) +
495  c2 * INTERPOLATE(mc1_r, mc2_r, nsample - band);
496  su1[nsample] = c2;
497  su2[nsample] = c1 * 2.0 - c2;
498  }
499  }
500 
501  /* Apply the matrix without interpolation. */
502  switch (s2) {
503  case 0: /* M/S decoding */
504  for (; nsample < band + 256; nsample++) {
505  float c1 = su1[nsample];
506  float c2 = su2[nsample];
507  su1[nsample] = c2 * 2.0;
508  su2[nsample] = (c1 - c2) * 2.0;
509  }
510  break;
511  case 1:
512  for (; nsample < band + 256; nsample++) {
513  float c1 = su1[nsample];
514  float c2 = su2[nsample];
515  su1[nsample] = (c1 + c2) * 2.0;
516  su2[nsample] = c2 * -2.0;
517  }
518  break;
519  case 2:
520  case 3:
521  for (; nsample < band + 256; nsample++) {
522  float c1 = su1[nsample];
523  float c2 = su2[nsample];
524  su1[nsample] = c1 + c2;
525  su2[nsample] = c1 - c2;
526  }
527  break;
528  default:
529  av_assert1(0);
530  }
531  }
532 }
533 
534 static void get_channel_weights(int index, int flag, float ch[2])
535 {
536  if (index == 7) {
537  ch[0] = 1.0;
538  ch[1] = 1.0;
539  } else {
540  ch[0] = (index & 7) / 7.0;
541  ch[1] = sqrt(2 - ch[0] * ch[0]);
542  if (flag)
543  FFSWAP(float, ch[0], ch[1]);
544  }
545 }
546 
547 static void channel_weighting(float *su1, float *su2, int *p3)
548 {
549  int band, nsample;
550  /* w[x][y] y=0 is left y=1 is right */
551  float w[2][2];
552 
553  if (p3[1] != 7 || p3[3] != 7) {
554  get_channel_weights(p3[1], p3[0], w[0]);
555  get_channel_weights(p3[3], p3[2], w[1]);
556 
557  for (band = 256; band < 4 * 256; band += 256) {
558  for (nsample = band; nsample < band + 8; nsample++) {
559  su1[nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample - band);
560  su2[nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample - band);
561  }
562  for(; nsample < band + 256; nsample++) {
563  su1[nsample] *= w[1][0];
564  su2[nsample] *= w[1][1];
565  }
566  }
567  }
568 }
569 
570 /**
571  * Decode a Sound Unit
572  *
573  * @param snd the channel unit to be used
574  * @param output the decoded samples before IQMF in float representation
575  * @param channel_num channel number
576  * @param coding_mode the coding mode (JOINT_STEREO or single channels)
577  */
579  ChannelUnit *snd, float *output,
580  int channel_num, int coding_mode)
581 {
582  int band, ret, num_subbands, last_tonal, num_bands;
583  GainBlock *gain1 = &snd->gain_block[ snd->gc_blk_switch];
584  GainBlock *gain2 = &snd->gain_block[1 - snd->gc_blk_switch];
585 
586  if (coding_mode == JOINT_STEREO && (channel_num % 2) == 1) {
587  if (get_bits(gb, 2) != 3) {
588  av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n");
589  return AVERROR_INVALIDDATA;
590  }
591  } else {
592  if (get_bits(gb, 6) != 0x28) {
593  av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n");
594  return AVERROR_INVALIDDATA;
595  }
596  }
597 
598  /* number of coded QMF bands */
599  snd->bands_coded = get_bits(gb, 2);
600 
601  ret = decode_gain_control(gb, gain2, snd->bands_coded);
602  if (ret)
603  return ret;
604 
606  snd->bands_coded);
607  if (snd->num_components < 0)
608  return snd->num_components;
609 
610  num_subbands = decode_spectrum(gb, snd->spectrum);
611 
612  /* Merge the decoded spectrum and tonal components. */
613  last_tonal = add_tonal_components(snd->spectrum, snd->num_components,
614  snd->components);
615 
616 
617  /* calculate number of used MLT/QMF bands according to the amount of coded
618  spectral lines */
619  num_bands = (subband_tab[num_subbands] - 1) >> 8;
620  if (last_tonal >= 0)
621  num_bands = FFMAX((last_tonal + 256) >> 8, num_bands);
622 
623 
624  /* Reconstruct time domain samples. */
625  for (band = 0; band < 4; band++) {
626  /* Perform the IMDCT step without overlapping. */
627  if (band <= num_bands)
628  imlt(q, &snd->spectrum[band * 256], snd->imdct_buf, band & 1);
629  else
630  memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf));
631 
632  /* gain compensation and overlapping */
634  &snd->prev_frame[band * 256],
635  &gain1->g_block[band], &gain2->g_block[band],
636  256, &output[band * 256]);
637  }
638 
639  /* Swap the gain control buffers for the next frame. */
640  snd->gc_blk_switch ^= 1;
641 
642  return 0;
643 }
644 
645 static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
646  float **out_samples)
647 {
648  ATRAC3Context *q = avctx->priv_data;
649  int ret, i, ch;
650  uint8_t *ptr1;
651 
652  if (q->coding_mode == JOINT_STEREO) {
653  /* channel coupling mode */
654 
655  /* Decode sound unit pairs (channels are expected to be even).
656  * Multichannel joint stereo interleaves pairs (6ch: 2ch + 2ch + 2ch) */
657  const uint8_t *js_databuf;
658  int js_pair, js_block_align;
659 
660  js_block_align = (avctx->block_align / avctx->channels) * 2; /* block pair */
661 
662  for (ch = 0; ch < avctx->channels; ch = ch + 2) {
663  js_pair = ch/2;
664  js_databuf = databuf + js_pair * js_block_align; /* align to current pair */
665 
666  /* Set the bitstream reader at the start of first channel sound unit. */
667  init_get_bits(&q->gb,
668  js_databuf, js_block_align * 8);
669 
670  /* decode Sound Unit 1 */
671  ret = decode_channel_sound_unit(q, &q->gb, &q->units[ch],
672  out_samples[ch], ch, JOINT_STEREO);
673  if (ret != 0)
674  return ret;
675 
676  /* Framedata of the su2 in the joint-stereo mode is encoded in
677  * reverse byte order so we need to swap it first. */
678  if (js_databuf == q->decoded_bytes_buffer) {
679  uint8_t *ptr2 = q->decoded_bytes_buffer + js_block_align - 1;
680  ptr1 = q->decoded_bytes_buffer;
681  for (i = 0; i < js_block_align / 2; i++, ptr1++, ptr2--)
682  FFSWAP(uint8_t, *ptr1, *ptr2);
683  } else {
684  const uint8_t *ptr2 = js_databuf + js_block_align - 1;
685  for (i = 0; i < js_block_align; i++)
686  q->decoded_bytes_buffer[i] = *ptr2--;
687  }
688 
689  /* Skip the sync codes (0xF8). */
690  ptr1 = q->decoded_bytes_buffer;
691  for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
692  if (i >= js_block_align)
693  return AVERROR_INVALIDDATA;
694  }
695 
696 
697  /* set the bitstream reader at the start of the second Sound Unit */
698  ret = init_get_bits8(&q->gb,
699  ptr1, q->decoded_bytes_buffer + js_block_align - ptr1);
700  if (ret < 0)
701  return ret;
702 
703  /* Fill the Weighting coeffs delay buffer */
704  memmove(q->weighting_delay[js_pair], &q->weighting_delay[js_pair][2],
705  4 * sizeof(*q->weighting_delay[js_pair]));
706  q->weighting_delay[js_pair][4] = get_bits1(&q->gb);
707  q->weighting_delay[js_pair][5] = get_bits(&q->gb, 3);
708 
709  for (i = 0; i < 4; i++) {
710  q->matrix_coeff_index_prev[js_pair][i] = q->matrix_coeff_index_now[js_pair][i];
711  q->matrix_coeff_index_now[js_pair][i] = q->matrix_coeff_index_next[js_pair][i];
712  q->matrix_coeff_index_next[js_pair][i] = get_bits(&q->gb, 2);
713  }
714 
715  /* Decode Sound Unit 2. */
716  ret = decode_channel_sound_unit(q, &q->gb, &q->units[ch+1],
717  out_samples[ch+1], ch+1, JOINT_STEREO);
718  if (ret != 0)
719  return ret;
720 
721  /* Reconstruct the channel coefficients. */
722  reverse_matrixing(out_samples[ch], out_samples[ch+1],
723  q->matrix_coeff_index_prev[js_pair],
724  q->matrix_coeff_index_now[js_pair]);
725 
726  channel_weighting(out_samples[ch], out_samples[ch+1], q->weighting_delay[js_pair]);
727  }
728  } else {
729  /* single channels */
730  /* Decode the channel sound units. */
731  for (i = 0; i < avctx->channels; i++) {
732  /* Set the bitstream reader at the start of a channel sound unit. */
733  init_get_bits(&q->gb,
734  databuf + i * avctx->block_align / avctx->channels,
735  avctx->block_align * 8 / avctx->channels);
736 
737  ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
738  out_samples[i], i, q->coding_mode);
739  if (ret != 0)
740  return ret;
741  }
742  }
743 
744  /* Apply the iQMF synthesis filter. */
745  for (i = 0; i < avctx->channels; i++) {
746  float *p1 = out_samples[i];
747  float *p2 = p1 + 256;
748  float *p3 = p2 + 256;
749  float *p4 = p3 + 256;
750  ff_atrac_iqmf(p1, p2, 256, p1, q->units[i].delay_buf1, q->temp_buf);
751  ff_atrac_iqmf(p4, p3, 256, p3, q->units[i].delay_buf2, q->temp_buf);
752  ff_atrac_iqmf(p1, p3, 512, p1, q->units[i].delay_buf3, q->temp_buf);
753  }
754 
755  return 0;
756 }
757 
758 static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
759  int size, float **out_samples)
760 {
761  ATRAC3Context *q = avctx->priv_data;
762  int ret, i;
763 
764  /* Set the bitstream reader at the start of a channel sound unit. */
765  init_get_bits(&q->gb, databuf, size * 8);
766  /* single channels */
767  /* Decode the channel sound units. */
768  for (i = 0; i < avctx->channels; i++) {
769  ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
770  out_samples[i], i, q->coding_mode);
771  if (ret != 0)
772  return ret;
773  while (i < avctx->channels && get_bits_left(&q->gb) > 6 && show_bits(&q->gb, 6) != 0x28) {
774  skip_bits(&q->gb, 1);
775  }
776  }
777 
778  /* Apply the iQMF synthesis filter. */
779  for (i = 0; i < avctx->channels; i++) {
780  float *p1 = out_samples[i];
781  float *p2 = p1 + 256;
782  float *p3 = p2 + 256;
783  float *p4 = p3 + 256;
784  ff_atrac_iqmf(p1, p2, 256, p1, q->units[i].delay_buf1, q->temp_buf);
785  ff_atrac_iqmf(p4, p3, 256, p3, q->units[i].delay_buf2, q->temp_buf);
786  ff_atrac_iqmf(p1, p3, 512, p1, q->units[i].delay_buf3, q->temp_buf);
787  }
788 
789  return 0;
790 }
791 
792 static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
793  int *got_frame_ptr, AVPacket *avpkt)
794 {
795  AVFrame *frame = data;
796  const uint8_t *buf = avpkt->data;
797  int buf_size = avpkt->size;
798  ATRAC3Context *q = avctx->priv_data;
799  int ret;
800  const uint8_t *databuf;
801 
802  if (buf_size < avctx->block_align) {
803  av_log(avctx, AV_LOG_ERROR,
804  "Frame too small (%d bytes). Truncated file?\n", buf_size);
805  return AVERROR_INVALIDDATA;
806  }
807 
808  /* get output buffer */
809  frame->nb_samples = SAMPLES_PER_FRAME;
810  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
811  return ret;
812 
813  /* Check if we need to descramble and what buffer to pass on. */
814  if (q->scrambled_stream) {
816  databuf = q->decoded_bytes_buffer;
817  } else {
818  databuf = buf;
819  }
820 
821  ret = decode_frame(avctx, databuf, (float **)frame->extended_data);
822  if (ret) {
823  av_log(avctx, AV_LOG_ERROR, "Frame decoding error!\n");
824  return ret;
825  }
826 
827  *got_frame_ptr = 1;
828 
829  return avctx->block_align;
830 }
831 
832 static int atrac3al_decode_frame(AVCodecContext *avctx, void *data,
833  int *got_frame_ptr, AVPacket *avpkt)
834 {
835  AVFrame *frame = data;
836  int ret;
837 
838  frame->nb_samples = SAMPLES_PER_FRAME;
839  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
840  return ret;
841 
842  ret = al_decode_frame(avctx, avpkt->data, avpkt->size,
843  (float **)frame->extended_data);
844  if (ret) {
845  av_log(avctx, AV_LOG_ERROR, "Frame decoding error!\n");
846  return ret;
847  }
848 
849  *got_frame_ptr = 1;
850 
851  return avpkt->size;
852 }
853 
855 {
857  int i;
858 
861 
862  /* Initialize the VLC tables. */
863  for (i = 0; i < 7; i++) {
864  spectral_coeff_tab[i].table = table;
865  spectral_coeff_tab[i].table_allocated = 256;
866  init_vlc(&spectral_coeff_tab[i], ATRAC3_VLC_BITS, huff_tab_sizes[i],
867  huff_bits[i], 1, 1,
869  table += 256;
870  }
871 }
872 
874 {
875  static int static_init_done;
876  int i, js_pair, ret;
877  int version, delay, samples_per_frame, frame_factor;
878  const uint8_t *edata_ptr = avctx->extradata;
879  ATRAC3Context *q = avctx->priv_data;
880  AVFloatDSPContext *fdsp;
881 
882  if (avctx->channels < MIN_CHANNELS || avctx->channels > MAX_CHANNELS) {
883  av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
884  return AVERROR(EINVAL);
885  }
886 
887  if (!static_init_done)
889  static_init_done = 1;
890 
891  /* Take care of the codec-specific extradata. */
892  if (avctx->codec_id == AV_CODEC_ID_ATRAC3AL) {
893  version = 4;
894  samples_per_frame = SAMPLES_PER_FRAME * avctx->channels;
895  delay = 0x88E;
896  q->coding_mode = SINGLE;
897  } else if (avctx->extradata_size == 14) {
898  /* Parse the extradata, WAV format */
899  av_log(avctx, AV_LOG_DEBUG, "[0-1] %d\n",
900  bytestream_get_le16(&edata_ptr)); // Unknown value always 1
901  edata_ptr += 4; // samples per channel
902  q->coding_mode = bytestream_get_le16(&edata_ptr);
903  av_log(avctx, AV_LOG_DEBUG,"[8-9] %d\n",
904  bytestream_get_le16(&edata_ptr)); //Dupe of coding mode
905  frame_factor = bytestream_get_le16(&edata_ptr); // Unknown always 1
906  av_log(avctx, AV_LOG_DEBUG,"[12-13] %d\n",
907  bytestream_get_le16(&edata_ptr)); // Unknown always 0
908 
909  /* setup */
910  samples_per_frame = SAMPLES_PER_FRAME * avctx->channels;
911  version = 4;
912  delay = 0x88E;
914  q->scrambled_stream = 0;
915 
916  if (avctx->block_align != 96 * avctx->channels * frame_factor &&
917  avctx->block_align != 152 * avctx->channels * frame_factor &&
918  avctx->block_align != 192 * avctx->channels * frame_factor) {
919  av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
920  "configuration %d/%d/%d\n", avctx->block_align,
921  avctx->channels, frame_factor);
922  return AVERROR_INVALIDDATA;
923  }
924  } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) {
925  /* Parse the extradata, RM format. */
926  version = bytestream_get_be32(&edata_ptr);
927  samples_per_frame = bytestream_get_be16(&edata_ptr);
928  delay = bytestream_get_be16(&edata_ptr);
929  q->coding_mode = bytestream_get_be16(&edata_ptr);
930  q->scrambled_stream = 1;
931 
932  } else {
933  av_log(avctx, AV_LOG_ERROR, "Unknown extradata size %d.\n",
934  avctx->extradata_size);
935  return AVERROR(EINVAL);
936  }
937 
938  /* Check the extradata */
939 
940  if (version != 4) {
941  av_log(avctx, AV_LOG_ERROR, "Version %d != 4.\n", version);
942  return AVERROR_INVALIDDATA;
943  }
944 
945  if (samples_per_frame != SAMPLES_PER_FRAME * avctx->channels) {
946  av_log(avctx, AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n",
947  samples_per_frame);
948  return AVERROR_INVALIDDATA;
949  }
950 
951  if (delay != 0x88E) {
952  av_log(avctx, AV_LOG_ERROR, "Unknown amount of delay %x != 0x88E.\n",
953  delay);
954  return AVERROR_INVALIDDATA;
955  }
956 
957  if (q->coding_mode == SINGLE)
958  av_log(avctx, AV_LOG_DEBUG, "Single channels detected.\n");
959  else if (q->coding_mode == JOINT_STEREO) {
960  if (avctx->channels % 2 == 1) { /* Joint stereo channels must be even */
961  av_log(avctx, AV_LOG_ERROR, "Invalid joint stereo channel configuration.\n");
962  return AVERROR_INVALIDDATA;
963  }
964  av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n");
965  } else {
966  av_log(avctx, AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
967  q->coding_mode);
968  return AVERROR_INVALIDDATA;
969  }
970 
971  if (avctx->block_align > 4096 || avctx->block_align <= 0)
972  return AVERROR(EINVAL);
973 
976  if (!q->decoded_bytes_buffer)
977  return AVERROR(ENOMEM);
978 
980 
981  /* initialize the MDCT transform */
982  if ((ret = ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768)) < 0) {
983  av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n");
984  return ret;
985  }
986 
987  /* init the joint-stereo decoding data */
988  for (js_pair = 0; js_pair < MAX_JS_PAIRS; js_pair++) {
989  q->weighting_delay[js_pair][0] = 0;
990  q->weighting_delay[js_pair][1] = 7;
991  q->weighting_delay[js_pair][2] = 0;
992  q->weighting_delay[js_pair][3] = 7;
993  q->weighting_delay[js_pair][4] = 0;
994  q->weighting_delay[js_pair][5] = 7;
995 
996  for (i = 0; i < 4; i++) {
997  q->matrix_coeff_index_prev[js_pair][i] = 3;
998  q->matrix_coeff_index_now[js_pair][i] = 3;
999  q->matrix_coeff_index_next[js_pair][i] = 3;
1000  }
1001  }
1002 
1005  if (!fdsp)
1006  return AVERROR(ENOMEM);
1007  q->vector_fmul = fdsp->vector_fmul;
1008  av_free(fdsp);
1009 
1010  q->units = av_mallocz_array(avctx->channels, sizeof(*q->units));
1011  if (!q->units)
1012  return AVERROR(ENOMEM);
1013 
1014  return 0;
1015 }
1016 
1018  .name = "atrac3",
1019  .long_name = NULL_IF_CONFIG_SMALL("ATRAC3 (Adaptive TRansform Acoustic Coding 3)"),
1020  .type = AVMEDIA_TYPE_AUDIO,
1021  .id = AV_CODEC_ID_ATRAC3,
1022  .priv_data_size = sizeof(ATRAC3Context),
1024  .close = atrac3_decode_close,
1026  .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
1027  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1029  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1030 };
1031 
1033  .name = "atrac3al",
1034  .long_name = NULL_IF_CONFIG_SMALL("ATRAC3 AL (Adaptive TRansform Acoustic Coding 3 Advanced Lossless)"),
1035  .type = AVMEDIA_TYPE_AUDIO,
1036  .id = AV_CODEC_ID_ATRAC3AL,
1037  .priv_data_size = sizeof(ATRAC3Context),
1039  .close = atrac3_decode_close,
1041  .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
1042  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1044  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1045 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
version
Definition: libkvazaar.c:317
This structure describes decoded (raw) audio or video data.
Definition: frame.h:314
static void reverse_matrixing(float *su1, float *su2, int *prev_code, int *curr_code)
Definition: atrac3.c:472
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Definition: atrac3.c:116
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
#define JOINT_STEREO
Definition: atrac3.c:55
uint8_t * decoded_bytes_buffer
data buffers
Definition: atrac3.c:106
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
static int add_tonal_components(float *spectrum, int num_components, TonalComponent *components)
Combine the tonal band spectrum and regular band spectrum.
Definition: atrac3.c:451
static const uint8_t clc_length_tab[8]
Definition: atrac3data.h:108
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define SINGLE
Definition: atrac3.c:56
static const uint8_t *const huff_codes[7]
Definition: atrac3data.h:98
#define MDCT_SIZE
Definition: atrac3.c:59
AtracGCContext gainc_ctx
Definition: atrac3.c:114
#define avpriv_request_sample(...)
#define SAMPLES_PER_FRAME
Definition: atrac3.c:58
TonalComponent components[64]
Definition: atrac3.c:78
int size
Definition: packet.h:364
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
Quadrature mirror synthesis filter.
Definition: atrac.c:127
float coef[8]
Definition: atrac3.c:70
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
FFTContext mdct_ctx
Definition: atrac3.c:115
static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band)
Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands caused ...
Definition: atrac3.c:130
#define av_be2ne32(x)
Definition: bswap.h:93
AVCodec.
Definition: codec.h:190
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1228
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:359
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
GetBitContext gb
Definition: atrac3.c:90
Macro definitions for various function/variable attributes.
int lev_code[7]
level at corresponding control point
Definition: atrac.h:37
float ff_atrac_sf_table[64]
Definition: atrac.c:36
static const uint8_t *const huff_bits[7]
Definition: atrac3data.h:102
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1199
The exact code depends on how similar the blocks are and how related they are to the block
uint8_t
GainBlock gain_block[2]
Definition: atrac3.c:79
#define av_cold
Definition: attributes.h:88
static void channel_weighting(float *su1, float *su2, int *p3)
Definition: atrac3.c:547
static float mdct_window[MDCT_SIZE]
Definition: atrac3.c:120
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the entry wise product of two vectors of floats and store the result in a vector of floats...
Definition: float_dsp.h:38
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:632
static const int8_t mantissa_clc_tab[4]
Definition: atrac3data.h:110
static VLC_TYPE atrac3_vlc_table[7 *1<< ATRAC3_VLC_BITS][2]
Definition: atrac3.c:121
int matrix_coeff_index_now[MAX_JS_PAIRS][4]
Definition: atrac3.c:100
static const float inv_max_quant[8]
Definition: atrac3data.h:119
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
uint8_t * data
Definition: packet.h:363
ATRAC common header.
static const uint64_t c1
Definition: murmur3.c:51
int num_components
Definition: atrac3.c:75
bitstream reader API header.
ptrdiff_t size
Definition: opengl_enc.c:100
channels
Definition: aptx.h:33
int loc_code[7]
location of gain control points
Definition: atrac.h:38
static int atrac3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3.c:792
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
static const uint16_t table[]
Definition: prosumer.c:206
static int decode_spectrum(GetBitContext *gb, float *output)
Restore the quantized band spectrum coefficients.
Definition: atrac3.c:273
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
#define s2
Definition: regdef.h:39
#define MAX_JS_PAIRS
Definition: atrac3.c:53
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: vlc.h:38
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
int bands_coded
Definition: atrac3.c:74
unsigned int pos
Definition: spdifenc.c:410
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
int matrix_coeff_index_next[MAX_JS_PAIRS][4]
Definition: atrac3.c:101
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:611
float temp_buf[1070]
Definition: atrac3.c:107
const char * name
Name of the codec implementation.
Definition: codec.h:197
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:107
#define ff_mdct_init
Definition: fft.h:169
#define FFMAX(a, b)
Definition: common.h:94
Gain compensation context structure.
Definition: atrac.h:44
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, int loc_scale)
Initialize gain compensation context.
Definition: atrac.c:66
Definition: vlc.h:26
float spectrum[SAMPLES_PER_FRAME]
Definition: atrac3.c:81
AVCodec ff_atrac3al_decoder
Definition: atrac3.c:1032
static const uint16_t subband_tab[33]
Definition: atrac3data.h:124
static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, float **out_samples)
Definition: atrac3.c:645
#define b
Definition: input.c:41
Definition: fft.h:88
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:333
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
static void get_channel_weights(int index, int flag, float ch[2])
Definition: atrac3.c:534
#define FFMIN(a, b)
Definition: common.h:96
#define MIN_CHANNELS
Definition: atrac3.c:51
static const int8_t mantissa_vlc_tab[18]
Definition: atrac3data.h:112
float prev_frame[SAMPLES_PER_FRAME]
Definition: atrac3.c:76
uint8_t w
Definition: llviddspenc.c:38
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int num_coefs
Definition: atrac3.c:69
int gc_blk_switch
Definition: atrac3.c:77
float imdct_buf[SAMPLES_PER_FRAME]
Definition: atrac3.c:82
static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
Definition: atrac3.c:156
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:446
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
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:797
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
Definition: motion_est.c:260
int table_allocated
Definition: vlc.h:29
#define src1
Definition: h264pred.c:139
static int decode_gain_control(GetBitContext *gb, GainBlock *block, int num_bands)
Decode gain parameters for the coded bands.
Definition: atrac3.c:415
Gain control parameters for one subband.
Definition: atrac.h:35
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static void read_quant_spectral_coeffs(GetBitContext *gb, int selector, int coding_flag, int *mantissas, int num_codes)
Mantissa decoding.
Definition: atrac3.c:214
enum AVCodecID codec_id
Definition: avcodec.h:541
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
main external API structure.
Definition: avcodec.h:531
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1879
int coding_mode
stream data
Definition: atrac3.c:93
int extradata_size
Definition: avcodec.h:633
Replacements for frequently missing libm functions.
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
static av_cold int atrac3_decode_close(AVCodecContext *avctx)
Definition: atrac3.c:194
int index
Definition: gxfenc.c:89
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
Definition: codec.h:93
AtracGainInfo g_block[4]
Definition: atrac3.c:64
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
#define src0
Definition: h264pred.c:138
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
#define s1
Definition: regdef.h:38
ChannelUnit * units
Definition: atrac3.c:95
static av_cold void init_imdct_window(void)
Definition: atrac3.c:179
float delay_buf2[46]
Definition: atrac3.c:85
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
int num_points
number of gain control points
Definition: atrac.h:36
uint8_t level
Definition: svq3.c:205
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
Definition: atrac3.c:873
#define ATRAC3_VLC_BITS
Definition: atrac3.c:61
float delay_buf3[46]
Definition: atrac3.c:86
static int atrac3al_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3.c:832
common internal api header.
int scrambled_stream
extradata
Definition: atrac3.c:111
#define ff_mdct_end
Definition: fft.h:170
#define flag(name)
Definition: cbs_av1.c:552
#define INIT_VLC_USE_NEW_STATIC
Definition: vlc.h:60
static const uint64_t c2
Definition: murmur3.c:52
static VLC spectral_coeff_tab[7]
Definition: atrac3.c:122
static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf, int size, float **out_samples)
Definition: atrac3.c:758
float delay_buf1[46]
qmf delay buffers
Definition: atrac3.c:84
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:215
AVCodec ff_atrac3_decoder
Definition: atrac3.c:1017
void * priv_data
Definition: avcodec.h:558
#define av_free(p)
#define MAX_CHANNELS
Definition: atrac3.c:52
static const float matrix_coeffs[8]
Definition: atrac3data.h:133
int len
int channels
number of audio channels
Definition: avcodec.h:1192
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
#define INTERPOLATE(old, new, nsample)
Definition: atrac3.c:469
void ff_atrac_gain_compensation(AtracGCContext *gctx, float *in, float *prev, AtracGainInfo *gc_now, AtracGainInfo *gc_next, int num_samples, float *out)
Apply gain compensation and perform the MDCT overlapping part.
Definition: atrac.c:84
av_cold void ff_atrac_generate_tables(void)
Generate common tables.
Definition: atrac.c:48
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:940
FILE * out
Definition: movenc.c:54
static av_cold void atrac3_init_static_data(void)
Definition: atrac3.c:854
#define av_freep(p)
int weighting_delay[MAX_JS_PAIRS][6]
Definition: atrac3.c:102
#define M_PI
Definition: mathematics.h:52
#define VLC_TYPE
Definition: vlc.h:24
static const uint8_t huff_tab_sizes[7]
Definition: atrac3data.h:94
#define FFSWAP(type, a, b)
Definition: common.h:99
int matrix_coeff_index_prev[MAX_JS_PAIRS][4]
joint-stereo related variables
Definition: atrac3.c:99
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
ATRAC3 AKA RealAudio 8 compatible decoder data.
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:361
This structure stores compressed data.
Definition: packet.h:340
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:380
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
static int decode_tonal_components(GetBitContext *gb, TonalComponent *components, int num_bands)
Restore the quantized tonal components.
Definition: atrac3.c:331
int i
Definition: input.c:407
static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, ChannelUnit *snd, float *output, int channel_num, int coding_mode)
Decode a Sound Unit.
Definition: atrac3.c:578
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:190