26 #define BITSTREAM_READER_LE
77 0x0, 0x1, 0x2, 0x3, 0x4, 0x6, 0x8, 0xA,
78 0xC, 0x10, 0x14, 0x18, 0x1C, 0x24, 0x2C, 0x34,
79 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, 0x9C, 0xBC, 0xDC,
80 0xFC, 0x13C, 0x17C, 0x1BC, 0x1FC, 0x27C, 0x2FC, 0x37C,
81 0x3FC, 0x4FC, 0x5FC, 0x6FC, 0x7FC, 0x9FC, 0xBFC, 0xDFC,
82 0xFFC, 0x13FC, 0x17FC, 0x1BFC, 0x1FFC, 0x27FC, 0x2FFC, 0x37FC,
83 0x3FFC, 0x4FFC, 0x5FFC, 0x6FFC, 0x7FFC, 0x9FFC, 0xBFFC, 0xDFFC,
84 0xFFFC, 0x13FFC, 0x17FFC, 0x1BFFC, 0x1FFFC, 0x27FFC, 0x2FFFC, 0x37FFC,
89 1.18750000f, 1.68359380f, 2.37500000f, 3.36718750f, 4.75000000f,
90 6.73437500f, 9.50000000f, 13.4687500f, 19.0000000f, 26.9375000f,
91 38.0000000f, 53.8750000f, 76.0000000f, 107.750000f, 152.000000f,
92 215.500000f, 304.000000f, 431.000000f, 608.000000f, 862.000000f,
93 1216.00000f, 1724.00000f, 2432.00000f, 3448.00000f, 4864.00000f,
94 6896.00000f, 9728.00000f, 13792.0000f, 19456.0000f, 27584.0000f,
95 38912.0000f, 55168.0000f, 77824.0000f, 110336.000f, 155648.000f,
96 220672.000f, 311296.000f, 441344.000f, 622592.000f, 882688.000f,
97 1245184.00f, 1765376.00f, 2490368.00f, 3530752.00f, 4980736.00f,
98 7061504.00f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 56, 64,
103 80, 96, 120, 144, 176, 208, 240, 256,
104 0, 2, 4, 8, 16, 24, 32, 48, 56, 64, 80, 104,
105 128, 160, 208, 256, 0, 0, 0, 0, 0,
106 0, 2, 4, 8, 16, 32, 48, 64, 80, 112, 160, 208,
107 256, 0, 0, 0, 0, 0, 0, 0, 0,
108 0, 4, 8, 16, 32, 48, 64, 96, 144, 208, 256,
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 4, 16, 32, 64, 256, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
115 19, 14, 11, 9, 4, 2, 0
124 { 1, 2 }, { 10, 7 }, { 26, 9 }, { 22, 9 }, { 24, 9 }, { 14, 9 },
125 { 8, 6 }, { 6, 5 }, { 7, 5 }, { 9, 7 }, { 30, 9 }, { 32, 10 },
126 { 13, 10 }, { 20, 9 }, { 28, 9 }, { 12, 7 }, { 15, 11 }, { 36, 12 },
127 { 0, 12 }, { 34, 10 }, { 18, 9 }, { 11, 9 }, { 16, 9 }, { 5, 3 },
128 { 2, 3 }, { 4, 3 }, { 3, 2 },
130 { 1, 1 }, { 2, 2 }, { 3, 4 }, { 8, 9 }, { 9, 10 }, { 0, 10 },
131 { 13, 8 }, { 7, 7 }, { 6, 6 }, { 17, 5 }, { 4, 4 }, { 5, 4 },
133 { 18, 3 }, { 16, 3 }, { 22, 7 }, { 8, 10 }, { 4, 10 }, { 3, 9 },
134 { 2, 8 }, { 23, 8 }, { 10, 8 }, { 11, 7 }, { 21, 5 }, { 20, 4 },
135 { 1, 7 }, { 7, 10 }, { 5, 10 }, { 9, 9 }, { 6, 10 }, { 25, 11 },
136 { 26, 12 }, { 27, 13 }, { 0, 13 }, { 24, 9 }, { 12, 6 }, { 13, 5 },
137 { 14, 4 }, { 19, 3 }, { 15, 3 }, { 17, 2 },
139 { 2, 4 }, { 14, 6 }, { 26, 7 }, { 31, 8 }, { 32, 9 }, { 35, 9 },
140 { 7, 5 }, { 10, 5 }, { 22, 7 }, { 27, 7 }, { 19, 7 }, { 20, 7 },
141 { 4, 5 }, { 13, 5 }, { 17, 6 }, { 15, 6 }, { 8, 5 }, { 5, 4 },
142 { 28, 7 }, { 33, 9 }, { 36, 11 }, { 38, 12 }, { 42, 14 }, { 45, 16 },
143 { 44, 18 }, { 0, 18 }, { 46, 17 }, { 43, 15 }, { 40, 13 }, { 37, 11 },
144 { 39, 12 }, { 41, 12 }, { 34, 8 }, { 16, 6 }, { 11, 5 }, { 9, 4 },
145 { 1, 2 }, { 3, 4 }, { 30, 7 }, { 29, 7 }, { 23, 6 }, { 24, 6 },
146 { 18, 6 }, { 6, 4 }, { 12, 5 }, { 21, 6 }, { 25, 6 },
148 { 1, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 },
149 { 8, 8 }, { 0, 8 }, { 2, 1 },
151 { 2, 2 }, { 1, 2 }, { 3, 4 }, { 7, 4 }, { 6, 5 }, { 5, 6 },
152 { 0, 6 }, { 4, 4 }, { 8, 2 },
169 static VLC_TYPE vlc_buffer[13698][2];
173 &hufftab[0][1], 2, &hufftab[0][0], 2, 1, -1,
179 for (
i = 0;
i < 512;
i++)
185 int i, j, n0, n1, n2,
diff;
192 nptr =
s->noise_buffer + 256 * j;
194 for (
i = 0;
i + n0 < n1;
i++, nptr++)
195 nptr[0] =
i / (
float)(n1 - n0);
198 nptr =
s->noise_buffer + (j << 8) + n1 - n0;
200 for (
i = n1;
i < n2;
i++, nptr++,
diff--)
201 nptr[0] =
diff / (
float)(n2 - n1);
209 int ret, fft_size, fft_order,
size,
g, j, x;
222 if (bytestream2_peek_be64(&
b) == (((uint64_t)
MKBETAG(
'f',
'r',
'm',
'a') << 32) |
223 (uint64_t)
MKBETAG(
'Q',
'D',
'M',
'C')))
235 size = bytestream2_get_be32u(&
b);
242 if (bytestream2_get_be32u(&
b) !=
MKBETAG(
'Q',
'D',
'C',
'A')) {
248 avctx->
channels =
s->nb_channels = bytestream2_get_be32u(&
b);
249 if (
s->nb_channels <= 0 ||
s->nb_channels > 2) {
257 avctx->
bit_rate = bytestream2_get_be32u(&
b);
259 fft_size = bytestream2_get_be32u(&
b);
260 fft_order =
av_log2(fft_size) + 1;
261 s->checksum_size = bytestream2_get_be32u(&
b);
262 if (
s->checksum_size >= 1U << 28) {
277 s->frame_size = 1 <<
s->frame_bits;
278 s->subframe_size =
s->frame_size >> 5;
284 if ((fft_order < 7) || (fft_order > 9)) {
289 if (fft_size != (1 << (fft_order - 1))) {
300 for (
g = 5;
g > 0;
g--) {
301 for (j = 0; j < (1 <<
g) - 1; j++)
302 s->alt_sin[5-
g][j] =
sin_table[(((j+1) << (8 -
g)) & 0x1FF)];
346 if (label !=
MKTAG(
'Q',
'M',
'C', 1))
349 for (
i = 0;
i <
s->checksum_size - 6;
i++)
357 int ch, j, k, v, idx, band, lastval, newval,
len;
359 for (ch = 0; ch <
s->nb_channels; ch++) {
371 s->noise[ch][band][0] = lastval - 1;
372 for (j = 0; j < 15;) {
383 newval = lastval + (v + 1) / 2;
385 newval = lastval - v / 2;
391 for (k = 1; idx <= j +
len; k++, idx++)
392 s->noise[ch][band][idx] = lastval + k * (newval - lastval) /
len - 1;
405 const int index =
s->nb_tones[group];
413 s->tones[group][
index].freq = freq;
414 s->tones[group][
index].mode = stereo_mode;
415 s->tones[group][
index].amplitude = amplitude;
416 s->tones[group][
index].phase = phase;
417 s->nb_tones[group]++;
422 int amp, phase, stereo_mode = 0,
i, group, freq, group_size, group_bits;
423 int amp2, phase2, pos2, off;
425 for (group = 0; group < 5; group++) {
426 group_size = 1 << (
s->frame_bits - group - 1);
427 group_bits = 4 - group;
431 for (
i = 1; ;
i = freq + 1) {
439 while (freq >= group_size - 1) {
440 freq += 2 - group_size;
442 off += 1 << group_bits;
445 if (pos2 >=
s->frame_size)
448 if (
s->nb_channels > 1)
456 if (stereo_mode > 1) {
465 phase2 = phase - phase2;
471 if ((freq >> group_bits) + 1 <
s->subframe_size) {
472 add_tone(
s, group, off, freq, stereo_mode & 1, amp, phase);
474 add_tone(
s, group, off, freq, ~stereo_mode & 1, amp2, phase2);
484 int subframe_size,
i, j, k, length;
485 float scale, *noise_ptr;
487 scale = 0.5 * amplitude;
488 subframe_size =
s->subframe_size;
489 if (subframe_size >= node2)
490 subframe_size = node2;
491 length = (subframe_size - node1) & 0xFFFC;
493 noise_ptr = &
s->noise_buffer[256 *
index];
495 for (
i = 0;
i < length;
i += 4, j+= 4, noise_ptr += 4) {
496 s->noise2_buffer[j ] += scale * noise_ptr[0];
497 s->noise2_buffer[j + 1] += scale * noise_ptr[1];
498 s->noise2_buffer[j + 2] += scale * noise_ptr[2];
499 s->noise2_buffer[j + 3] += scale * noise_ptr[3];
503 noise_ptr =
s->noise_buffer + length + (
index << 8);
504 for (
i = length;
i < subframe_size - node1;
i++, k++, noise_ptr++)
505 s->noise2_buffer[k] += scale * noise_ptr[0];
512 float *
im = &
s->fft_buffer[0 + ch][
s->fft_offset +
s->subframe_size * current_subframe];
513 float *
re = &
s->fft_buffer[2 + ch][
s->fft_offset +
s->subframe_size * current_subframe];
515 memset(
s->noise2_buffer, 0, 4 *
s->subframe_size);
518 if (
qdmc_nodes[
i + 21 *
s->band_index] >
s->subframe_size - 1)
521 aindex =
s->noise[ch][
i][current_subframe / 2];
522 amplitude = aindex > 0 ?
amplitude_tab[aindex & 0x3F] : 0.0f;
528 for (j = 2; j <
s->subframe_size - 1; j++) {
529 float rnd_re, rnd_im;
531 s->rndval = 214013U *
s->rndval + 2531011;
532 rnd_im = ((
s->rndval & 0x7FFF) - 16384.0f) * 0.000030517578f *
s->noise2_buffer[j];
533 s->rndval = 214013U *
s->rndval + 2531011;
534 rnd_re = ((
s->rndval & 0x7FFF) - 16384.0f) * 0.000030517578f *
s->noise2_buffer[j];
544 int j, group_bits,
pos, pindex;
545 float im,
re, amplitude,
level, *imptr, *reptr;
547 if (
s->nb_channels == 1)
550 group_bits = 4 - group;
551 pos = freqs >> (4 - group);
553 imptr = &
s->fft_buffer[ stereo_mode][
s->fft_offset +
s->subframe_size *
offset +
pos];
554 reptr = &
s->fft_buffer[2 + stereo_mode][
s->fft_offset +
s->subframe_size *
offset +
pos];
555 pindex = (phase << 6) - ((2 * (freqs >> (4 - group)) + 1) << 7);
556 for (j = 0; j < (1 << (group_bits + 1)) - 1; j++) {
557 pindex += (2 * freqs + 1) << (7 - group_bits);
558 level = amplitude *
s->alt_sin[group][j];
565 imptr +=
s->subframe_size;
566 reptr +=
s->subframe_size;
567 if (imptr >= &
s->fft_buffer[stereo_mode][2 *
s->frame_size]) {
568 imptr = &
s->fft_buffer[0 + stereo_mode][
pos];
569 reptr = &
s->fft_buffer[2 + stereo_mode][
pos];
579 if (
s->nb_channels == 1)
585 pos =
s->fft_offset + freqs +
s->subframe_size *
offset;
586 s->fft_buffer[ stereo_mode][
pos ] +=
im;
587 s->fft_buffer[2 + stereo_mode][
pos ] +=
re;
588 s->fft_buffer[ stereo_mode][
pos + 1] -=
im;
589 s->fft_buffer[2 + stereo_mode][
pos + 1] -=
re;
596 for (
g = 0;
g < 4;
g++) {
597 for (
w =
s->cur_tone[
g]; w < s->nb_tones[
g];
w++) {
600 if (current_subframe < t->
offset)
606 for (
w =
s->cur_tone[4]; w < s->nb_tones[4];
w++) {
609 if (current_subframe < t->
offset)
623 s->fft_offset =
s->frame_size -
s->fft_offset;
624 s->buffer_ptr = &
s->buffer[
s->nb_channels *
s->buffer_offset];
634 for (n = 0; n < 32; n++) {
637 for (ch = 0; ch <
s->nb_channels; ch++)
642 for (ch = 0; ch <
s->nb_channels; ch++) {
643 for (
i = 0;
i <
s->subframe_size;
i++) {
644 s->cmplx[ch][
i].re =
s->fft_buffer[ch + 2][
s->fft_offset + n *
s->subframe_size +
i];
645 s->cmplx[ch][
i].im =
s->fft_buffer[ch + 0][
s->fft_offset + n *
s->subframe_size +
i];
646 s->cmplx[ch][
s->subframe_size +
i].re = 0;
647 s->cmplx[ch][
s->subframe_size +
i].im = 0;
651 for (ch = 0; ch <
s->nb_channels; ch++) {
652 s->fft_ctx.fft_permute(&
s->fft_ctx,
s->cmplx[ch]);
653 s->fft_ctx.fft_calc(&
s->fft_ctx,
s->cmplx[ch]);
656 r = &
s->buffer_ptr[
s->nb_channels * n *
s->subframe_size];
657 for (
i = 0;
i < 2 *
s->subframe_size;
i++) {
658 for (ch = 0; ch <
s->nb_channels; ch++) {
659 *
r++ +=
s->cmplx[ch][
i].re;
663 r = &
s->buffer_ptr[n *
s->subframe_size *
s->nb_channels];
664 for (
i = 0;
i <
s->nb_channels *
s->subframe_size;
i++) {
667 out +=
s->subframe_size *
s->nb_channels;
669 for (ch = 0; ch <
s->nb_channels; ch++) {
670 memset(
s->fft_buffer[ch+0] +
s->fft_offset + n *
s->subframe_size, 0, 4 *
s->subframe_size);
671 memset(
s->fft_buffer[ch+2] +
s->fft_offset + n *
s->subframe_size, 0, 4 *
s->subframe_size);
673 memset(
s->buffer +
s->nb_channels * (n *
s->subframe_size +
s->frame_size +
s->buffer_offset), 0, 4 *
s->subframe_size *
s->nb_channels);
676 s->buffer_offset +=
s->frame_size;
677 if (
s->buffer_offset >= 32768 -
s->frame_size) {
678 memcpy(
s->buffer, &
s->buffer[
s->nb_channels *
s->buffer_offset], 4 *
s->frame_size *
s->nb_channels);
679 s->buffer_offset = 0;
689 memset(
s->buffer, 0,
sizeof(
s->buffer));
690 memset(
s->fft_buffer, 0,
sizeof(
s->fft_buffer));
692 s->buffer_offset = 0;
696 int *got_frame_ptr,
AVPacket *avpkt)
705 if (avpkt->
size <
s->checksum_size)
716 memset(
s->nb_tones, 0,
sizeof(
s->nb_tones));
717 memset(
s->cur_tone, 0,
sizeof(
s->cur_tone));
722 return s->checksum_size;
static void flush(AVCodecContext *avctx)
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
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 void bytestream2_skipu(GetByteContext *g, unsigned int size)
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)
audio channel layout utility functions
#define MKTAG(a, b, c, d)
#define MKBETAG(a, b, c, d)
static __device__ float floor(float a)
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 unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
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 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 av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int ff_thread_once(char *control, void(*routine)(void))
static const uint16_t table[]
static void add_tone(QDMCContext *s, int group, int offset, int freq, int stereo_mode, int amplitude, int phase)
static const float amplitude_tab[64]
static const uint8_t huff_sizes[]
static int read_noise_data(QDMCContext *s, GetBitContext *gb)
static const uint8_t noise_bands_selector[]
static void lin_calc(QDMCContext *s, float amplitude, int node1, int node2, int index)
static av_cold int qdmc_decode_close(AVCodecContext *avctx)
static const uint8_t huff_bits[]
static av_cold void qdmc_flush(AVCodecContext *avctx)
static const uint16_t qdmc_nodes[112]
static void make_noises(QDMCContext *s)
static int qdmc_get_vlc(GetBitContext *gb, VLC *table, int flag)
static void add_wave0(QDMCContext *s, int offset, int freqs, int stereo_mode, int amp, int phase)
static int qdmc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static float sin_table[512]
static int skip_label(QDMCContext *s, GetBitContext *gb)
static int read_wave_data(QDMCContext *s, GetBitContext *gb)
static av_cold int qdmc_decode_init(AVCodecContext *avctx)
static void add_waves(QDMCContext *s, int current_subframe)
static void add_wave(QDMCContext *s, int offset, int freqs, int group, int stereo_mode, int amp, int phase)
static const uint8_t qdmc_hufftab[][2]
static void add_noise(QDMCContext *s, int ch, int current_subframe)
static const uint8_t noise_bands_size[]
static const unsigned code_prefix[]
static int decode_frame(QDMCContext *s, GetBitContext *gb, int16_t *out)
static av_cold void qdmc_init_static_data(void)
#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
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 * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
float noise2_buffer[4096 *2]
float noise_buffer[4096 *2]
float fft_buffer[4][8192 *2]
VLC_TYPE(* table)[2]
code, bits
#define avpriv_request_sample(...)
static volatile int checksum
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const uint8_t offset[127][2]
#define INIT_VLC_STATIC_OVERLONG