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 95 float mono_previous_buffer1[1024];
96 float mono_previous_buffer2[1024];
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) {
448 exp_idx =
av_clip_uintp2((i - quant_index_table[index] + bias) / 2, 3);
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;
507 category[i] = exp_index2[i];
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)
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)
629 index = category[band];
630 if (category[band] < 7) {
631 if (
unpack_SQVH(q, p, category[band], subband_coef_index, subband_coef_sign)) {
634 category[band + j] = 7;
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];
662 categorize(q, p, quant_index_table, category, category_index);
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)
722 inbuffer[i] = inbuffer[i] * fc * q->
mlt_window[i] -
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;
969 outbuffer ? outbuffer[p->
ch_idx + 1] : NULL);
973 outbuffer ? outbuffer[p->
ch_idx + 1] : NULL);
981 int *got_frame_ptr,
AVPacket *avpkt)
985 int buf_size = avpkt->
size;
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);
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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, clip and convert to integer.
Context structure for the Lagged Fibonacci PRNG.
static av_cold void init_cplscales_table(COOKContext *q)
static const int cplband[51]
static const uint8_t ccpl_huffcounts[5][16]
static const void *const cvh_huffsyms[7]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
float decode_buffer_1[1024]
int64_t bit_rate
the average bitrate
static av_cold int init(AVCodecContext *avctx)
static const int kmax_tab[7]
#define avpriv_request_sample(...)
static const int expbits_tab[8]
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 const float *const cplscales[5]
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define MAX_COOK_VLC_ENTRIES
static av_cold void init_pow2table(void)
#define FF_ARRAY_ELEMS(a)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
#define AV_CH_LAYOUT_STEREO
VLC envelope_quant_index[13]
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
static const float quant_centroid_tab[7][14]
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 av_cold void init_gain_table(COOKContext *q)
enum AVSampleFormat sample_fmt
audio sample format
uint8_t * decoded_bytes_buffer
static int decouple_info(COOKContext *q, COOKSubpacket *p, int *decouple_tab)
function for getting the jointstereo coupling information
float mono_previous_buffer1[1024]
static void decode_vectors(COOKContext *q, COOKSubpacket *p, int *category, int *quant_index_table, float *mlt_buffer)
Fill the mlt_buffer with mlt coefficients.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
av_cold void ff_audiodsp_init(AudioDSPContext *c)
static void expand_category(COOKContext *q, int *category, int *category_index)
Expand the category vector.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void(* vector_clipf)(float *dst, const float *src, int len, float min, float max)
static void interpolate(float *out, float v1, float v2, int size)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
const float * cplscales[5]
static int decode_subpacket(COOKContext *q, COOKSubpacket *p, const uint8_t *inbuffer, float **outbuffer)
Cook subpacket decoding.
static int cook_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
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.
#define DECODE_BYTES_PAD1(bytes)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static int get_bits_left(GetBitContext *gb)
#define fc(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const int vd_tab[7]
static const float dither_tab[9]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const uint8_t envelope_quant_index_huffsyms[13][24]
static const uint8_t cvh_huffcounts[7][16]
float mono_previous_buffer2[1024]
const char * name
Name of the codec implementation.
static int decode_envelope(COOKContext *q, COOKSubpacket *p, int *quant_index_table)
Create the quant index table needed for the envelope.
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
uint64_t channel_layout
Audio channel layout.
static void saturate_output_float(COOKContext *q, float *out)
Saturate the output signal and interleave.
static const int vhvlcsize_tab[7]
void(* decouple)(struct cook *q, COOKSubpacket *p, int subband, float f1, float f2, float *decode_buffer, float *mlt_buffer1, float *mlt_buffer2)
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 av_cold int init_cook_mlt(COOKContext *q)
audio channel layout utility functions
static int mono_decode(COOKContext *q, COOKSubpacket *p, float *mlt_buffer)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
static av_cold int cook_decode_init(AVCodecContext *avctx)
Cook initialization.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
void ff_sine_window_init(float *window, int n)
Generate a sine window.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static void interpolate_float(COOKContext *q, float *buffer, int gain_index, int gain_index_next)
the actual requantization of the timedomain samples
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
static av_cold int init_cook_vlc_tables(COOKContext *q)
int sample_rate
samples per second
main external API structure.
float mono_mdct_output[2048]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
static void dump_cook_context(COOKContext *q)
static unsigned int get_bits1(GetBitContext *s)
static int joint_decode(COOKContext *q, COOKSubpacket *p, float *mlt_buffer_left, float *mlt_buffer_right)
function for decoding joint stereo data
static av_cold int cook_decode_close(AVCodecContext *avctx)
static float pow2tab[127]
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 int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
float decode_buffer_0[1060]
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)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
COOKSubpacket subpacket[MAX_SUBPACKETS]
float decode_buffer_2[1024]
static const uint8_t envelope_quant_index_huffcounts[13][16]
static const uint8_t *const ccpl_huffsyms[5]
static float rootpow2tab[127]
static int decode_bytes(const uint8_t *inbuffer, uint8_t *out, int bytes)
Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
void(* scalar_dequant)(struct cook *q, int index, int quant_index, int *subband_coef_index, int *subband_coef_sign, float *mlt_p)
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.
common internal api header.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static const int invradix_tab[7]
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
static const struct twinvq_data tab
and forward the result(frame or status change) to the corresponding input.If nothing is possible
void(* interpolate)(struct cook *q, float *buffer, int gain_index, int gain_index_next)
static enum AVSampleFormat sample_fmts[]
Filter the word “frame” indicates either a video frame or a group of audio samples
static void decode_gain_info(GetBitContext *gb, int *gaininfo)
Fill the gain array for the timedomain quantization.
#define COUPLING_VLC_BITS
#define av_malloc_array(a, b)
#define FFSWAP(type, a, b)
void(* saturate_output)(struct cook *q, float *out)
static void imlt_window_float(COOKContext *q, float *inbuffer, cook_gains *gains_ptr, float *previous_buffer)
Apply transform window, overlap buffers.
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.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
static const int vpr_tab[7]
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
void ff_free_vlc(VLC *vlc)
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* imlt_window)(struct cook *q, float *buffer1, cook_gains *gains_ptr, float *previous_buffer)
unsigned int channel_mask
Cook AKA RealAudio G2 compatible decoder data.