50 #define JOINT_STEREO 0x12
53 #define SAMPLES_PER_FRAME 1024
145 for (i = 0; i < 128; i++)
146 FFSWAP(
float, input[i], input[255 - i]);
163 uint32_t *output = (uint32_t *)out;
165 off = (intptr_t)input & 3;
166 buf = (
const uint32_t *)(input - off);
168 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
172 for (i = 0; i < bytes / 4; i++)
173 output[i] = c ^ buf[i];
187 for (i = 0, j = 255; i < 128; i++, j--) {
188 float wi = sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
189 float wj = sin(((j + 0.5) / 256.0 - 0.5) * M_PI) + 1.0;
190 float w = 0.5 * (wi * wi + wj * wj);
217 int coding_flag,
int *mantissas,
220 int i, code, huff_symb;
225 if (coding_flag != 0) {
230 for (i = 0; i < num_codes; i++) {
238 for (i = 0; i < num_codes; i++) {
250 for (i = 0; i < num_codes; i++) {
251 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector-1].table,
252 spectral_coeff_tab[selector-1].
bits, 3);
254 code = huff_symb >> 1;
260 for (i = 0; i < num_codes; i++) {
261 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector - 1].table,
262 spectral_coeff_tab[selector - 1].
bits, 3);
277 int num_subbands, coding_mode, i, j, first, last, subband_size;
278 int subband_vlc_index[32], sf_index[32];
286 for (i = 0; i <= num_subbands; i++)
287 subband_vlc_index[i] =
get_bits(gb, 3);
290 for (i = 0; i <= num_subbands; i++) {
291 if (subband_vlc_index[i] != 0)
295 for (i = 0; i <= num_subbands; i++) {
299 subband_size = last - first;
301 if (subband_vlc_index[i] != 0) {
306 mantissas, subband_size);
313 for (j = 0; first < last; first++, j++)
314 output[first] = mantissas[j] * scale_factor;
317 memset(output + first, 0, subband_size *
sizeof(*output));
337 int nb_components, coding_mode_selector, coding_mode;
338 int band_flags[4], mantissa[8];
339 int component_count = 0;
344 if (nb_components == 0)
347 coding_mode_selector =
get_bits(gb, 2);
348 if (coding_mode_selector == 2)
351 coding_mode = coding_mode_selector & 1;
353 for (i = 0; i < nb_components; i++) {
354 int coded_values_per_component, quant_step_index;
356 for (b = 0; b <= num_bands; b++)
359 coded_values_per_component =
get_bits(gb, 3);
362 if (quant_step_index <= 1)
365 if (coding_mode_selector == 3)
368 for (b = 0; b < (num_bands + 1) * 4; b++) {
369 int coded_components;
371 if (band_flags[b >> 2] == 0)
376 for (c = 0; c < coded_components; c++) {
378 int sf_index, coded_values, max_coded_values;
382 if (component_count >= 64)
388 coded_values = coded_values_per_component + 1;
389 coded_values =
FFMIN(max_coded_values, coded_values);
395 mantissa, coded_values);
400 for (m = 0; m < coded_values; m++)
401 cmp->
coef[m] = mantissa[m] * scale_factor;
408 return component_count;
425 for (i = 0; i <= num_bands; i++) {
434 if (cf && loc[cf] <= loc[cf - 1])
441 gain[i].num_gain_data = 0;
459 float g1, g2, gain_inc;
460 int i, j, num_data, start_loc, end_loc;
469 for (i = 0; i < 256; i++)
470 output[i] = input[i] * g1 + prev[i];
476 for (i = 0, j = 0; i < num_data; i++) {
478 end_loc = start_loc + 8;
485 for (; j < start_loc; j++)
486 output[j] = (input[j] * g1 + prev[j]) * g2;
489 for (; j < end_loc; j++) {
490 output[j] = (input[j] * g1 + prev[j]) * g2;
496 output[j] = input[j] * g1 + prev[j];
500 memcpy(prev, &input[256], 256 *
sizeof(*prev));
514 int i, j, last_pos = -1;
515 float *input, *output;
517 for (i = 0; i < num_components; i++) {
518 last_pos =
FFMAX(components[i].pos + components[i].num_coefs, last_pos);
519 input = components[i].
coef;
520 output = &spectrum[components[i].
pos];
522 for (j = 0; j < components[i].num_coefs; j++)
523 output[j] += input[j];
529 #define INTERPOLATE(old, new, nsample) \
530 ((old) + (nsample) * 0.125 * ((new) - (old)))
535 int i, nsample, band;
536 float mc1_l, mc1_r, mc2_l, mc2_r;
538 for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
539 int s1 = prev_code[i];
540 int s2 = curr_code[i];
551 for (; nsample < band + 8; nsample++) {
552 float c1 = su1[nsample];
553 float c2 = su2[nsample];
554 c2 = c1 *
INTERPOLATE(mc1_l, mc2_l, nsample - band) +
557 su2[nsample] = c1 * 2.0 -
c2;
564 for (; nsample < band + 256; nsample++) {
565 float c1 = su1[nsample];
566 float c2 = su2[nsample];
567 su1[nsample] = c2 * 2.0;
568 su2[nsample] = (c1 -
c2) * 2.0;
572 for (; nsample < band + 256; nsample++) {
573 float c1 = su1[nsample];
574 float c2 = su2[nsample];
575 su1[nsample] = (c1 +
c2) * 2.0;
576 su2[nsample] = c2 * -2.0;
581 for (; nsample < band + 256; nsample++) {
582 float c1 = su1[nsample];
583 float c2 = su2[nsample];
584 su1[nsample] = c1 +
c2;
585 su2[nsample] = c1 -
c2;
600 ch[0] = (index & 7) / 7.0;
601 ch[1] = sqrt(2 - ch[0] * ch[0]);
603 FFSWAP(
float, ch[0], ch[1]);
613 if (p3[1] != 7 || p3[3] != 7) {
617 for (band = 256; band < 4 * 256; band += 256) {
618 for (nsample = band; nsample < band + 8; nsample++) {
619 su1[nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample - band);
620 su2[nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample - band);
622 for(; nsample < band + 256; nsample++) {
623 su1[nsample] *= w[1][0];
624 su2[nsample] *= w[1][1];
640 int channel_num,
int coding_mode)
642 int band, ret, num_subbands, last_tonal, num_bands;
681 num_bands =
FFMAX((last_tonal + 256) >> 8, num_bands);
685 for (band = 0; band < 4; band++) {
687 if (band <= num_bands)
728 for (i = 0; i < avctx->
block_align / 2; i++, ptr1++, ptr2--)
738 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
753 for (i = 0; i < 4; i++) {
774 for (i = 0; i < avctx->
channels; i++) {
788 for (i = 0; i < avctx->
channels; i++) {
789 float *p1 = out_samples[i];
790 float *p2 = p1 + 256;
791 float *p3 = p2 + 256;
792 float *p4 = p3 + 256;
802 int *got_frame_ptr,
AVPacket *avpkt)
805 int buf_size = avpkt->
size;
810 if (buf_size < avctx->block_align) {
812 "Frame too small (%d bytes). Truncated file?\n", buf_size);
851 for (i = 0; i < 7; i++) {
861 for (i = 0; i < 16; i++)
864 for (i = -15; i < 16; i++)
871 int version, delay, samples_per_frame, frame_factor;
884 bytestream_get_le16(&edata_ptr));
888 bytestream_get_le16(&edata_ptr));
889 frame_factor = bytestream_get_le16(&edata_ptr);
891 bytestream_get_le16(&edata_ptr));
910 version = bytestream_get_be32(&edata_ptr);
911 samples_per_frame = bytestream_get_be16(&edata_ptr);
912 delay = bytestream_get_be16(&edata_ptr);
936 if (delay != 0x88E) {
979 for (i = 0; i < 4; i++) {
static const uint16_t atrac3_vlc_offs[9]
#define CODEC_FLAG_BITEXACT
This structure describes decoded (raw) audio or video data.
static void reverse_matrixing(float *su1, float *su2, int *prev_code, int *curr_code)
int matrix_coeff_index_next[4]
struct ATRAC3Context ATRAC3Context
uint8_t * decoded_bytes_buffer
data buffers
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int add_tonal_components(float *spectrum, int num_components, TonalComponent *components)
static const uint8_t clc_length_tab[8]
AVFrame * coded_frame
the picture in the bitstream
static const uint8_t *const huff_codes[7]
#define SAMPLES_PER_FRAME
TonalComponent components[64]
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
Quadrature mirror synthesis filter.
static void imlt(ATRAC3Context *q, float *input, float *output, int odd_band)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static int get_sbits(GetBitContext *s, int n)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
float ff_atrac_sf_table[64]
static const uint8_t *const huff_bits[7]
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
#define FFSWAP(type, a, b)
enum AVSampleFormat sample_fmt
audio sample format
static void channel_weighting(float *su1, float *su2, int *p3)
static float mdct_window[MDCT_SIZE]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void ff_atrac_generate_tables(void)
Generate common tables.
static const int8_t mantissa_clc_tab[4]
static const float inv_max_quant[8]
bitstream reader API header.
static int atrac3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int init(AVCodecParserContext *s)
static int decode_spectrum(GetBitContext *gb, float *output)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
Calculate the product of two vectors of floats and store the result in a vector of floats...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
float spectrum[SAMPLES_PER_FRAME]
static const uint16_t subband_tab[33]
int matrix_coeff_index_now[4]
static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, float **out_samples)
static void get_channel_weights(int index, int flag, float ch[2])
static const int8_t mantissa_vlc_tab[18]
float prev_frame[SAMPLES_PER_FRAME]
static float gain_tab2[31]
float imdct_buf[SAMPLES_PER_FRAME]
static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
#define CODEC_CAP_SUBFRAMES
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
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...
#define INIT_VLC_USE_NEW_STATIC
static VLC_TYPE atrac3_vlc_table[4096][2]
struct ChannelUnit ChannelUnit
static int decode_gain_control(GetBitContext *gb, GainBlock *block, int num_bands)
static void read_quant_spectral_coeffs(GetBitContext *gb, int selector, int coding_flag, int *mantissas, int num_codes)
struct TonalComponent TonalComponent
struct GainBlock GainBlock
main external API structure.
static void close(AVCodecParserContext *s)
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
int coding_mode
stream data
static unsigned int get_bits1(GetBitContext *s)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
static av_cold int atrac3_decode_close(AVCodecContext *avctx)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define FF_INPUT_BUFFER_PADDING_SIZE
#define DECLARE_ALIGNED(n, t, v)
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
common internal api header.
int scrambled_stream
extradata
#define AVERROR_INVALIDDATA
AVSampleFormat
Audio Sample Formats.
static void atrac3_init_static_data(AVCodec *codec)
static VLC spectral_coeff_tab[7]
static float gain_tab1[16]
float delay_buf1[46]
qmf delay buffers
AVCodec ff_atrac3_decoder
static const float matrix_coeffs[8]
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
static av_cold void init_atrac3_window(void)
#define INTERPOLATE(old, new, nsample)
int matrix_coeff_index_prev[4]
joint-stereo related variables
static const uint8_t huff_tab_sizes[7]
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static void gain_compensate_and_overlap(float *input, float *prev, float *output, GainInfo *gain1, GainInfo *gain2)
Atrac 3 AKA RealAudio 8 compatible decoder data.
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int decode_tonal_components(GetBitContext *gb, TonalComponent *components, int num_bands)
static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, ChannelUnit *snd, float *output, int channel_num, int coding_mode)
FmtConvertContext fmt_conv