61 #define MONO 0x1000001
62 #define STEREO 0x1000002
63 #define JOINT_STEREO 0x1000003
64 #define MC_COOK 0x2000000
66 #define SUBBAND_SIZE 20
67 #define MAX_SUBPACKETS 5
69 #define QUANT_VLC_BITS 9
70 #define COUPLING_VLC_BITS 6
106 typedef struct cook {
111 void (*scalar_dequant)(
struct cook *q,
int index,
int quant_index,
112 int *subband_coef_index,
int *subband_coef_sign,
115 void (*decouple)(
struct cook *q,
119 float *decode_buffer,
120 float *mlt_buffer1,
float *mlt_buffer2);
122 void (*imlt_window)(
struct cook *q,
float *buffer1,
123 cook_gains *gains_ptr,
float *previous_buffer);
126 int gain_index,
int gain_index_next);
128 void (*saturate_output)(
struct cook *q,
float *
out);
145 VLC envelope_quant_index[13];
150 float gain_table[31];
156 float decode_buffer_1[1024];
157 float decode_buffer_2[1024];
158 float decode_buffer_0[1060];
175 static const float exp2_tab[2] = {1,
M_SQRT2};
176 float exp2_val =
powf(2, -63);
177 float root_val =
powf(2, -32);
178 for (
i = -63;
i < 64;
i++) {
192 for (
i = 0;
i < 31;
i++)
198 const void *syms,
int symbol_size,
int offset,
204 for (
int i = 0;
i < 16;
i++)
205 for (
unsigned count = num + counts[
i]; num < count; num++)
209 syms, symbol_size, symbol_size,
218 for (
i = 0;
i < 13;
i++) {
224 for (
i = 0;
i < 7;
i++) {
225 int sym_size = 1 + (
i == 3);
255 for (j = 0; j < mlt_size; j++)
272 for (
i = 0;
i < 5;
i++)
278 #define DECODE_BYTES_PAD1(bytes) (3 - ((bytes) + 3) % 4)
279 #define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))
303 static const uint32_t
tab[4] = {
310 uint32_t *obuf = (uint32_t *)
out;
317 off = (intptr_t) inbuffer & 3;
318 buf = (
const uint32_t *) (inbuffer - off);
321 for (
i = 0;
i < bytes / 4;
i++)
322 obuf[
i] =
c ^ buf[
i];
341 for (
i = 0;
i < 13;
i++)
343 for (
i = 0;
i < 7;
i++)
371 gaininfo[
i++] = gain;
384 int *quant_index_table)
388 quant_index_table[0] =
get_bits(&q->
gb, 6) - 6;
404 quant_index_table[
i] = quant_index_table[
i - 1] + j;
405 if (quant_index_table[
i] > 63 || quant_index_table[
i] < -63) {
407 "Invalid quantizer %d at position %d, outside [-63, 63] range\n",
408 quant_index_table[
i],
i);
427 int exp_idx, bias, tmpbias1, tmpbias2, bits_left, num_bits,
index, v,
i, j;
428 int exp_index2[102] = { 0 };
429 int exp_index1[102] = { 0 };
431 int tmp_categorize_array[128 * 2] = { 0 };
444 for (
i = 32;
i > 0;
i =
i / 2) {
452 if (num_bits >= bits_left - 32)
461 exp_index1[
i] = exp_idx;
462 exp_index2[
i] = exp_idx;
464 tmpbias1 = tmpbias2 = num_bits;
467 if (tmpbias1 + tmpbias2 > 2 * bits_left) {
471 if (exp_index1[
i] < 7) {
472 v = (-2 * exp_index1[
i]) - quant_index_table[
i] + bias;
481 tmp_categorize_array[tmp_categorize_array1_idx++] =
index;
489 if (exp_index2[
i] > 0) {
490 v = (-2 * exp_index2[
i]) - quant_index_table[
i] + bias;
499 tmp_categorize_array[--tmp_categorize_array2_idx] =
index;
510 category_index[
i] = tmp_categorize_array[tmp_categorize_array2_idx++];
527 int idx = category_index[
i];
544 int *subband_coef_index,
int *subband_coef_sign,
551 if (subband_coef_index[
i]) {
553 if (subband_coef_sign[
i])
573 int *subband_coef_index,
int *subband_coef_sign)
576 int vlc, vd,
tmp, result;
586 for (j = vd - 1; j >= 0; j--) {
591 for (j = 0; j < vd; j++) {
592 if (subband_coef_index[
i * vd + j]) {
597 subband_coef_sign[
i * vd + j] = 0;
600 subband_coef_sign[
i * vd + j] = 0;
617 int *quant_index_table,
float *mlt_buffer)
638 memset(subband_coef_index, 0,
sizeof(subband_coef_index));
639 memset(subband_coef_sign, 0,
sizeof(subband_coef_sign));
642 subband_coef_index, subband_coef_sign,
654 int category_index[128] = { 0 };
656 int quant_index_table[102];
683 int gain_index,
int gain_index_next)
687 fc1 =
pow2tab[gain_index + 63];
689 if (gain_index == gain_index_next) {
693 fc2 = q->
gain_table[15 + (gain_index_next - gain_index)];
710 cook_gains *gains_ptr,
float *previous_buffer)
738 cook_gains *gains_ptr,
float *previous_buffer)
747 q->
imlt_window(q, buffer1, gains_ptr, previous_buffer);
750 for (
i = 0;
i < 8;
i++)
751 if (gains_ptr->
now[
i] || gains_ptr->
now[
i + 1])
753 gains_ptr->
now[
i], gains_ptr->
now[
i + 1]);
756 memcpy(previous_buffer, buffer0,
773 int length = end - start + 1;
779 for (
i = 0;
i < length;
i++)
784 for (
i = 0;
i < length;
i++) {
790 decouple_tab[start +
i] = v;
810 float *decode_buffer,
811 float *mlt_buffer1,
float *mlt_buffer2)
816 mlt_buffer1[
SUBBAND_SIZE * subband + j] = f1 * decode_buffer[tmp_idx];
817 mlt_buffer2[
SUBBAND_SIZE * subband + j] = f2 * decode_buffer[tmp_idx];
829 float *mlt_buffer_left,
float *mlt_buffer_right)
836 const float *cplscale;
841 memset(mlt_buffer_left, 0, 1024 *
sizeof(*mlt_buffer_left));
842 memset(mlt_buffer_right, 0, 1024 *
sizeof(*mlt_buffer_right));
850 mlt_buffer_left[
i * 20 + j] = decode_buffer[
i * 40 + j];
851 mlt_buffer_right[
i * 20 + j] = decode_buffer[
i * 40 + 20 + j];
860 idx -= decouple_tab[cpl_tmp];
862 f1 = cplscale[decouple_tab[cpl_tmp] + 1];
864 q->
decouple(q, p,
i, f1, f2, decode_buffer,
865 mlt_buffer_left, mlt_buffer_right);
921 cook_gains *gains_ptr,
float *previous_buffer,
924 imlt_gain(q, decode_buffer, gains_ptr, previous_buffer);
939 const uint8_t *inbuffer,
float **outbuffer)
941 int sub_packet_size = p->
size;
981 int *got_frame_ptr,
AVPacket *avpkt)
985 int buf_size = avpkt->
size;
987 float **samples =
NULL;
992 if (buf_size < avctx->block_align)
1011 "frame subpacket size total > avctx->block_align!\n");
1022 "subpacket[%i] size %i js %i %i block_align %i\n",
1049 #define PRINT(a, b) ff_dlog(q->avctx, " %s = %d\n", a, b);
1078 unsigned int channel_mask = 0;
1079 int samples_per_frame = 0;
1114 samples_per_frame = bytestream2_get_be16(&gb);
1116 bytestream2_get_be32(&gb);
static enum AVSampleFormat sample_fmts[]
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
void ff_free_vlc(VLC *vlc)
int ff_init_vlc_from_lengths(VLC *vlc_arg, 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()
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define fc(width, name, range_min, range_max)
audio channel layout utility functions
#define FFSWAP(type, a, b)
static int decode_bytes(const uint8_t *inbuffer, uint8_t *out, int bytes)
Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
static av_cold int build_vlc(VLC *vlc, int nb_bits, const uint8_t counts[16], const void *syms, int symbol_size, int offset, void *logctx)
static void imlt_gain(COOKContext *q, float *inbuffer, cook_gains *gains_ptr, float *previous_buffer)
The modulated lapped transform, this takes transform coefficients and transforms them into timedomain...
static int decode_envelope(COOKContext *q, COOKSubpacket *p, int *quant_index_table)
Create the quant index table needed for the envelope.
static void saturate_output_float(COOKContext *q, float *out)
Saturate the output signal and interleave.
static int joint_decode(COOKContext *q, COOKSubpacket *p, float *mlt_buffer_left, float *mlt_buffer_right)
function for decoding joint stereo data
static void dump_cook_context(COOKContext *q)
static void categorize(COOKContext *q, COOKSubpacket *p, const int *quant_index_table, int *category, int *category_index)
Calculate the category and category_index vector.
static void interpolate_float(COOKContext *q, float *buffer, int gain_index, int gain_index_next)
the actual requantization of the timedomain samples
static int decouple_info(COOKContext *q, COOKSubpacket *p, int *decouple_tab)
function for getting the jointstereo coupling information
static int cook_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static av_cold void init_pow2table(void)
#define COUPLING_VLC_BITS
static void decouple_float(COOKContext *q, COOKSubpacket *p, int subband, float f1, float f2, float *decode_buffer, float *mlt_buffer1, float *mlt_buffer2)
function decouples a pair of signals from a single signal via multiplication.
static void imlt_window_float(COOKContext *q, float *inbuffer, cook_gains *gains_ptr, float *previous_buffer)
Apply transform window, overlap buffers.
static float rootpow2tab[127]
static av_cold void init_cplscales_table(COOKContext *q)
static int unpack_SQVH(COOKContext *q, COOKSubpacket *p, int category, int *subband_coef_index, int *subband_coef_sign)
Unpack the subband_coef_index and subband_coef_sign vectors.
static int decode_subpacket(COOKContext *q, COOKSubpacket *p, const uint8_t *inbuffer, float **outbuffer)
Cook subpacket decoding.
#define DECODE_BYTES_PAD1(bytes)
static void expand_category(COOKContext *q, int *category, int *category_index)
Expand the category vector.
static int mono_decode(COOKContext *q, COOKSubpacket *p, float *mlt_buffer)
static void scalar_dequant_float(COOKContext *q, int index, int quant_index, int *subband_coef_index, int *subband_coef_sign, float *mlt_p)
The real requantization of the mltcoefs.
static av_cold void init_gain_table(COOKContext *q)
static void decode_gain_info(GetBitContext *gb, int *gaininfo)
Fill the gain array for the timedomain quantization.
static av_cold int init_cook_mlt(COOKContext *q)
static void decode_bytes_and_gain(COOKContext *q, COOKSubpacket *p, const uint8_t *inbuffer, cook_gains *gains_ptr)
First part of subpacket decoding: decode raw stream bytes and read gain info.
static void decode_vectors(COOKContext *q, COOKSubpacket *p, int *category, int *quant_index_table, float *mlt_buffer)
Fill the mlt_buffer with mlt coefficients.
static void mlt_compensate_output(COOKContext *q, float *decode_buffer, cook_gains *gains_ptr, float *previous_buffer, float *out)
Final part of subpacket decoding: Apply modulated lapped transform, gain compensation,...
static av_cold int cook_decode_init(AVCodecContext *avctx)
Cook initialization.
static av_cold int init_cook_vlc_tables(COOKContext *q)
static float pow2tab[127]
static av_cold int cook_decode_close(AVCodecContext *avctx)
Cook AKA RealAudio G2 compatible decoder data.
static const int kmax_tab[7]
static const uint8_t *const ccpl_huffsyms[5]
static const void *const cvh_huffsyms[7]
static const int expbits_tab[8]
static const float quant_centroid_tab[7][14]
static const uint8_t ccpl_huffcounts[5][16]
static const uint8_t cvh_huffcounts[7][16]
static const int vd_tab[7]
static const int vpr_tab[7]
static const uint8_t envelope_quant_index_huffcounts[13][16]
#define MAX_COOK_VLC_ENTRIES
static const float dither_tab[9]
static const uint8_t envelope_quant_index_huffsyms[13][24]
static const float *const cplscales[5]
static const int cplband[51]
static const int invradix_tab[7]
static const int vhvlcsize_tab[7]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#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_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
av_cold void ff_audiodsp_init(AudioDSPContext *c)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
typedef void(RENAME(mix_any_func_type))
void ff_sine_window_init(float *window, int n)
Generate a sine window.
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int64_t bit_rate
the average bitrate
int sample_rate
samples per second
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
uint64_t channel_layout
Audio channel layout.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
Context structure for the Lagged Fibonacci PRNG.
This structure stores compressed data.
void(* vector_clipf)(float *dst, const float *src, int len, float min, float max)
void(* imlt_window)(struct cook *q, float *buffer1, cook_gains *gains_ptr, float *previous_buffer)
VLC envelope_quant_index[13]
float decode_buffer_0[1060]
void(* scalar_dequant)(struct cook *q, int index, int quant_index, int *subband_coef_index, int *subband_coef_sign, float *mlt_p)
uint8_t * decoded_bytes_buffer
void(* decouple)(struct cook *q, COOKSubpacket *p, int subband, float f1, float f2, float *decode_buffer, float *mlt_buffer1, float *mlt_buffer2)
void(* interpolate)(struct cook *q, float *buffer, int gain_index, int gain_index_next)
float decode_buffer_1[1024]
float mono_mdct_output[2048]
COOKSubpacket subpacket[MAX_SUBPACKETS]
const float * cplscales[5]
float decode_buffer_2[1024]
void(* saturate_output)(struct cook *q, float *out)
float mono_previous_buffer1[1024]
unsigned int channel_mask
float mono_previous_buffer2[1024]
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
VLC_TYPE(* table)[2]
code, bits
#define av_malloc_array(a, b)
#define avpriv_request_sample(...)
static void interpolate(float *out, float v1, float v2, int size)
static const struct twinvq_data tab
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
static const uint8_t offset[127][2]