58 { 0, 1, 2, 4, 5, 3, },
59 { 0, 1, 2, 4, 5, 6, 3, },
60 { 0, 1, 2, 4, 5, 6, 7, 3, },
102 memset(
ctx->channel_blocks, 0,
sizeof(
ctx->channel_blocks));
108 ctx->num_channel_blocks = 1;
113 ctx->num_channel_blocks = 1;
118 ctx->num_channel_blocks = 2;
124 ctx->num_channel_blocks = 3;
131 ctx->num_channel_blocks = 4;
139 ctx->num_channel_blocks = 5;
148 ctx->num_channel_blocks = 5;
157 "Unsupported channel count: %d!\n",
channels);
185 scale = 32.0 / 32768.0;
205 if (!
ctx->ch_units || !
ctx->fdsp) {
209 for (
i = 0;
i <
ctx->num_channel_blocks;
i++) {
210 for (ch = 0; ch < 2; ch++) {
211 ctx->ch_units[
i].channels[ch].ch_num = ch;
212 ctx->ch_units[
i].channels[ch].wnd_shape = &
ctx->ch_units[
i].channels[ch].wnd_shape_hist[0][0];
213 ctx->ch_units[
i].channels[ch].wnd_shape_prev = &
ctx->ch_units[
i].channels[ch].wnd_shape_hist[1][0];
214 ctx->ch_units[
i].channels[ch].gain_data = &
ctx->ch_units[
i].channels[ch].gain_data_hist[0][0];
215 ctx->ch_units[
i].channels[ch].gain_data_prev = &
ctx->ch_units[
i].channels[ch].gain_data_hist[1][0];
216 ctx->ch_units[
i].channels[ch].tones_info = &
ctx->ch_units[
i].channels[ch].tones_info_hist[0][0];
217 ctx->ch_units[
i].channels[ch].tones_info_prev = &
ctx->ch_units[
i].channels[ch].tones_info_hist[1][0];
220 ctx->ch_units[
i].waves_info = &
ctx->ch_units[
i].wave_synth_hist[0];
221 ctx->ch_units[
i].waves_info_prev = &
ctx->ch_units[
i].wave_synth_hist[1];
236 int i, sb, ch,
qu, nspeclines, RNG_index;
243 for (ch = 0; ch < num_channels; ch++)
253 sb_RNG_index[sb] = RNG_index & 0x3FC;
256 for (ch = 0; ch < num_channels; ch++) {
269 for (
i = 0;
i < nspeclines;
i++)
276 sb_RNG_index[sb], sb);
300 for (ch = 0; ch < num_channels; ch++) {
338 &
ctx->time_buf[ch][sb * 128]);
345 &
ctx->outp_buf[ch][0]);
349 for (ch = 0; ch < num_channels; ch++) {
362 int *got_frame_ptr,
AVPacket *avpkt)
365 int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
366 float **samples_p = (
float **)
frame->extended_data;
386 if (ch_block >=
ctx->num_channel_blocks ||
387 ctx->channel_blocks[ch_block] != ch_unit_id) {
389 "Frame data doesn't match channel configuration!\n");
393 ctx->ch_units[ch_block].unit_type = ch_unit_id;
394 channels_to_process = ch_unit_id + 1;
397 &
ctx->ch_units[ch_block],
403 channels_to_process, avctx);
405 channels_to_process, avctx);
407 for (
i = 0;
i < channels_to_process;
i++)
408 memcpy(samples_p[
ctx->channel_map[out_ch_index +
i]],
ctx->outp_buf[
i],
412 out_ch_index += channels_to_process;
421 .p.name =
"atrac3plus",
434 .p.name =
"atrac3plusal",
435 CODEC_LONG_NAME(
"ATRAC3+ AL (Adaptive TRansform Acoustic Coding 3+ Advanced Lossless)"),
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_atrac3pal_decoder
const FFCodec ff_atrac3p_decoder
static av_cold void close(AVCodecParserContext *s)
av_cold void ff_atrac3p_init_vlcs(void)
Initialize VLC tables for bitstream parsing.
int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx, int num_channels, AVCodecContext *avctx)
Decode bitstream data of a channel unit.
Global structures, constants and data for ATRAC3+ decoder.
void ff_atrac3p_init_dsp_static(void)
Initialize sine waves synthesizer and ff_sine_* tables.
const uint16_t ff_atrac3p_qu_to_spec_pos[33]
Map quant unit number to its position in the spectrum.
#define ATRAC3P_FRAME_SAMPLES
#define ATRAC3P_SUBBAND_SAMPLES
number of samples per subband
const float ff_atrac3p_mant_tab[8]
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.
const float ff_atrac3p_sf_tab[64]
void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp, int ch_num, int sb, float *out)
Synthesize sine waves for a particular subband.
#define ATRAC3P_SUBBANDS
Global unit sizes.
@ CH_UNIT_TERMINATOR
unit sequence terminator
@ CH_UNIT_EXTENSION
unit containing extension information
@ CH_UNIT_STEREO
unit containing two jointly-coded channels
@ CH_UNIT_MONO
unit containing one coded channel
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.
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.
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
static int atrac3p_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static av_cold int set_channel_params(ATRAC3PContext *ctx, AVCodecContext *avctx)
static const uint8_t channel_map[8][8]
static void decode_residual_spectrum(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, float out[2][ATRAC3P_FRAME_SAMPLES], int num_channels, AVCodecContext *avctx)
static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit, int num_channels, AVCodecContext *avctx)
static av_cold void atrac3p_init_static(void)
static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
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.
av_cold void ff_atrac_init_gain_compensation(AtracGCContext *gctx, int id2exp_offset, int loc_scale)
Initialize gain compensation context.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
bitstream reader API header.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CHANNEL_LAYOUT_4POINT0
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_6POINT1_BACK
#define AV_CHANNEL_LAYOUT_MONO
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_7POINT1
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_SAMPLE_FMT_FLTP
float, planar
static void scale(int *out, const int *in, const int w, const int h, const int shift)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int ff_thread_once(char *control, void(*routine)(void))
#define FFSWAP(type, a, b)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
float outp_buf[2][ATRAC3P_FRAME_SAMPLES]
AVTXContext * ipqf_dct_ctx
IDCT context used by IPQF.
Atrac3pChanUnitCtx * ch_units
global channel units
float time_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the gain compensation
const uint8_t * channel_map
channel layout map
int num_channel_blocks
number of channel blocks
AtracGCContext gainc_ctx
gain compensation context
float mdct_buf[2][ATRAC3P_FRAME_SAMPLES]
output of the IMDCT
float samples[2][ATRAC3P_FRAME_SAMPLES]
quantized MDCT spectrum
uint8_t channel_blocks[5]
channel configuration descriptor
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
main external API structure.
AVChannelLayout ch_layout
Audio channel layout.
enum AVSampleFormat sample_fmt
audio sample format
int flags
AV_CODEC_FLAG_*.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
int qu_sf_idx[32]
array of scale factor indexes for each quant unit
int qu_wordlen[32]
array of word lengths for each quant unit
uint8_t * wnd_shape
IMDCT window shape for current frame.
AtracGainInfo * gain_data_prev
gain control data for previous frame
int16_t spectrum[2048]
decoded IMDCT spectrum
uint8_t * wnd_shape_prev
IMDCT window shape for previous frame.
AtracGainInfo * gain_data
gain control data for next frame
Atrac3pWavesData * tones_info
Atrac3pWavesData * tones_info_prev
Atrac3pWaveSynthParams * waves_info
float prev_buf[2][ATRAC3P_FRAME_SAMPLES]
overlapping buffer
uint8_t swap_channels[ATRAC3P_SUBBANDS]
1 - perform subband-wise channel swapping
uint8_t negate_coeffs[ATRAC3P_SUBBANDS]
1 - subband-wise IMDCT coefficients negation
int used_quant_units
number of quant units with coded spectrum
Atrac3pChanParams channels[2]
Atrac3pIPQFChannelCtx ipqf_ctx[2]
Atrac3pWaveSynthParams * waves_info_prev
int num_coded_subbands
number of subbands with coded spectrum
int unit_type
unit type (mono/stereo)
int tones_present
1 - tones info present
Parameters of a group of sine waves.
int num_wavs
number of sine waves in the group
Gain compensation context structure.
Gain control parameters for one subband.
static AVFormatContext * ctx
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
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...
@ AV_TX_FULL_IMDCT
Performs a full inverse MDCT rather than leaving out samples that can be derived through symmetry.
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respectively.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.