Go to the documentation of this file.
32 #include "config_components.h"
54 #define IMC_BLOCK_SIZE 64
55 #define IMC_FRAME_ID 0x21
111 #define IMC_VLC_BITS 9
112 #define VLC_TABLES_SIZE 9512
118 return 3.5 * atan((freq / 7500.0) * (freq / 7500.0)) + 13.0 * atan(freq * 0.00076);
123 double freqmin[32], freqmid[32], freqmax[32];
124 double scale = sampling_rate / (256.0 * 2.0 * 2.0);
125 double nyquist_freq = sampling_rate * 0.5;
126 double freq, bark, prev_bark = 0,
tf,
tb;
129 for (
i = 0;
i < 32;
i++) {
134 tb = bark - prev_bark;
143 while (
tf < nyquist_freq) {
155 if (
tb <= bark - 0.5)
161 for (
i = 0;
i < 32;
i++) {
163 for (j = 31; j > 0 && freq <= freqmid[j]; j--);
167 for (j = 0; j < 32 && freq >= freqmid[j]; j++);
176 for (
int i = 0;
i < 4 ;
i++) {
177 for (
int j = 0; j < 4; j++) {
192 float scale = 1.0f / (16384);
196 "Strange sample rate of %i, file likely corrupt or "
197 "needing a new table derivation method.\n",
225 for (
i = 0;
i < 30;
i++)
255 float *flcoeffs2,
int *bandWidthT,
256 float *flcoeffs3,
float *flcoeffs5)
261 float snr_limit = 1.e-30;
266 flcoeffs5[
i] = workT2[
i] = 0.0;
268 workT1[
i] = flcoeffs1[
i] * flcoeffs1[
i];
269 flcoeffs3[
i] = 2.0 * flcoeffs2[
i];
272 flcoeffs3[
i] = -30000.0;
274 workT3[
i] = bandWidthT[
i] * workT1[
i] * 0.01;
275 if (workT3[
i] <= snr_limit)
280 for (cnt2 =
i; cnt2 < q->
cyclTab[
i]; cnt2++)
281 flcoeffs5[cnt2] = flcoeffs5[cnt2] + workT3[
i];
282 workT2[cnt2 - 1] = workT2[cnt2 - 1] + workT3[
i];
286 accum = (workT2[
i - 1] + accum) * q->
weights1[
i - 1];
287 flcoeffs5[
i] += accum;
294 for (cnt2 =
i - 1; cnt2 > q->
cyclTab2[
i]; cnt2--)
295 flcoeffs5[cnt2] += workT3[
i];
296 workT2[cnt2+1] += workT3[
i];
302 accum = (workT2[
i+1] + accum) * q->
weights2[
i];
303 flcoeffs5[
i] += accum;
314 const uint8_t *cb_sel;
315 int s = stream_format_code >> 1;
320 if (stream_format_code & 4)
327 if (levlCoeffs[
i] == 17)
344 float *flcoeffs1,
float *flcoeffs2)
350 flcoeffs1[0] = 20000.0 /
exp2 (levlCoeffBuf[0] * 0.18945);
351 flcoeffs2[0] =
log2f(flcoeffs1[0]);
363 else if (
level <= 24)
369 tmp2 += 0.83048 *
level;
378 float *old_floor,
float *flcoeffs1,
388 if (levlCoeffBuf[
i] < 16) {
390 flcoeffs2[
i] = (levlCoeffBuf[
i] - 7) * 0.83048 + flcoeffs2[
i];
392 flcoeffs1[
i] = old_floor[
i];
398 float *flcoeffs1,
float *flcoeffs2)
404 flcoeffs1[
pos] = 20000.0 / pow (2, levlCoeffBuf[0] * 0.18945);
407 tmp2 = flcoeffs2[
pos];
413 level = *levlCoeffBuf++;
415 flcoeffs2[
i] = tmp2 - 1.4533435415 *
level;
423 int stream_format_code,
int freebits,
int flag)
426 const float limit = -1.e20;
435 float lowest = 1.e10;
453 highest = highest * 0.25;
472 if (stream_format_code & 0x2) {
479 for (
i = (stream_format_code & 0x2) ? 4 : 0;
i <
BANDS - 1;
i++) {
488 summa = (summa * 0.5 - freebits) / iacc;
492 rres = summer - freebits;
493 if ((rres >= -8) && (rres <= 8))
499 for (j = (stream_format_code & 0x2) ? 4 : 0; j <
BANDS; j++) {
511 if (freebits < summer)
518 summa = (
float)(summer - freebits) / ((
t1 + 1) * iacc) + summa;
521 for (
i = (stream_format_code & 0x2) ? 4 : 0;
i <
BANDS;
i++) {
526 if (freebits > summer) {
535 if (highest <= -1.e20)
542 if (workT[
i] > highest) {
548 if (highest > -1.e20) {
549 workT[found_indx] -= 2.0;
551 workT[found_indx] = -1.e20;
553 for (j =
band_tab[found_indx]; j <
band_tab[found_indx + 1] && (freebits > summer); j++) {
558 }
while (freebits > summer);
560 if (freebits < summer) {
565 if (stream_format_code & 0x2) {
571 while (freebits < summer) {
575 if (workT[
i] < lowest) {
582 workT[low_indx] = lowest + 2.0;
585 workT[low_indx] = 1.e20;
587 for (j =
band_tab[low_indx]; j <
band_tab[low_indx+1] && (freebits < summer); j++) {
668 while (corrected < summer) {
669 if (highest <= -1.e20)
675 if (workT[
i] > highest) {
681 if (highest > -1.e20) {
682 workT[found_indx] -= 2.0;
683 if (++(chctx->
bitsBandT[found_indx]) == 6)
684 workT[found_indx] = -1.e20;
686 for (j =
band_tab[found_indx]; j <
band_tab[found_indx+1] && (corrected < summer); j++) {
697 int stream_format_code)
700 int middle_value, cw_len, max_size;
701 const float *quantizer;
708 if (cw_len <= 0 || chctx->skipFlags[j])
711 max_size = 1 << cw_len;
712 middle_value = max_size >> 1;
739 int i, j, cw_len, cw;
752 "Potential problem on band %i, coefficient %i"
753 ": cw_len=%i\n",
i, j, cw_len);
809 int stream_format_code;
810 int imc_hdr,
i, j,
ret;
819 if (imc_hdr & 0x18) {
826 if (stream_format_code & 0x04)
838 if (stream_format_code & 0x1)
843 if (stream_format_code & 0x1)
846 else if (stream_format_code & 0x4)
862 if (stream_format_code & 0x1) {
889 if (stream_format_code & 0x2) {
896 for (
i = 1;
i < 4;
i++) {
897 if (stream_format_code & 0x1)
910 if (!(stream_format_code & 0x2))
922 if (stream_format_code & 0x1) {
952 memcpy(chctx->
prev_win, q->
temp + 128,
sizeof(
float)*128);
958 int *got_frame_ptr,
AVPacket *avpkt)
960 const uint8_t *buf = avpkt->
data;
961 int buf_size = avpkt->
size;
970 if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
1021 #if CONFIG_IMC_DECODER
1038 #if CONFIG_IAC_DECODER
const FFCodec ff_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.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
void(* butterflies_float)(float *restrict v1, float *restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
int CWlengthT[COEFFS]
how many bits in each codeword
static const float imc_exp_tab[32]
int sample_rate
samples per second
static const uint8_t imc_huffman_lens[4][4][18]
int skipFlagCount[BANDS]
skipped coefficients per band
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)
int nb_channels
Number of channels in this layout.
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)
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...
static void imc_read_level_coeffs_raw(IMCContext *q, int stream_format_code, int *levlCoeffs)
static VLCElem vlc_tables[VLC_TABLES_SIZE]
static const float *const imc_exp_tab2
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.
AVCodec p
The public AVCodec.
int skipFlagRaw[BANDS]
skip flags are stored in raw form or not
static const int8_t cyclTab[32]
AVChannelLayout ch_layout
Audio channel layout.
static av_cold void imc_init_static(void)
static const float imc_weights2[31]
int flags
AV_CODEC_FLAG_*.
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
static av_cold int imc_decode_close(AVCodecContext *avctx)
#define FF_CODEC_DECODE_CB(func)
#define LOCAL_ALIGNED_16(t, v,...)
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)
#define CODEC_LONG_NAME(str)
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]
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static const int8_t cyclTab2[32]
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
int bandWidthT[BANDS]
codewords per band
static void imc_decode_level_coefficients_raw(IMCContext *q, int *levlCoeffBuf, float *flcoeffs1, float *flcoeffs2)
static const uint8_t imc_huffman_syms[4][4][18]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
An AVChannelLayout holds information about the channel layout of audio data.
#define DECLARE_ALIGNED(n, t, v)
static const VLCElem * huffman_vlc[4][4]
enum AVSampleFormat sample_fmt
audio sample format
static const float imc_quantizer1[4][8]
static int imc_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
void ff_sine_window_init(float *window, int n)
Generate a sine window.
int nb_samples
number of audio samples (per channel) described by this frame
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.
static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, int stream_format_code)
uint8_t ** extended_data
pointers to the data planes/channels.
int bitsBandT[BANDS]
how many bits per codeword in band
static const float xTab[14]
AVSampleFormat
Audio sample formats.
const char * name
Name of the codec implementation.
static av_cold int imc_decode_init(AVCodecContext *avctx)
static double limit(double x)
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
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int skipFlags[COEFFS]
skip coefficient decoding or not
const FFCodec ff_imc_decoder
const av_cold VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, 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)
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(...)
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
#define AV_CHANNEL_LAYOUT_MONO
#define VLC_INIT_STATE(_table)
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 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)
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