FFmpeg
atrac3plusdec.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  * Sony ATRAC3+ compatible decoder.
26  *
27  * Container formats used to store its data:
28  * RIFF WAV (.at3) and Sony OpenMG (.oma, .aa3).
29  *
30  * Technical description of this codec can be found here:
31  * http://wiki.multimedia.cx/index.php?title=ATRAC3plus
32  *
33  * Kudos to Benjamin Larsson and Michael Karcher
34  * for their precious technical help!
35  */
36 
37 #include <stdint.h>
38 #include <string.h>
39 
41 #include "libavutil/float_dsp.h"
42 #include "libavutil/mem_internal.h"
43 #include "libavutil/thread.h"
44 #include "avcodec.h"
45 #include "codec_internal.h"
46 #include "decode.h"
47 #include "get_bits.h"
48 #include "atrac.h"
49 #include "atrac3plus.h"
50 
51 static const uint8_t channel_map[8][8] = {
52  { 0, },
53  { 0, 1, },
54  { 0, 1, 2, },
55  { 0, 1, 2, 3, },
56  { 0, },
57  { 0, 1, 2, 4, 5, 3, },
58  { 0, 1, 2, 4, 5, 6, 3, },
59  { 0, 1, 2, 4, 5, 6, 7, 3, },
60 };
61 
62 typedef struct ATRAC3PContext {
65 
66  DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES]; ///< quantized MDCT spectrum
67  DECLARE_ALIGNED(32, float, mdct_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the IMDCT
68  DECLARE_ALIGNED(32, float, time_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the gain compensation
70 
71  AtracGCContext gainc_ctx; ///< gain compensation context
74  AVTXContext *ipqf_dct_ctx; ///< IDCT context used by IPQF
76 
77  Atrac3pChanUnitCtx *ch_units; ///< global channel units
78 
79  int num_channel_blocks; ///< number of channel blocks
80  uint8_t channel_blocks[5]; ///< channel configuration descriptor
81  const uint8_t *channel_map; ///< channel layout map
83 
85 {
86  ATRAC3PContext *ctx = avctx->priv_data;
87 
88  av_freep(&ctx->ch_units);
89  av_freep(&ctx->fdsp);
90 
91  av_tx_uninit(&ctx->mdct_ctx);
92  av_tx_uninit(&ctx->ipqf_dct_ctx);
93 
94  return 0;
95 }
96 
98  AVCodecContext *avctx)
99 {
100  int channels = avctx->ch_layout.nb_channels;
101  memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
102 
104  switch (channels) {
105  case 1:
107  ctx->num_channel_blocks = 1;
108  ctx->channel_blocks[0] = CH_UNIT_MONO;
109  break;
110  case 2:
112  ctx->num_channel_blocks = 1;
113  ctx->channel_blocks[0] = CH_UNIT_STEREO;
114  break;
115  case 3:
117  ctx->num_channel_blocks = 2;
118  ctx->channel_blocks[0] = CH_UNIT_STEREO;
119  ctx->channel_blocks[1] = CH_UNIT_MONO;
120  break;
121  case 4:
123  ctx->num_channel_blocks = 3;
124  ctx->channel_blocks[0] = CH_UNIT_STEREO;
125  ctx->channel_blocks[1] = CH_UNIT_MONO;
126  ctx->channel_blocks[2] = CH_UNIT_MONO;
127  break;
128  case 6:
130  ctx->num_channel_blocks = 4;
131  ctx->channel_blocks[0] = CH_UNIT_STEREO;
132  ctx->channel_blocks[1] = CH_UNIT_MONO;
133  ctx->channel_blocks[2] = CH_UNIT_STEREO;
134  ctx->channel_blocks[3] = CH_UNIT_MONO;
135  break;
136  case 7:
138  ctx->num_channel_blocks = 5;
139  ctx->channel_blocks[0] = CH_UNIT_STEREO;
140  ctx->channel_blocks[1] = CH_UNIT_MONO;
141  ctx->channel_blocks[2] = CH_UNIT_STEREO;
142  ctx->channel_blocks[3] = CH_UNIT_MONO;
143  ctx->channel_blocks[4] = CH_UNIT_MONO;
144  break;
145  case 8:
147  ctx->num_channel_blocks = 5;
148  ctx->channel_blocks[0] = CH_UNIT_STEREO;
149  ctx->channel_blocks[1] = CH_UNIT_MONO;
150  ctx->channel_blocks[2] = CH_UNIT_STEREO;
151  ctx->channel_blocks[3] = CH_UNIT_STEREO;
152  ctx->channel_blocks[4] = CH_UNIT_MONO;
153  break;
154  default:
155  av_log(avctx, AV_LOG_ERROR,
156  "Unsupported channel count: %d!\n", channels);
157  return AVERROR_INVALIDDATA;
158  }
159 
160  ctx->channel_map = channel_map[channels - 1];
161 
162  return 0;
163 }
164 
165 static av_cold void atrac3p_init_static(void)
166 {
169 }
170 
172 {
173  static AVOnce init_static_once = AV_ONCE_INIT;
174  ATRAC3PContext *ctx = avctx->priv_data;
175  float scale;
176  int i, ch, ret;
177 
178  if (!avctx->block_align) {
179  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
180  return AVERROR(EINVAL);
181  }
182 
183  /* initialize IPQF */
184  scale = 32.0 / 32768.0;
185  ret = av_tx_init(&ctx->ipqf_dct_ctx, &ctx->ipqf_dct_fn, AV_TX_FLOAT_MDCT,
186  1, 16, &scale, 0);
187  if (ret < 0)
188  return ret;
189 
190  scale = -1.0f;
191  ret = av_tx_init(&ctx->mdct_ctx, &ctx->mdct_fn, AV_TX_FLOAT_MDCT,
192  1, 128, &scale, AV_TX_FULL_IMDCT);
193  if (ret < 0)
194  return ret;
195 
196  ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
197 
198  if ((ret = set_channel_params(ctx, avctx)) < 0)
199  return ret;
200 
201  ctx->ch_units = av_calloc(ctx->num_channel_blocks, sizeof(*ctx->ch_units));
203 
204  if (!ctx->ch_units || !ctx->fdsp) {
205  return AVERROR(ENOMEM);
206  }
207 
208  for (i = 0; i < ctx->num_channel_blocks; i++) {
209  for (ch = 0; ch < 2; ch++) {
210  ctx->ch_units[i].channels[ch].ch_num = ch;
211  ctx->ch_units[i].channels[ch].wnd_shape = &ctx->ch_units[i].channels[ch].wnd_shape_hist[0][0];
212  ctx->ch_units[i].channels[ch].wnd_shape_prev = &ctx->ch_units[i].channels[ch].wnd_shape_hist[1][0];
213  ctx->ch_units[i].channels[ch].gain_data = &ctx->ch_units[i].channels[ch].gain_data_hist[0][0];
214  ctx->ch_units[i].channels[ch].gain_data_prev = &ctx->ch_units[i].channels[ch].gain_data_hist[1][0];
215  ctx->ch_units[i].channels[ch].tones_info = &ctx->ch_units[i].channels[ch].tones_info_hist[0][0];
216  ctx->ch_units[i].channels[ch].tones_info_prev = &ctx->ch_units[i].channels[ch].tones_info_hist[1][0];
217  }
218 
219  ctx->ch_units[i].waves_info = &ctx->ch_units[i].wave_synth_hist[0];
220  ctx->ch_units[i].waves_info_prev = &ctx->ch_units[i].wave_synth_hist[1];
221  }
222 
224 
225  ff_thread_once(&init_static_once, atrac3p_init_static);
226 
227  return 0;
228 }
229 
231  float out[2][ATRAC3P_FRAME_SAMPLES],
232  int num_channels,
233  AVCodecContext *avctx)
234 {
235  int i, sb, ch, qu, nspeclines, RNG_index;
236  float *dst, q;
237  int16_t *src;
238  /* calculate RNG table index for each subband */
239  int sb_RNG_index[ATRAC3P_SUBBANDS] = { 0 };
240 
241  if (ch_unit->mute_flag) {
242  for (ch = 0; ch < num_channels; ch++)
243  memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
244  return;
245  }
246 
247  for (qu = 0, RNG_index = 0; qu < ch_unit->used_quant_units; qu++)
248  RNG_index += ch_unit->channels[0].qu_sf_idx[qu] +
249  ch_unit->channels[1].qu_sf_idx[qu];
250 
251  for (sb = 0; sb < ch_unit->num_coded_subbands; sb++, RNG_index += 128)
252  sb_RNG_index[sb] = RNG_index & 0x3FC;
253 
254  /* inverse quant and power compensation */
255  for (ch = 0; ch < num_channels; ch++) {
256  /* clear channel's residual spectrum */
257  memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
258 
259  for (qu = 0; qu < ch_unit->used_quant_units; qu++) {
261  dst = &out[ch][ff_atrac3p_qu_to_spec_pos[qu]];
262  nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
264 
265  if (ch_unit->channels[ch].qu_wordlen[qu] > 0) {
266  q = ff_atrac3p_sf_tab[ch_unit->channels[ch].qu_sf_idx[qu]] *
267  ff_atrac3p_mant_tab[ch_unit->channels[ch].qu_wordlen[qu]];
268  for (i = 0; i < nspeclines; i++)
269  dst[i] = src[i] * q;
270  }
271  }
272 
273  for (sb = 0; sb < ch_unit->num_coded_subbands; sb++)
274  ff_atrac3p_power_compensation(ch_unit, ctx->fdsp, ch, &out[ch][0],
275  sb_RNG_index[sb], sb);
276  }
277 
278  if (ch_unit->unit_type == CH_UNIT_STEREO) {
279  for (sb = 0; sb < ch_unit->num_coded_subbands; sb++) {
280  if (ch_unit->swap_channels[sb]) {
281  for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
282  FFSWAP(float, out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
283  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
284  }
285 
286  /* flip coefficients' sign if requested */
287  if (ch_unit->negate_coeffs[sb])
288  for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
289  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
290  }
291  }
292 }
293 
295  int num_channels, AVCodecContext *avctx)
296 {
297  int ch, sb;
298 
299  for (ch = 0; ch < num_channels; ch++) {
300  for (sb = 0; sb < ch_unit->num_subbands; sb++) {
301  /* inverse transform and windowing */
302  ff_atrac3p_imdct(ctx->fdsp, ctx->mdct_ctx, ctx->mdct_fn,
303  &ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
304  &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
305  (ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
306  ch_unit->channels[ch].wnd_shape[sb], sb);
307 
308  /* gain compensation and overlapping */
309  ff_atrac_gain_compensation(&ctx->gainc_ctx,
310  &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
311  &ch_unit->prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
312  &ch_unit->channels[ch].gain_data_prev[sb],
313  &ch_unit->channels[ch].gain_data[sb],
315  &ctx->time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
316  }
317 
318  /* zero unused subbands in both output and overlapping buffers */
319  memset(&ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
320  0,
321  (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
323  sizeof(ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
324  memset(&ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
325  0,
326  (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
328  sizeof(ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
329 
330  /* resynthesize and add tonal signal */
331  if (ch_unit->waves_info->tones_present ||
332  ch_unit->waves_info_prev->tones_present) {
333  for (sb = 0; sb < ch_unit->num_subbands; sb++)
334  if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
335  ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
336  ff_atrac3p_generate_tones(ch_unit, ctx->fdsp, ch, sb,
337  &ctx->time_buf[ch][sb * 128]);
338  }
339  }
340 
341  /* subband synthesis and acoustic signal output */
342  ff_atrac3p_ipqf(ctx->ipqf_dct_ctx, ctx->ipqf_dct_fn,
343  &ch_unit->ipqf_ctx[ch], &ctx->time_buf[ch][0],
344  &ctx->outp_buf[ch][0]);
345  }
346 
347  /* swap window shape and gain control buffers. */
348  for (ch = 0; ch < num_channels; ch++) {
349  FFSWAP(uint8_t *, ch_unit->channels[ch].wnd_shape,
350  ch_unit->channels[ch].wnd_shape_prev);
351  FFSWAP(AtracGainInfo *, ch_unit->channels[ch].gain_data,
352  ch_unit->channels[ch].gain_data_prev);
353  FFSWAP(Atrac3pWavesData *, ch_unit->channels[ch].tones_info,
354  ch_unit->channels[ch].tones_info_prev);
355  }
356 
358 }
359 
361  int *got_frame_ptr, AVPacket *avpkt)
362 {
363  ATRAC3PContext *ctx = avctx->priv_data;
364  int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
365  float **samples_p = (float **)frame->extended_data;
366 
368  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
369  return ret;
370 
371  if ((ret = init_get_bits8(&ctx->gb, avpkt->data, avpkt->size)) < 0)
372  return ret;
373 
374  if (get_bits1(&ctx->gb)) {
375  av_log(avctx, AV_LOG_ERROR, "Invalid start bit!\n");
376  return AVERROR_INVALIDDATA;
377  }
378 
379  while (get_bits_left(&ctx->gb) >= 2 &&
380  (ch_unit_id = get_bits(&ctx->gb, 2)) != CH_UNIT_TERMINATOR) {
381  if (ch_unit_id == CH_UNIT_EXTENSION) {
382  avpriv_report_missing_feature(avctx, "Channel unit extension");
383  return AVERROR_PATCHWELCOME;
384  }
385  if (ch_block >= ctx->num_channel_blocks ||
386  ctx->channel_blocks[ch_block] != ch_unit_id) {
387  av_log(avctx, AV_LOG_ERROR,
388  "Frame data doesn't match channel configuration!\n");
389  return AVERROR_INVALIDDATA;
390  }
391 
392  ctx->ch_units[ch_block].unit_type = ch_unit_id;
393  channels_to_process = ch_unit_id + 1;
394 
396  &ctx->ch_units[ch_block],
397  channels_to_process,
398  avctx)) < 0)
399  return ret;
400 
401  decode_residual_spectrum(ctx, &ctx->ch_units[ch_block], ctx->samples,
402  channels_to_process, avctx);
403  reconstruct_frame(ctx, &ctx->ch_units[ch_block],
404  channels_to_process, avctx);
405 
406  for (i = 0; i < channels_to_process; i++)
407  memcpy(samples_p[ctx->channel_map[out_ch_index + i]], ctx->outp_buf[i],
408  ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p));
409 
410  ch_block++;
411  out_ch_index += channels_to_process;
412  }
413 
414  *got_frame_ptr = 1;
415 
416  return avctx->codec_id == AV_CODEC_ID_ATRAC3P ? FFMIN(avctx->block_align, avpkt->size) : avpkt->size;
417 }
418 
420  .p.name = "atrac3plus",
421  CODEC_LONG_NAME("ATRAC3+ (Adaptive TRansform Acoustic Coding 3+)"),
422  .p.type = AVMEDIA_TYPE_AUDIO,
423  .p.id = AV_CODEC_ID_ATRAC3P,
424  .p.capabilities = AV_CODEC_CAP_DR1,
425  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
426  .priv_data_size = sizeof(ATRAC3PContext),
428  .close = atrac3p_decode_close,
430 };
431 
433  .p.name = "atrac3plusal",
434  CODEC_LONG_NAME("ATRAC3+ AL (Adaptive TRansform Acoustic Coding 3+ Advanced Lossless)"),
435  .p.type = AVMEDIA_TYPE_AUDIO,
436  .p.id = AV_CODEC_ID_ATRAC3PAL,
437  .p.capabilities = AV_CODEC_CAP_DR1,
438  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
439  .priv_data_size = sizeof(ATRAC3PContext),
441  .close = atrac3p_decode_close,
443 };
Atrac3pChanUnitCtx::waves_info
Atrac3pWaveSynthParams * waves_info
Definition: atrac3plus.h:151
ATRAC3PContext::channel_map
const uint8_t * channel_map
channel layout map
Definition: atrac3plusdec.c:81
ff_atrac3p_init_dsp_static
void ff_atrac3p_init_dsp_static(void)
Initialize sine waves synthesizer and ff_sine_* tables.
Definition: atrac3plusdsp.c:88
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
AVERROR
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
Atrac3pChanParams::tones_info_prev
Atrac3pWavesData * tones_info_prev
Definition: atrac3plus.h:117
mem_internal.h
out
FILE * out
Definition: movenc.c:54
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:383
thread.h
Atrac3pWavesData::num_wavs
int num_wavs
number of sine waves in the group
Definition: atrac3plus.h:78
AVTXContext
Definition: tx_priv.h:235
ATRAC3PContext::gainc_ctx
AtracGCContext gainc_ctx
gain compensation context
Definition: atrac3plusdec.c:71
atrac3p_decode_close
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
Definition: atrac3plusdec.c:84
reconstruct_frame
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, int num_channels, AVCodecContext *avctx)
Definition: atrac3plusdec.c:294
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVPacket::data
uint8_t * data
Definition: packet.h:491
Atrac3pChanUnitCtx::ipqf_ctx
Atrac3pIPQFChannelCtx ipqf_ctx[2]
Definition: atrac3plus.h:154
ff_atrac3p_generate_tones
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
Definition: atrac3plusdsp.c:178
ATRAC3PContext::ch_units
Atrac3pChanUnitCtx * ch_units
global channel units
Definition: atrac3plusdec.c:77
atrac3p_init_static
static av_cold void atrac3p_init_static(void)
Definition: atrac3plusdec.c:165
FFCodec
Definition: codec_internal.h:127
ff_atrac3p_power_compensation
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, AVFloatDSPContext *fdsp, int ch_index, float *sp, int rng_index, int sb_num)
Perform power compensation aka noise dithering.
Definition: atrac3plusdsp.c:412
ATRAC3PContext
Definition: atrac3plusdec.c:62
AV_CODEC_ID_ATRAC3PAL
@ AV_CODEC_ID_ATRAC3PAL
Definition: codec_id.h:525
Atrac3pChanUnitCtx::negate_coeffs
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
Definition: atrac3plus.h:146
ATRAC3PContext::mdct_buf
float mdct_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the IMDCT
Definition: atrac3plusdec.c:67
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
atrac3p_decode_frame
static int atrac3p_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: atrac3plusdec.c:360
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:901
ATRAC3P_FRAME_SAMPLES
#define ATRAC3P_FRAME_SAMPLES
Definition: atrac3plus.h:44
CH_UNIT_EXTENSION
@ CH_UNIT_EXTENSION
unit containing extension information
Definition: atrac3plus.h:55
Atrac3pChanParams::wnd_shape
uint8_t * wnd_shape
IMDCT window shape for current frame.
Definition: atrac3plus.h:105
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
ATRAC3PContext::gb
GetBitContext gb
Definition: atrac3plusdec.c:63
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
decode_residual_spectrum
static void decode_residual_spectrum(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, float out[2][ATRAC3P_FRAME_SAMPLES], int num_channels, AVCodecContext *avctx)
Definition: atrac3plusdec.c:230
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2107
GetBitContext
Definition: get_bits.h:108
set_channel_params
static av_cold int set_channel_params(ATRAC3PContext *ctx, AVCodecContext *avctx)
Definition: atrac3plusdec.c:97
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
ff_atrac_init_gain_compensation
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, int loc_scale)
Initialize gain compensation context.
Definition: atrac.c:67
Atrac3pWaveSynthParams
Definition: atrac3plus.h:121
AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_SURROUND
Definition: channel_layout.h:386
atrac3p_decode_init
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
Definition: atrac3plusdec.c:171
ff_atrac3p_sf_tab
const float ff_atrac3p_sf_tab[64]
Definition: atrac3plusdsp.c:52
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:203
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_CODEC_ID_ATRAC3P
@ AV_CODEC_ID_ATRAC3P
Definition: codec_id.h:481
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
ATRAC3PContext::outp_buf
float outp_buf[2][ATRAC3P_FRAME_SAMPLES]
Definition: atrac3plusdec.c:69
Atrac3pChanUnitCtx::used_quant_units
int used_quant_units
number of quant units with coded spectrum
Definition: atrac3plus.h:138
AV_CHANNEL_LAYOUT_4POINT0
#define AV_CHANNEL_LAYOUT_4POINT0
Definition: channel_layout.h:388
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_7POINT1
Definition: channel_layout.h:405
CH_UNIT_MONO
@ CH_UNIT_MONO
unit containing one coded channel
Definition: atrac3plus.h:53
Atrac3pChanUnitCtx::num_coded_subbands
int num_coded_subbands
number of subbands with coded spectrum
Definition: atrac3plus.h:139
atrac.h
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AtracGCContext
Gain compensation context structure.
Definition: atrac.h:44
channels
channels
Definition: aptx.h:31
decode.h
get_bits.h
channel_map
static const uint8_t channel_map[8][8]
Definition: atrac3plusdec.c:51
ff_atrac3p_qu_to_spec_pos
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
Definition: atrac3plusdsp.c:42
Atrac3pChanUnitCtx::waves_info_prev
Atrac3pWaveSynthParams * waves_info_prev
Definition: atrac3plus.h:152
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:451
ff_atrac3p_mant_tab
const float ff_atrac3p_mant_tab[8]
Definition: atrac3plusdsp.c:67
if
if(ret)
Definition: filter_design.txt:179
AV_TX_FULL_IMDCT
@ AV_TX_FULL_IMDCT
Performs a full inverse MDCT rather than leaving out samples that can be derived through symmetry.
Definition: tx.h:175
CH_UNIT_TERMINATOR
@ CH_UNIT_TERMINATOR
unit sequence terminator
Definition: atrac3plus.h:56
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:201
ff_atrac3p_ipqf
void ff_atrac3p_ipqf(AVTXContext *dct_ctx, av_tx_fn dct_fn, Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) filter bank.
Definition: atrac3plusdsp.c:600
ATRAC3PContext::num_channel_blocks
int num_channel_blocks
number of channel blocks
Definition: atrac3plusdec.c:79
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
Atrac3pChanParams::gain_data_prev
AtracGainInfo * gain_data_prev
gain control data for previous frame
Definition: atrac3plus.h:111
Atrac3pChanParams::spectrum
int16_t spectrum[2048]
decoded IMDCT spectrum
Definition: atrac3plus.h:100
ATRAC3PContext::channel_blocks
uint8_t channel_blocks[5]
channel configuration descriptor
Definition: atrac3plusdec.c:80
AtracGainInfo
Gain control parameters for one subband.
Definition: atrac.h:35
Atrac3pChanParams::tones_info
Atrac3pWavesData * tones_info
Definition: atrac3plus.h:116
atrac3plus.h
ATRAC3PContext::fdsp
AVFloatDSPContext * fdsp
Definition: atrac3plusdec.c:64
AVOnce
#define AVOnce
Definition: thread.h:200
float_dsp.h
ATRAC3PContext::ipqf_dct_fn
av_tx_fn ipqf_dct_fn
Definition: atrac3plusdec.c:75
Atrac3pChanUnitCtx::channels
Atrac3pChanParams channels[2]
Definition: atrac3plus.h:147
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1617
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
ATRAC3PContext::ipqf_dct_ctx
AVTXContext * ipqf_dct_ctx
IDCT context used by IPQF.
Definition: atrac3plusdec.c:74
AVPacket::size
int size
Definition: packet.h:492
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:307
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:87
ff_atrac3pal_decoder
const FFCodec ff_atrac3pal_decoder
Definition: atrac3plusdec.c:432
ff_atrac3p_init_vlcs
av_cold void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
Definition: atrac3plus.c:76
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1080
Atrac3pChanParams::qu_sf_idx
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
Definition: atrac3plus.h:98
CH_UNIT_STEREO
@ CH_UNIT_STEREO
unit containing two jointly-coded channels
Definition: atrac3plus.h:54
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
AVFloatDSPContext
Definition: float_dsp.h:24
ATRAC3PContext::time_buf
float time_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the gain compensation
Definition: atrac3plusdec.c:68
ff_atrac3p_decode_channel_unit
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:1662
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
AV_CHANNEL_LAYOUT_6POINT1_BACK
#define AV_CHANNEL_LAYOUT_6POINT1_BACK
Definition: channel_layout.h:401
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
ATRAC3PContext::mdct_fn
av_tx_fn mdct_fn
Definition: atrac3plusdec.c:73
Atrac3pChanUnitCtx::unit_type
int unit_type
unit type (mono/stereo)
Definition: atrac3plus.h:135
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
ff_atrac3p_imdct
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, AVTXContext *mdct_ctx, av_tx_fn mdct_fn, float *pIn, float *pOut, int wind_id, int sb)
Regular IMDCT and windowing without overlapping, with spectrum reversal in the odd subbands.
Definition: atrac3plusdsp.c:458
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
avcodec.h
ret
ret
Definition: filter_design.txt:187
Atrac3pChanUnitCtx
Channel unit parameters.
Definition: atrac3plus.h:133
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1113
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
Atrac3pChanUnitCtx::prev_buf
float prev_buf[2][ATRAC3P_FRAME_SAMPLES]
overlapping buffer
Definition: atrac3plus.h:155
Atrac3pChanUnitCtx::mute_flag
int mute_flag
mute flag
Definition: atrac3plus.h:140
Atrac3pWaveSynthParams::tones_present
int tones_present
1 - tones info present
Definition: atrac3plus.h:122
Atrac3pChanUnitCtx::swap_channels
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
Definition: atrac3plus.h:145
AVCodecContext
main external API structure.
Definition: avcodec.h:441
ff_atrac_gain_compensation
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:85
channel_layout.h
Atrac3pWavesData
Parameters of a group of sine waves.
Definition: atrac3plus.h:75
Atrac3pChanUnitCtx::num_subbands
int num_subbands
Definition: atrac3plus.h:137
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:640
Atrac3pChanParams::wnd_shape_prev
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
Definition: atrac3plus.h:106
qu
static const float qu[2]
Definition: sipr16kdata.h:28
ATRAC3PContext::mdct_ctx
AVTXContext * mdct_ctx
Definition: atrac3plusdec.c:72
ATRAC3P_SUBBAND_SAMPLES
#define ATRAC3P_SUBBAND_SAMPLES
number of samples per subband
Definition: atrac3plus.h:43
ff_atrac3p_decoder
const FFCodec ff_atrac3p_decoder
Definition: atrac3plusdec.c:419
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:382
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
ATRAC3P_SUBBANDS
#define ATRAC3P_SUBBANDS
Global unit sizes.
Definition: atrac3plus.h:42
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:395
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
Atrac3pChanParams::qu_wordlen
int qu_wordlen[32]
array of word lengths for each quant unit
Definition: atrac3plus.h:97
Atrac3pChanParams::gain_data
AtracGainInfo * gain_data
gain control data for next frame
Definition: atrac3plus.h:110
ATRAC3PContext::samples
float samples[2][ATRAC3P_FRAME_SAMPLES]
quantized MDCT spectrum
Definition: atrac3plusdec.c:66