57#define MAX_JS_PAIRS 8 / 2
59#define JOINT_STEREO 0x12
62#define SAMPLES_PER_FRAME 1024
65#define ATRAC3_VLC_BITS 8
148 for (
i = 0;
i < 128;
i++)
149 FFSWAP(
float, input[
i], input[255 -
i]);
166 uint32_t *output = (uint32_t *)
out;
168 off = (intptr_t)input & 3;
169 buf = (
const uint32_t *)(input - off);
171 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
175 for (
i = 0;
i < bytes / 4;
i++)
176 output[
i] =
c ^ buf[
i];
190 for (
i = 0, j = 255;
i < 128;
i++, j--) {
191 float wi = sin(((
i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
192 float wj = sin(((j + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
193 float w = 0.5 * (wi * wi + wj * wj);
220 int coding_flag,
int *mantissas,
223 int i,
code, huff_symb;
228 if (coding_flag != 0) {
233 for (
i = 0;
i < num_codes;
i++) {
241 for (
i = 0;
i < num_codes;
i++) {
253 for (
i = 0;
i < num_codes;
i++) {
258 for (
i = 0;
i < num_codes;
i++) {
275 int num_subbands, coding_mode,
i, j, first, last, subband_size;
276 int subband_vlc_index[32], sf_index[32];
284 for (
i = 0;
i <= num_subbands;
i++)
288 for (
i = 0;
i <= num_subbands;
i++) {
289 if (subband_vlc_index[
i] != 0)
293 for (
i = 0;
i <= num_subbands;
i++) {
297 subband_size = last - first;
299 if (subband_vlc_index[
i] != 0) {
304 mantissas, subband_size);
311 for (j = 0; first < last; first++, j++)
312 output[first] = mantissas[j] * scale_factor;
315 memset(output + first, 0, subband_size *
sizeof(*output));
335 int nb_components, coding_mode_selector, coding_mode;
336 int band_flags[4], mantissa[8];
337 int component_count = 0;
342 if (nb_components == 0)
345 coding_mode_selector =
get_bits(gb, 2);
346 if (coding_mode_selector == 2)
349 coding_mode = coding_mode_selector & 1;
351 for (
i = 0;
i < nb_components;
i++) {
352 int coded_values_per_component, quant_step_index;
354 for (
b = 0;
b <= num_bands;
b++)
357 coded_values_per_component =
get_bits(gb, 3);
360 if (quant_step_index <= 1)
363 if (coding_mode_selector == 3)
366 for (
b = 0;
b < (num_bands + 1) * 4;
b++) {
367 int coded_components;
369 if (band_flags[
b >> 2] == 0)
374 for (
c = 0;
c < coded_components;
c++) {
376 int sf_index, coded_values, max_coded_values;
380 if (component_count >= 64)
386 coded_values = coded_values_per_component + 1;
387 coded_values =
FFMIN(max_coded_values, coded_values);
393 mantissa, coded_values);
395 cmp->num_coefs = coded_values;
398 for (m = 0; m < coded_values; m++)
399 cmp->coef[m] = mantissa[m] * scale_factor;
406 return component_count;
423 for (
b = 0;
b <= num_bands;
b++) {
431 if (j && loc[j] <= loc[j - 1])
438 gain[
b].num_points = 0;
454 int i, j, last_pos = -1;
455 float *input, *output;
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];
462 for (j = 0; j < components[
i].num_coefs; j++)
463 output[j] += input[j];
469#define INTERPOLATE(old, new, nsample) \
470 ((old) + (nsample) * 0.125 * ((new) - (old)))
475 int i, nsample, band;
476 float mc1_l, mc1_r, mc2_l, mc2_r;
478 for (
i = 0, band = 0; band < 4 * 256; band += 256,
i++) {
479 int s1 = prev_code[
i];
480 int s2 = curr_code[
i];
491 for (; nsample < band + 8; nsample++) {
492 float c1 = su1[nsample];
493 float c2 = su2[nsample];
497 su2[nsample] =
c1 * 2.0 -
c2;
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;
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;
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;
529 av_unreachable(
"curr_code/matrix_coeff_index_* values are stored in two bits");
540 ch[0] = (
index & 7) / 7.0;
541 ch[1] = sqrt(2 - ch[0] * ch[0]);
543 FFSWAP(
float, ch[0], ch[1]);
553 if (p3[1] != 7 || p3[3] != 7) {
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);
562 for(; nsample < band + 256; nsample++) {
563 su1[nsample] *=
w[1][0];
564 su2[nsample] *=
w[1][1];
580 int channel_num,
int coding_mode)
582 int band, ret, num_subbands, last_tonal, num_bands;
586 if (coding_mode ==
JOINT_STEREO && (channel_num % 2) == 1) {
619 num_bands = (
subband_tab[num_subbands + 1] - 1) >> 8;
621 num_bands =
FFMAX((last_tonal + 256) >> 8, num_bands);
625 for (band = 0; band < 4; band++) {
627 if (band <= num_bands)
636 256, &output[band * 256]);
658 const uint8_t *js_databuf;
659 int js_pair, js_block_align;
663 for (ch = 0; ch <
channels; ch = ch + 2) {
665 js_databuf = databuf + js_pair * js_block_align;
669 js_databuf, js_block_align * 8);
682 for (
i = 0;
i < js_block_align / 2;
i++, ptr1++, ptr2--)
683 FFSWAP(uint8_t, *ptr1, *ptr2);
685 const uint8_t *ptr2 = js_databuf + js_block_align - 1;
686 for (
i = 0;
i < js_block_align;
i++)
692 for (
i = 4; *ptr1 == 0xF8;
i++, ptr1++) {
693 if (
i >= js_block_align)
710 for (
i = 0;
i < 4;
i++) {
747 float *p1 = out_samples[
i];
748 float *p2 = p1 + 256;
749 float *p3 = p2 + 256;
750 float *p4 = p3 + 256;
760 int size,
float **out_samples)
782 float *p1 = out_samples[
i];
783 float *p2 = p1 + 256;
784 float *p3 = p2 + 256;
785 float *p4 = p3 + 256;
795 int *got_frame_ptr,
AVPacket *avpkt)
797 const uint8_t *buf = avpkt->
data;
798 int buf_size = avpkt->
size;
801 const uint8_t *databuf;
803 if (buf_size < avctx->block_align) {
805 "Frame too small (%d bytes). Truncated file?\n", buf_size);
834 int *got_frame_ptr,
AVPacket *avpkt)
843 (
float **)
frame->extended_data);
864 for (
i = 0;
i < 7;
i++) {
869 &hufftabs[0][0], 2, 1,
880 int version, delay, samples_per_frame, frame_factor;
881 const uint8_t *edata_ptr = avctx->
extradata;
884 float scale = 1.0 / 32768;
901 bytestream_get_le16(&edata_ptr));
905 bytestream_get_le16(&edata_ptr));
906 frame_factor = bytestream_get_le16(&edata_ptr);
908 bytestream_get_le16(&edata_ptr));
927 version = bytestream_get_be32(&edata_ptr);
928 samples_per_frame = bytestream_get_be16(&edata_ptr);
929 delay = bytestream_get_be16(&edata_ptr);
952 if (delay != 0x88E) {
998 for (
i = 0;
i < 4;
i++) {
1035 .p.name =
"atrac3al",
1036 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_atrac3al_decoder
const FFCodec ff_atrac3_decoder
static av_cold void close(AVCodecParserContext *s)
static int add_tonal_components(float *spectrum, int num_components, TonalComponent *components)
Combine the tonal band spectrum and regular band spectrum.
static av_cold void init_imdct_window(void)
static int decode_spectrum(GetBitContext *gb, float *output)
Restore the quantized band spectrum coefficients.
static void read_quant_spectral_coeffs(GetBitContext *gb, int selector, int coding_flag, int *mantissas, int num_codes)
Mantissa decoding.
static int al_decode_frame(AVCodecContext *avctx, const uint8_t *databuf, int size, float **out_samples)
static int atrac3al_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static void reverse_matrixing(float *su1, float *su2, int *prev_code, int *curr_code)
static av_cold int atrac3_decode_close(AVCodecContext *avctx)
static void get_channel_weights(int index, int flag, float ch[2])
static VLCElem atrac3_vlc_table[7 *1<< ATRAC3_VLC_BITS]
static int decode_tonal_components(GetBitContext *gb, TonalComponent *components, int num_bands)
Restore the quantized tonal components.
static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes)
#define SAMPLES_PER_FRAME
static VLC spectral_coeff_tab[7]
static void channel_weighting(float *su1, float *su2, int *p3)
static av_cold void atrac3_init_static_data(void)
#define INTERPOLATE(old, new, nsample)
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
static int atrac3_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static int decode_gain_control(GetBitContext *gb, GainBlock *block, int num_bands)
Decode gain parameters for the coded bands.
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 ...
static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, float **out_samples)
static float mdct_window[MDCT_SIZE]
static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, ChannelUnit *snd, float *output, int channel_num, int coding_mode)
Decode a Sound Unit.
ATRAC3 AKA RealAudio 8 compatible decoder data.
static const int8_t mantissa_vlc_tab[18]
static const uint16_t subband_tab[33]
static const uint8_t huff_tab_sizes[7]
static const float matrix_coeffs[8]
static const uint8_t clc_length_tab[8]
static const float inv_max_quant[8]
static const uint8_t atrac3_hufftabs[][2]
static const int8_t mantissa_clc_tab[4]
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.
float ff_atrac_sf_table[64]
av_cold void ff_atrac_generate_tables(void)
Generate common tables.
void ff_atrac_iqmf(float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)
Quadrature mirror synthesis filter.
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#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 av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_sbits(GetBitContext *s, int n)
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
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.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#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_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#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)
Macro definitions for various function/variable attributes.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static int ff_thread_once(char *control, void(*routine)(void))
Replacements for frequently missing libm functions.
#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.
static av_always_inline int cmp(MPVEncContext *const 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...
static const uint16_t table[]
int matrix_coeff_index_next[MAX_JS_PAIRS][4]
int weighting_delay[MAX_JS_PAIRS][6]
void(* vector_fmul)(float *dst, const float *src0, const float *src1, int len)
int matrix_coeff_index_now[MAX_JS_PAIRS][4]
int scrambled_stream
extradata
uint8_t * decoded_bytes_buffer
data buffers
int coding_mode
stream data
int matrix_coeff_index_prev[MAX_JS_PAIRS][4]
joint-stereo related variables
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_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
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.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Gain compensation context structure.
Gain control parameters for one subband.
int num_points
number of gain control points
int loc_code[7]
location of gain control points
int lev_code[7]
level at corresponding control point
float imdct_buf[SAMPLES_PER_FRAME]
float spectrum[SAMPLES_PER_FRAME]
float delay_buf1[46]
qmf delay buffers
TonalComponent components[64]
float prev_frame[SAMPLES_PER_FRAME]
#define avpriv_request_sample(...)
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.
int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
#define VLC_INIT_USE_STATIC