Libav
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 Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
37 #include <stdint.h>
38 #include <string.h>
39 
41 #include "libavutil/float_dsp.h"
42 #include "avcodec.h"
43 #include "get_bits.h"
44 #include "internal.h"
45 #include "atrac.h"
46 #include "atrac3plus.h"
47 
48 typedef struct ATRAC3PContext {
51 
56 
60 
62 
65  uint64_t my_channel_layout;
67 
69 {
70  av_free(((ATRAC3PContext *)(avctx->priv_data))->ch_units);
71 
72  return 0;
73 }
74 
76  AVCodecContext *avctx)
77 {
78  memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
79 
80  switch (avctx->channels) {
81  case 1:
82  if (avctx->channel_layout != AV_CH_FRONT_LEFT)
84 
85  ctx->num_channel_blocks = 1;
86  ctx->channel_blocks[0] = CH_UNIT_MONO;
87  break;
88  case 2:
90  ctx->num_channel_blocks = 1;
92  break;
93  case 3:
95  ctx->num_channel_blocks = 2;
97  ctx->channel_blocks[1] = CH_UNIT_MONO;
98  break;
99  case 4:
101  ctx->num_channel_blocks = 3;
102  ctx->channel_blocks[0] = CH_UNIT_STEREO;
103  ctx->channel_blocks[1] = CH_UNIT_MONO;
104  ctx->channel_blocks[2] = CH_UNIT_MONO;
105  break;
106  case 6:
108  ctx->num_channel_blocks = 4;
109  ctx->channel_blocks[0] = CH_UNIT_STEREO;
110  ctx->channel_blocks[1] = CH_UNIT_MONO;
111  ctx->channel_blocks[2] = CH_UNIT_STEREO;
112  ctx->channel_blocks[3] = CH_UNIT_MONO;
113  break;
114  case 7:
116  ctx->num_channel_blocks = 5;
117  ctx->channel_blocks[0] = CH_UNIT_STEREO;
118  ctx->channel_blocks[1] = CH_UNIT_MONO;
119  ctx->channel_blocks[2] = CH_UNIT_STEREO;
120  ctx->channel_blocks[3] = CH_UNIT_MONO;
121  ctx->channel_blocks[4] = CH_UNIT_MONO;
122  break;
123  case 8:
125  ctx->num_channel_blocks = 5;
126  ctx->channel_blocks[0] = CH_UNIT_STEREO;
127  ctx->channel_blocks[1] = CH_UNIT_MONO;
128  ctx->channel_blocks[2] = CH_UNIT_STEREO;
129  ctx->channel_blocks[3] = CH_UNIT_STEREO;
130  ctx->channel_blocks[4] = CH_UNIT_MONO;
131  break;
132  default:
133  av_log(avctx, AV_LOG_ERROR,
134  "Unsupported channel count: %d!\n", avctx->channels);
135  return AVERROR_INVALIDDATA;
136  }
137 
138  return 0;
139 }
140 
142 {
143  ATRAC3PContext *ctx = avctx->priv_data;
144  int i, ch, ret;
145 
146  if (!avctx->block_align) {
147  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
148  return AVERROR(EINVAL);
149  }
150 
152 
153  /* initialize IPQF */
154  ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
155 
156  ff_atrac3p_init_imdct(avctx, &ctx->mdct_ctx);
157 
159 
161 
162  if ((ret = set_channel_params(ctx, avctx)) < 0)
163  return ret;
164 
165  ctx->my_channel_layout = avctx->channel_layout;
166 
167  ctx->ch_units = av_mallocz(sizeof(*ctx->ch_units) *
168  ctx->num_channel_blocks);
169  if (!ctx->ch_units) {
170  atrac3p_decode_close(avctx);
171  return AVERROR(ENOMEM);
172  }
173 
174  for (i = 0; i < ctx->num_channel_blocks; i++) {
175  for (ch = 0; ch < 2; ch++) {
176  ctx->ch_units[i].channels[ch].ch_num = ch;
177  ctx->ch_units[i].channels[ch].wnd_shape = &ctx->ch_units[i].channels[ch].wnd_shape_hist[0][0];
178  ctx->ch_units[i].channels[ch].wnd_shape_prev = &ctx->ch_units[i].channels[ch].wnd_shape_hist[1][0];
179  ctx->ch_units[i].channels[ch].gain_data = &ctx->ch_units[i].channels[ch].gain_data_hist[0][0];
180  ctx->ch_units[i].channels[ch].gain_data_prev = &ctx->ch_units[i].channels[ch].gain_data_hist[1][0];
181  ctx->ch_units[i].channels[ch].tones_info = &ctx->ch_units[i].channels[ch].tones_info_hist[0][0];
182  ctx->ch_units[i].channels[ch].tones_info_prev = &ctx->ch_units[i].channels[ch].tones_info_hist[1][0];
183  }
184 
185  ctx->ch_units[i].waves_info = &ctx->ch_units[i].wave_synth_hist[0];
186  ctx->ch_units[i].waves_info_prev = &ctx->ch_units[i].wave_synth_hist[1];
187  }
188 
190 
191  return 0;
192 }
193 
195  float out[2][ATRAC3P_FRAME_SAMPLES],
196  int num_channels,
197  AVCodecContext *avctx)
198 {
199  int i, sb, ch, qu, nspeclines, RNG_index;
200  float *dst, q;
201  int16_t *src;
202  /* calculate RNG table index for each subband */
203  int sb_RNG_index[ATRAC3P_SUBBANDS] = { 0 };
204 
205  if (ctx->mute_flag) {
206  for (ch = 0; ch < num_channels; ch++)
207  memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
208  return;
209  }
210 
211  for (qu = 0, RNG_index = 0; qu < ctx->used_quant_units; qu++)
212  RNG_index += ctx->channels[0].qu_sf_idx[qu] +
213  ctx->channels[1].qu_sf_idx[qu];
214 
215  for (sb = 0; sb < ctx->num_coded_subbands; sb++, RNG_index += 128)
216  sb_RNG_index[sb] = RNG_index & 0x3FC;
217 
218  /* inverse quant and power compensation */
219  for (ch = 0; ch < num_channels; ch++) {
220  /* clear channel's residual spectrum */
221  memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
222 
223  for (qu = 0; qu < ctx->used_quant_units; qu++) {
224  src = &ctx->channels[ch].spectrum[ff_atrac3p_qu_to_spec_pos[qu]];
225  dst = &out[ch][ff_atrac3p_qu_to_spec_pos[qu]];
226  nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
227  ff_atrac3p_qu_to_spec_pos[qu];
228 
229  if (ctx->channels[ch].qu_wordlen[qu] > 0) {
230  q = ff_atrac3p_sf_tab[ctx->channels[ch].qu_sf_idx[qu]] *
232  for (i = 0; i < nspeclines; i++)
233  dst[i] = src[i] * q;
234  }
235  }
236 
237  for (sb = 0; sb < ctx->num_coded_subbands; sb++)
238  ff_atrac3p_power_compensation(ctx, ch, &out[ch][0],
239  sb_RNG_index[sb], sb);
240  }
241 
242  if (ctx->unit_type == CH_UNIT_STEREO) {
243  for (sb = 0; sb < ctx->num_coded_subbands; sb++) {
244  if (ctx->swap_channels[sb]) {
245  for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
246  FFSWAP(float, out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
247  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
248  }
249 
250  /* flip coefficients' sign if requested */
251  if (ctx->negate_coeffs[sb])
252  for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
253  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
254  }
255  }
256 }
257 
259  int num_channels, AVCodecContext *avctx)
260 {
261  int ch, sb;
262 
263  for (ch = 0; ch < num_channels; ch++) {
264  for (sb = 0; sb < ch_unit->num_subbands; sb++) {
265  /* inverse transform and windowing */
266  ff_atrac3p_imdct(&ctx->fdsp, &ctx->mdct_ctx,
267  &ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
268  &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
269  (ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
270  ch_unit->channels[ch].wnd_shape[sb], sb);
271 
272  /* gain compensation and overlapping */
274  &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
275  &ch_unit->prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
276  &ch_unit->channels[ch].gain_data_prev[sb],
277  &ch_unit->channels[ch].gain_data[sb],
278  ATRAC3P_SUBBAND_SAMPLES,
279  &ctx->time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
280  }
281 
282  /* zero unused subbands in both output and overlapping buffers */
283  memset(&ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
284  0,
285  (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
286  ATRAC3P_SUBBAND_SAMPLES *
287  sizeof(ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
288  memset(&ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
289  0,
290  (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
291  ATRAC3P_SUBBAND_SAMPLES *
292  sizeof(ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
293 
294  /* resynthesize and add tonal signal */
295  if (ch_unit->waves_info->tones_present ||
296  ch_unit->waves_info_prev->tones_present) {
297  for (sb = 0; sb < ch_unit->num_subbands; sb++)
298  if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
299  ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
300  ff_atrac3p_generate_tones(ch_unit, &ctx->fdsp, ch, sb,
301  &ctx->time_buf[ch][sb * 128]);
302  }
303  }
304 
305  /* subband synthesis and acoustic signal output */
306  ff_atrac3p_ipqf(&ctx->ipqf_dct_ctx, &ch_unit->ipqf_ctx[ch],
307  &ctx->time_buf[ch][0], &ctx->outp_buf[ch][0]);
308  }
309 
310  /* swap window shape and gain control buffers. */
311  for (ch = 0; ch < num_channels; ch++) {
312  FFSWAP(uint8_t *, ch_unit->channels[ch].wnd_shape,
313  ch_unit->channels[ch].wnd_shape_prev);
314  FFSWAP(AtracGainInfo *, ch_unit->channels[ch].gain_data,
315  ch_unit->channels[ch].gain_data_prev);
316  FFSWAP(Atrac3pWavesData *, ch_unit->channels[ch].tones_info,
317  ch_unit->channels[ch].tones_info_prev);
318  }
319 
321 }
322 
323 static int atrac3p_decode_frame(AVCodecContext *avctx, void *data,
324  int *got_frame_ptr, AVPacket *avpkt)
325 {
326  ATRAC3PContext *ctx = avctx->priv_data;
327  AVFrame *frame = data;
328  int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
329  float **samples_p = (float **)frame->extended_data;
330 
332  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
333  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
334  return ret;
335  }
336 
337  if ((ret = init_get_bits8(&ctx->gb, avpkt->data, avpkt->size)) < 0)
338  return ret;
339 
340  if (get_bits1(&ctx->gb)) {
341  av_log(avctx, AV_LOG_ERROR, "Invalid start bit!\n");
342  return AVERROR_INVALIDDATA;
343  }
344 
345  while (get_bits_left(&ctx->gb) >= 2 &&
346  (ch_unit_id = get_bits(&ctx->gb, 2)) != CH_UNIT_TERMINATOR) {
347  if (ch_unit_id == CH_UNIT_EXTENSION) {
348  avpriv_report_missing_feature(avctx, "Channel unit extension");
349  return AVERROR_PATCHWELCOME;
350  }
351  if (ch_block >= ctx->num_channel_blocks ||
352  ctx->channel_blocks[ch_block] != ch_unit_id) {
353  av_log(avctx, AV_LOG_ERROR,
354  "Frame data doesn't match channel configuration!\n");
355  return AVERROR_INVALIDDATA;
356  }
357 
358  ctx->ch_units[ch_block].unit_type = ch_unit_id;
359  channels_to_process = ch_unit_id + 1;
360 
361  if ((ret = ff_atrac3p_decode_channel_unit(&ctx->gb,
362  &ctx->ch_units[ch_block],
363  channels_to_process,
364  avctx)) < 0)
365  return ret;
366 
367  decode_residual_spectrum(&ctx->ch_units[ch_block], ctx->samples,
368  channels_to_process, avctx);
369  reconstruct_frame(ctx, &ctx->ch_units[ch_block],
370  channels_to_process, avctx);
371 
372  for (i = 0; i < channels_to_process; i++)
373  memcpy(samples_p[out_ch_index + i], ctx->outp_buf[i],
374  ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p));
375 
376  ch_block++;
377  out_ch_index += channels_to_process;
378  }
379 
380  *got_frame_ptr = 1;
381 
382  return avctx->block_align;
383 }
384 
386  .name = "atrac3plus",
387  .long_name = NULL_IF_CONFIG_SMALL("ATRAC3+ (Adaptive TRansform Acoustic Coding 3+)"),
388  .type = AVMEDIA_TYPE_AUDIO,
389  .id = AV_CODEC_ID_ATRAC3P,
390  .priv_data_size = sizeof(ATRAC3PContext),
392  .init_static_data = ff_atrac3p_init_vlcs,
395 };
float prev_buf[2][ATRAC3P_FRAME_SAMPLES]
overlapping buffer
Definition: atrac3plus.h:153
float, planar
Definition: samplefmt.h:72
const float ff_atrac3p_sf_tab[64]
Definition: atrac3plusdsp.c:51
#define AV_CH_LAYOUT_7POINT1
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
Atrac3pWaveSynthParams wave_synth_hist[2]
waves synth history for two frames
Definition: atrac3plus.h:148
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 unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
Atrac3pChanUnitCtx * ch_units
global channel units
Definition: atrac3plusdec.c:61
#define AV_CH_LAYOUT_SURROUND
void ff_atrac3p_init_wave_synth(void)
Initialize sine waves synthesizer.
Definition: atrac3plusdsp.c:96
GetBitContext gb
Definition: atrac3plusdec.c:49
Atrac3pWavesData * tones_info_prev
Definition: atrac3plus.h:115
int num_coded_subbands
number of subbands with coded spectrum
Definition: atrac3plus.h:137
int size
Definition: avcodec.h:968
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:58
#define AV_CH_LAYOUT_4POINT0
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
Definition: atrac3plusdec.c:68
int num_wavs
number of sine waves in the group
Definition: atrac3plus.h:76
#define AV_CH_LAYOUT_STEREO
AVCodec.
Definition: avcodec.h:2790
int used_quant_units
number of quant units with coded spectrum
Definition: atrac3plus.h:136
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1822
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
Definition: atrac3plus.h:144
#define ATRAC3P_SUBBANDS
Global unit sizes.
Definition: atrac3plus.h:40
AtracGCContext gainc_ctx
gain compensation context
Definition: atrac3plusdec.c:57
AtracGainInfo * gain_data_prev
gain control data for previous frame
Definition: atrac3plus.h:109
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1793
uint8_t
#define av_cold
Definition: attributes.h:66
int16_t spectrum[2048]
decoded IMDCT spectrum
Definition: atrac3plus.h:98
float mdct_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the IMDCT
Definition: atrac3plusdec.c:53
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, int num_channels, AVCodecContext *avctx)
#define ATRAC3P_FRAME_SAMPLES
Definition: atrac3plus.h:42
const char data[16]
Definition: mxf.c:70
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 * data
Definition: avcodec.h:967
ATRAC common header.
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
Definition: atrac3plus.h:96
bitstream reader API header.
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:658
static void decode_residual_spectrum(Atrac3pChanUnitCtx *ctx, float out[2][ATRAC3P_FRAME_SAMPLES], int num_channels, AVCodecContext *avctx)
uint8_t * wnd_shape
IMDCT window shape for current frame.
Definition: atrac3plus.h:103
void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn, float *pOut, int wind_id, int sb)
Regular IMDCT and windowing without overlapping, with spectrum reversal in the odd subbands...
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:555
av_cold void ff_atrac3p_init_vlcs(AVCodec *codec)
Initialize VLC tables for bitstream parsing.
Definition: atrac3plus.c:83
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
int num_channel_blocks
number of channel blocks
Definition: atrac3plusdec.c:63
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
Definition: atrac3plus.h:104
void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist, const float *in, float *out)
Subband synthesis filter based on the polyphase quadrature (pseudo-QMF) filter bank.
Parameters of a group of sine waves.
Definition: atrac3plus.h:73
static av_cold int set_channel_params(ATRAC3PContext *ctx, AVCodecContext *avctx)
Definition: atrac3plusdec.c:75
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1138
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:168
const char * name
Name of the codec implementation.
Definition: avcodec.h:2797
#define ff_mdct_init
Definition: fft.h:151
static const float qu[2]
Definition: sipr16kdata.h:28
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
Gain compensation context structure.
Definition: atrac.h:44
int qu_wordlen[32]
array of word lengths for each quant unit
Definition: atrac3plus.h:95
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, int loc_scale)
Initialize gain compensation context.
Definition: atrac.c:66
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1846
#define ATRAC3P_SUBBAND_SAMPLES
number of samples per subband
Definition: atrac3plus.h:41
float samples[2][ATRAC3P_FRAME_SAMPLES]
quantized MDCT spectrum
Definition: atrac3plusdec.c:52
Definition: fft.h:73
unit containing one coded channel
Definition: atrac3plus.h:51
audio channel layout utility functions
float time_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the gain compensation
Definition: atrac3plusdec.c:54
Atrac3pWavesData * tones_info
Definition: atrac3plus.h:114
int unit_type
unit type (mono/stereo)
Definition: atrac3plus.h:133
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
Definition: atrac3plus.h:143
#define AV_CH_LAYOUT_5POINT1_BACK
#define AV_CH_LAYOUT_6POINT1_BACK
if(ac->has_optimized_func)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
uint8_t channel_blocks[5]
channel configuration descriptor
Definition: atrac3plusdec.c:64
void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
Initialize IMDCT transform.
Definition: atrac3plusdsp.c:79
Gain control parameters for one subband.
Definition: atrac.h:35
Libavcodec external API header.
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
float outp_buf[2][ATRAC3P_FRAME_SAMPLES]
Definition: atrac3plusdec.c:55
AVCodec ff_atrac3p_decoder
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:408
static int atrac3p_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
main external API structure.
Definition: avcodec.h:1044
#define AV_CH_FRONT_LEFT
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
Atrac3pIPQFChannelCtx ipqf_ctx[2]
Definition: atrac3plus.h:152
Channel unit parameters.
Definition: atrac3plus.h:131
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:603
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
unit sequence terminator
Definition: atrac3plus.h:54
const float ff_atrac3p_mant_tab[8]
Definition: atrac3plusdsp.c:66
Atrac3pWaveSynthParams * waves_info_prev
Definition: atrac3plus.h:150
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
av_cold void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
Definition: float_dsp.c:115
uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS]
IMDCT window shape, 0=sine/1=steep.
Definition: atrac3plus.h:102
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_dlog(ac->avr,"%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
common internal api header.
AtracGainInfo * gain_data
gain control data for next frame
Definition: atrac3plus.h:108
FFTContext mdct_ctx
Definition: atrac3plusdec.c:58
unit containing two jointly-coded channels
Definition: atrac3plus.h:52
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
AVFloatDSPContext fdsp
Definition: atrac3plusdec.c:50
Atrac3pWaveSynthParams * waves_info
Definition: atrac3plus.h:149
void * priv_data
Definition: avcodec.h:1086
void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index, float *sp, int rng_index, int sb_num)
Perform power compensation aka noise dithering.
int channels
number of audio channels
Definition: avcodec.h:1786
Atrac3pChanParams channels[2]
Definition: atrac3plus.h:145
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
uint64_t my_channel_layout
current channel layout
Definition: atrac3plusdec.c:65
int mute_flag
mute flag
Definition: atrac3plus.h:138
#define FFSWAP(type, a, b)
Definition: common.h:60
int tones_present
1 - tones info present
Definition: atrac3plus.h:120
FFTContext ipqf_dct_ctx
IDCT context used by IPQF.
Definition: atrac3plusdec.c:59
unit containing extension information
Definition: atrac3plus.h:53
Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS]
Definition: atrac3plus.h:113
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:169
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
Definition: avcodec.h:944
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:179
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
Global structures, constants and data for ATRAC3+ decoder.
for(j=16;j >0;--j)
AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS]
gain control data for all subbands
Definition: atrac3plus.h:107