Go to the documentation of this file.
50 #define IMC_BLOCK_SIZE 64
51 #define IMC_FRAME_ID 0x21
113 #define VLC_TABLES_SIZE 9512
116 0, 640, 1156, 1732, 2308, 2852, 3396, 3924,
124 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
129 double freqmin[32], freqmid[32], freqmax[32];
130 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
131 double nyquist_freq = sampling_rate * 0.5;
132 double freq, bark, prev_bark = 0,
tf,
tb;
135 for (
i = 0;
i < 32;
i++) {
140 tb = bark - prev_bark;
149 while (
tf < nyquist_freq) {
161 if (
tb <= bark - 0.5)
167 for (
i = 0;
i < 32;
i++) {
169 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
173 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
186 "Strange sample rate of %i, file likely corrupt or "
187 "needing a new table derivation method.\n",
200 for (j = 0; j < avctx->
channels; j++) {
218 r1 = sin((
i * 4.0 + 1.0) / 1024.0 *
M_PI);
219 r2 = cos((
i * 4.0 + 1.0) / 1024.0 *
M_PI);
232 for (
i = 0;
i < 30;
i++)
236 for (
i = 0;
i < 4 ;
i++) {
237 for (j = 0; j < 4; j++) {
275 float *flcoeffs2,
int *bandWidthT,
276 float *flcoeffs3,
float *flcoeffs5)
281 float snr_limit = 1.e-30;
286 flcoeffs5[
i] = workT2[
i] = 0.0;
288 workT1[
i] = flcoeffs1[
i] * flcoeffs1[
i];
289 flcoeffs3[
i] = 2.0 * flcoeffs2[
i];
292 flcoeffs3[
i] = -30000.0;
294 workT3[
i] = bandWidthT[
i] * workT1[
i] * 0.01;
295 if (workT3[
i] <= snr_limit)
300 for (cnt2 =
i; cnt2 < q->
cyclTab[
i]; cnt2++)
301 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[
i];
302 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[
i];
306 accum = (workT2[
i - 1] + accum) * q->
weights1[
i - 1];
307 flcoeffs5[
i] += accum;
314 for (cnt2 =
i - 1; cnt2 > q->
cyclTab2[
i]; cnt2--)
315 flcoeffs5[cnt2] += workT3[
i];
316 workT2[cnt2+1] += workT3[
i];
322 accum = (workT2[
i+1] + accum) * q->
weights2[
i];
323 flcoeffs5[
i] += accum;
338 s = stream_format_code >> 1;
345 if (stream_format_code & 4)
351 hufftab[cb_sel[
i]]->
bits, 2);
352 if (levlCoeffs[
i] == 17)
369 float *flcoeffs1,
float *flcoeffs2)
375 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
376 flcoeffs2[0] =
log2f(flcoeffs1[0]);
388 else if (
level <= 24)
394 tmp2 += 0.83048 *
level;
403 float *old_floor,
float *flcoeffs1,
413 if (levlCoeffBuf[
i] < 16) {
415 flcoeffs2[
i] = (levlCoeffBuf[
i] - 7) * 0.83048 + flcoeffs2[
i];
417 flcoeffs1[
i] = old_floor[
i];
423 float *flcoeffs1,
float *flcoeffs2)
429 flcoeffs1[
pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
432 tmp2 = flcoeffs2[
pos];
438 level = *levlCoeffBuf++;
440 flcoeffs2[
i] = tmp2 - 1.4533435415 *
level;
448 int stream_format_code,
int freebits,
int flag)
451 const float limit = -1.e20;
460 float lowest = 1.e10;
478 highest = highest * 0.25;
497 if (stream_format_code & 0x2) {
504 for (
i = (stream_format_code & 0x2) ? 4 : 0;
i <
BANDS - 1;
i++) {
513 summa = (summa * 0.5 - freebits) / iacc;
517 rres = summer - freebits;
518 if ((rres >= -8) && (rres <= 8))
524 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
525 cwlen = av_clipf(((chctx->
flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6);
536 if (freebits < summer)
543 summa = (float)(summer - freebits) / ((
t1 + 1) * iacc) + summa;
546 for (
i = (stream_format_code & 0x2) ? 4 : 0;
i <
BANDS;
i++) {
551 if (freebits > summer) {
560 if (highest <= -1.e20)
567 if (workT[
i] > highest) {
573 if (highest > -1.e20) {
574 workT[found_indx] -= 2.0;
576 workT[found_indx] = -1.e20;
578 for (j =
band_tab[found_indx]; j <
band_tab[found_indx + 1] && (freebits > summer); j++) {
583 }
while (freebits > summer);
585 if (freebits < summer) {
590 if (stream_format_code & 0x2) {
596 while (freebits < summer) {
600 if (workT[
i] < lowest) {
607 workT[low_indx] = lowest + 2.0;
610 workT[low_indx] = 1.e20;
612 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
693 while (corrected < summer) {
694 if (highest <= -1.e20)
700 if (workT[
i] > highest) {
706 if (highest > -1.e20) {
707 workT[found_indx] -= 2.0;
708 if (++(chctx->
bitsBandT[found_indx]) == 6)
709 workT[found_indx] = -1.e20;
711 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
755 int stream_format_code)
758 int middle_value, cw_len, max_size;
759 const float *quantizer;
766 if (cw_len <= 0 || chctx->skipFlags[j])
769 max_size = 1 << cw_len;
770 middle_value = max_size >> 1;
797 int i, j, cw_len, cw;
810 "Potential problem on band %i, coefficient %i"
811 ": cw_len=%i\n",
i, j, cw_len);
868 int stream_format_code;
869 int imc_hdr,
i, j,
ret;
872 int counter, bitscount;
878 if (imc_hdr & 0x18) {
885 if (stream_format_code & 0x04)
897 if (stream_format_code & 0x1)
902 if (stream_format_code & 0x1)
905 else if (stream_format_code & 0x4)
922 if (stream_format_code & 0x1) {
950 if (stream_format_code & 0x2) {
957 for (
i = 1;
i < 4;
i++) {
958 if (stream_format_code & 0x1)
971 if (!(stream_format_code & 0x2))
983 if (stream_format_code & 0x1) {
1016 int *got_frame_ptr,
AVPacket *avpkt)
1020 int buf_size = avpkt->
size;
1029 if (buf_size < IMC_BLOCK_SIZE * avctx->
channels) {
1080 #if CONFIG_IMC_DECODER
1096 #if CONFIG_IAC_DECODER
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
static av_cold int init(AVCodecContext *avctx)
static av_cold void flush(AVCodecContext *avctx)
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
int CWlengthT[COEFFS]
how many bits in each codeword
uint64_t channel_layout
Audio channel layout.
static const float imc_exp_tab[32]
int sample_rate
samples per second
static const uint8_t imc_huffman_lens[4][4][18]
static enum AVSampleFormat sample_fmts[]
int skipFlagCount[BANDS]
skipped coefficients per band
#define AV_CH_LAYOUT_MONO
static int get_bits_count(const GetBitContext *s)
static const float imc_quantizer2[2][56]
This structure describes decoded (raw) audio or video data.
static av_cold void iac_generate_tabs(IMCContext *q, int sampling_rate)
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void imc_calculate_coeffs(IMCContext *q, float *flcoeffs1, float *flcoeffs2, int *bandWidthT, float *flcoeffs3, float *flcoeffs5)
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
static const float *const imc_exp_tab2
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
static void imc_read_level_coeffs(IMCContext *q, int stream_format_code, int *levlCoeffs)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
static const int vlc_offsets[17]
static const int8_t cyclTab[32]
static void imc_imdct256(IMCContext *q, IMCChannel *chctx, int channels)
static const float imc_weights2[31]
int flags
AV_CODEC_FLAG_*.
#define AV_CH_LAYOUT_STEREO
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static av_cold int imc_decode_close(AVCodecContext *avctx)
static const float imc_weights1[31]
static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
void(* bswap16_buf)(uint16_t *dst, const uint16_t *src, int len)
int bandFlagsBuf[BANDS]
flags for each band
static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, float *old_floor, float *flcoeffs1, float *flcoeffs2)
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static unsigned int get_bits1(GetBitContext *s)
static const uint16_t band_tab[33]
#define INIT_VLC_USE_NEW_STATIC
static VLC huffman_vlc[4][4]
FFTComplex samples[COEFFS/2]
static const int8_t cyclTab2[32]
int bandWidthT[BANDS]
codewords per band
float last_fft_im[COEFFS]
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]
enum AVSampleFormat sample_fmt
audio sample format
static const float imc_quantizer1[4][8]
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
#define AV_LOG_INFO
Standard information.
int channels
number of audio channels
#define DECLARE_ALIGNED(n, t, v)
static void imc_refine_bit_allocation(IMCContext *q, IMCChannel *chctx)
#define i(width, name, range_min, range_max)
static int bit_allocation(IMCContext *q, IMCChannel *chctx, int stream_format_code, int freebits, int flag)
Perform bit allocation depending on bits available.
void AAC_RENAME() ff_sine_window_init(INTFLOAT *window, int n)
Generate a sine window.
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
int bitsBandT[BANDS]
how many bits per codeword in band
static const float xTab[14]
AVSampleFormat
Audio sample formats.
static int imc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
const char * name
Name of the codec implementation.
static av_cold int imc_decode_init(AVCodecContext *avctx)
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 const uint8_t imc_huffman_sizes[4]
#define AV_INPUT_BUFFER_PADDING_SIZE
main external API structure.
int skipFlagBits[BANDS]
bits used to code skip flags
int skipFlags[COEFFS]
skip coefficient decoding or not
static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define avpriv_request_sample(...)
#define LOCAL_ALIGNED_16(t, v,...)
This structure stores compressed data.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static const uint8_t imc_cb_select[4][32]
static const uint16_t imc_huffman_bits[4][4][18]
static void imc_decode_level_coefficients(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
static double freq2bark(double freq)
float mdct_sine_window[COEFFS]
MDCT tables.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void imc_get_coeffs(AVCodecContext *avctx, IMCContext *q, IMCChannel *chctx)
VLC_TYPE(* table)[2]
code, bits
static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx, int summer)
Increase highest' band coefficient sizes as some bits won't be used.
int codewords[COEFFS]
raw codewords read from bitstream
int sumLenArr[BANDS]
bits for all coeffs in band