38 #define BITSTREAM_READER_LE 54 #define QDM2_LIST_ADD(list, size, packet) \ 57 list[size - 1].next = &list[size]; \ 59 list[size].packet = packet; \ 60 list[size].next = NULL; \ 65 #define QDM2_SB_USED(sub_sampling) (((sub_sampling) >= 2) ? 30 : 8 << (sub_sampling)) 67 #define FIX_NOISE_IDX(noise_idx) \ 68 if ((noise_idx) >= 3840) \ 69 (noise_idx) -= 3840; \ 71 #define SB_DITHERING_NOISE(sb,noise_idx) (noise_table[(noise_idx)++] * sb_noise_attenuation[(sb)]) 73 #define SAMPLES_NEEDED \ 74 av_log (NULL,AV_LOG_INFO,"This file triggers some untested code. Please contact the developers.\n"); 76 #define SAMPLES_NEEDED_2(why) \ 77 av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why); 79 #define QDM2_MAX_FRAME_SIZE 512 162 int fft_coefs_min_index[5];
163 int fft_coefs_max_index[5];
164 int fft_level_exp[6];
216 0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
220 0, 5, 1, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 4
225 static VLC_TYPE qdm2_table[3838][2];
234 vlc_tab_diff.
table = &qdm2_table[qdm2_vlc_offs[1]];
241 vlc_tab_run.
table = &qdm2_table[qdm2_vlc_offs[2]];
248 fft_level_exp_alt_vlc.
table = &qdm2_table[qdm2_vlc_offs[3]];
251 init_vlc(&fft_level_exp_alt_vlc, 8, 28,
256 fft_level_exp_vlc.
table = &qdm2_table[qdm2_vlc_offs[4]];
257 fft_level_exp_vlc.
table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
263 fft_stereo_exp_vlc.
table = &qdm2_table[qdm2_vlc_offs[5]];
271 fft_stereo_phase_vlc.
table = &qdm2_table[qdm2_vlc_offs[6]];
274 init_vlc(&fft_stereo_phase_vlc, 6, 9,
279 vlc_tab_tone_level_idx_hi1.
table =
280 &qdm2_table[qdm2_vlc_offs[7]];
283 init_vlc(&vlc_tab_tone_level_idx_hi1, 8, 20,
288 vlc_tab_tone_level_idx_mid.
table =
289 &qdm2_table[qdm2_vlc_offs[8]];
292 init_vlc(&vlc_tab_tone_level_idx_mid, 8, 24,
297 vlc_tab_tone_level_idx_hi2.
table =
298 &qdm2_table[qdm2_vlc_offs[9]];
301 init_vlc(&vlc_tab_tone_level_idx_hi2, 8, 24,
306 vlc_tab_type30.
table = &qdm2_table[qdm2_vlc_offs[10]];
307 vlc_tab_type30.
table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
313 vlc_tab_type34.
table = &qdm2_table[qdm2_vlc_offs[11]];
314 vlc_tab_type34.
table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
320 vlc_tab_fft_tone_offset[0].
table =
321 &qdm2_table[qdm2_vlc_offs[12]];
324 init_vlc(&vlc_tab_fft_tone_offset[0], 8, 23,
329 vlc_tab_fft_tone_offset[1].
table =
330 &qdm2_table[qdm2_vlc_offs[13]];
333 init_vlc(&vlc_tab_fft_tone_offset[1], 8, 28,
338 vlc_tab_fft_tone_offset[2].
table =
339 &qdm2_table[qdm2_vlc_offs[14]];
342 init_vlc(&vlc_tab_fft_tone_offset[2], 8, 32,
347 vlc_tab_fft_tone_offset[3].
table =
348 &qdm2_table[qdm2_vlc_offs[15]];
351 init_vlc(&vlc_tab_fft_tone_offset[3], 8, 35,
356 vlc_tab_fft_tone_offset[4].
table =
357 &qdm2_table[qdm2_vlc_offs[16]];
360 init_vlc(&vlc_tab_fft_tone_offset[4], 8, 38,
380 if ((value & ~3) > 0)
392 return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
408 for (i = 0; i < length; i++)
411 return (uint16_t)(value & 0xffff);
425 if (sub_packet->
type == 0) {
426 sub_packet->
size = 0;
431 if (sub_packet->
type & 0x80) {
432 sub_packet->
size <<= 8;
434 sub_packet->
type &= 0x7f;
437 if (sub_packet->
type == 0x7f)
458 while (list && list->
packet) {
474 int i, j, n, ch, sum;
479 for (i = 0; i < n; i++) {
482 for (j = 0; j < 8; j++)
489 for (j = 0; j < 8; j++)
511 for (j = 0; j < 64; j++) {
535 for (ch = 0; ch < channels; ch++) {
536 for (j = 0; j < 64; ) {
537 if (coding_method[ch][sb][j] < 8)
539 if ((coding_method[ch][sb][j] - 8) > 22) {
543 switch (
switchtable[coding_method[ch][sb][j] - 8]) {
567 for (k = 0; k <
run; k++) {
569 if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j]) {
573 memset(&coding_method[ch][sb][j + k], case_val,
575 memset(&coding_method[ch][sb][j + k], case_val,
596 int i, sb, ch, sb_used;
600 for (sb = 0; sb < 30; sb++)
601 for (i = 0; i < 8; i++) {
615 for (sb = 0; sb < sb_used; sb++)
617 for (i = 0; i < 64; i++) {
626 for (sb = 0; sb < sb_used; sb++) {
627 if ((sb >= 4) && (sb <= 23)) {
629 for (i = 0; i < 64; i++) {
643 for (i = 0; i < 64; i++) {
655 for (i = 0; i < 64; i++) {
687 int c,
int superblocktype_2_3,
692 int add1, add2, add3, add4;
695 if (!superblocktype_2_3) {
699 for (sb = 0; sb < 30; sb++) {
700 for (j = 1; j < 63; j++) {
701 add1 = tone_level_idx[ch][sb][j] - 10;
704 add2 = add3 = add4 = 0;
720 tmp = tone_level_idx[ch][sb][j + 1] * 2 - add4 - add3 - add2 - add1;
723 tone_level_idx_temp[ch][sb][j + 1] = tmp & 0xff;
725 tone_level_idx_temp[ch][sb][0] = tone_level_idx_temp[ch][sb][1];
729 for (sb = 0; sb < 30; sb++)
730 for (j = 0; j < 64; j++)
731 acc += tone_level_idx_temp[ch][sb][j];
733 multres = 0x66666667LL * (acc * 10);
734 esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31);
736 for (sb = 0; sb < 30; sb++)
737 for (j = 0; j < 64; j++) {
738 comp = tone_level_idx_temp[ch][sb][j]* esp_40 * 10;
769 coding_method[ch][sb][j] = ((tmp & 0xfffa) + 30 )& 0xff;
771 for (sb = 0; sb < 30; sb++)
774 for (sb = 0; sb < 30; sb++)
775 for (j = 0; j < 64; j++)
777 if (coding_method[ch][sb][j] < 10)
778 coding_method[ch][sb][j] = 10;
781 if (coding_method[ch][sb][j] < 16)
782 coding_method[ch][sb][j] = 16;
784 if (coding_method[ch][sb][j] < 30)
785 coding_method[ch][sb][j] = 30;
790 for (sb = 0; sb < 30; sb++)
791 for (j = 0; j < 64; j++)
810 int length,
int sb_min,
int sb_max)
812 int sb, j, k, n, ch,
run, channels;
813 int joined_stereo, zero_encoding;
815 float type34_div = 0;
816 float type34_predictor;
817 float samples[10], sign_bits[16];
821 for (sb=sb_min; sb < sb_max; sb++)
827 for (sb = sb_min; sb < sb_max; sb++) {
839 for (j = 0; j < 16; j++)
842 for (j = 0; j < 64; j++)
854 for (ch = 0; ch < channels; ch++) {
857 type34_predictor = 0.0;
860 for (j = 0; j < 128; ) {
865 for (k = 0; k < 5; k++) {
866 if ((j + 2 * k) >= 128)
872 for (k = 0; k < 5; k++)
875 for (k = 0; k < 5; k++)
878 for (k = 0; k < 10; k++)
890 f -=
noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;
901 for (k = 0; k < 5; k++) {
908 for (k = 0; k < 5; k++)
912 for (k = 0; k < 5; k++)
921 for (k = 0; k < 3; k++)
924 for (k = 0; k < 3; k++)
946 type34_div = (float)(1 <<
get_bits(gb, 2));
947 samples[0] = ((float)
get_bits(gb, 5) - 16.0) / 15.0;
948 type34_predictor = samples[0];
954 type34_predictor = samples[0];
971 for (k = 0; k < run && j + k < 128; k++) {
973 q->
tone_level[0][sb][(j + k) / 2] * samples[k];
975 if (sign_bits[(j + k) / 8])
977 q->
tone_level[1][sb][(j + k) / 2] * -samples[k];
980 q->
tone_level[1][sb][(j + k) / 2] * samples[k];
984 for (k = 0; k <
run; k++)
1014 quantized_coeffs[0] =
level;
1016 for (i = 0; i < 7; ) {
1025 for (k = 1; k <=
run; k++)
1026 quantized_coeffs[i + k] = (level + ((k * diff) / run));
1044 int sb, j, k, n, ch;
1057 for (sb = 0; sb < n; sb++)
1059 for (j = 0; j < 8; j++) {
1063 for (k=0; k < 8; k++) {
1069 for (k=0; k < 8; k++)
1076 for (sb = 0; sb < n; sb++)
1084 for (j = 0; j < 8; j++)
1090 for (sb = 0; sb < n; sb++)
1092 for (j = 0; j < 8; j++) {
1108 int i, j, k, n, ch,
run,
level, diff;
1114 for (i = 1; i < n; i++)
1119 for (j = 0; j < (8 - 1); ) {
1123 for (k = 1; k <=
run; k++)
1132 for (i = 0; i < 8; i++)
1224 if (nodes[0] && nodes[1] && nodes[2])
1230 if (nodes[0] && nodes[1] && nodes[3])
1245 int i, packet_bytes, sub_packet_size, sub_packets_D;
1246 unsigned int next_index = 0;
1260 if (header.
type < 2 || header.
type >= 8) {
1271 if (header.
type == 2 || header.
type == 4 || header.
type == 5) {
1287 for (i = 0; i < 6; i++)
1291 for (i = 0; packet_bytes > 0; i++) {
1308 if (next_index >= header.
size)
1316 sub_packet_size = ((packet->
size > 0xff) ? 1 : 0) + packet->
size + 2;
1318 if (packet->
type == 0)
1321 if (sub_packet_size > packet_bytes) {
1322 if (packet->
type != 10 && packet->
type != 11 && packet->
type != 12)
1324 packet->
size += packet_bytes - sub_packet_size;
1327 packet_bytes -= sub_packet_size;
1333 if (packet->
type == 8) {
1336 }
else if (packet->
type >= 9 && packet->
type <= 12) {
1339 }
else if (packet->
type == 13) {
1340 for (j = 0; j < 6; j++)
1342 }
else if (packet->
type == 14) {
1343 for (j = 0; j < 6; j++)
1345 }
else if (packet->
type == 15) {
1348 }
else if (packet->
type >= 16 && packet->
type < 48 &&
1366 int offset,
int duration,
int channel,
1373 ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
1384 int channel, stereo, phase, exp;
1385 int local_int_4, local_int_8, stereo_phase, local_int_10;
1386 int local_int_14, stereo_exp, local_int_20, local_int_28;
1393 local_int_10 = 1 << (q->
group_order - duration - 1);
1398 while ((n =
qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) {
1401 local_int_4 += local_int_10;
1402 local_int_28 += (1 << local_int_8);
1404 local_int_4 += 8 * local_int_10;
1405 local_int_28 += (8 << local_int_8);
1410 offset +=
qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2);
1411 while (offset >= (local_int_10 - 1)) {
1412 offset += (1 - (local_int_10 - 1));
1413 local_int_4 += local_int_10;
1414 local_int_28 += (1 << local_int_8);
1421 local_int_14 = (offset >> local_int_8);
1433 exp =
qdm2_get_vlc(gb, (b ? &fft_level_exp_vlc : &fft_level_exp_alt_vlc), 0, 2);
1435 exp = (exp < 0) ? 0 : exp;
1442 stereo_exp = (exp -
qdm2_get_vlc(gb, &fft_stereo_exp_vlc, 0, 1));
1443 stereo_phase = (phase -
qdm2_get_vlc(gb, &fft_stereo_phase_vlc, 0, 1));
1444 if (stereo_phase < 0)
1449 int sub_packet = (local_int_20 + local_int_28);
1452 channel, exp, phase);
1456 stereo_exp, stereo_phase);
1464 int i, j,
min, max, value, type, unknown_flag;
1472 for (i = 0; i < 5; i++)
1482 if (value > min && value < max) {
1495 (packet->
type < 16 || packet->
type >= 48 ||
1507 type = packet->
type;
1509 if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {
1512 if (duration >= 0 && duration < 4)
1514 }
else if (type == 31) {
1515 for (j = 0; j < 4; j++)
1517 }
else if (type == 46) {
1518 for (j = 0; j < 6; j++)
1520 for (j = 0; j < 4; j++)
1526 for (i = 0, j = -1; i < 5; i++)
1541 const double iscale = 2.0 * M_PI / 512.0;
1547 c.
im = level * sin(tone->
phase * iscale);
1548 c.
re = level * cos(tone->
phase * iscale);
1557 f[1] = -tone->
table[4];
1559 f[2] = 1.0 - tone->
table[2] - tone->
table[3];
1560 f[3] = tone->
table[1] + tone->
table[4] - 1.0;
1562 f[5] = tone->
table[2];
1563 for (i = 0; i < 2; i++) {
1567 c.
im * ((tone->
cutoff <= i) ? -f[i] : f[i]);
1569 for (i = 0; i < 4; i++) {
1585 const double iscale = 0.25 * M_PI;
1587 for (ch = 0; ch < q->
channels; ch++) {
1619 for (i = 0; i < 4; i++)
1632 if (offset < q->frequency_range) {
1636 tone.
cutoff = (offset >= 60) ? 3 : 2;
1675 int i, k, ch, sb_used, sub_sampling, dither_state = 0;
1680 for (ch = 0; ch < q->
channels; ch++)
1681 for (i = 0; i < 8; i++)
1682 for (k = sb_used; k <
SBLIMIT; k++)
1686 float *samples_ptr = q->
samples + ch;
1688 for (i = 0; i < 8; i++) {
1701 for (ch = 0; ch < q->
channels; ch++)
1727 int tmp_val, tmp,
size;
1771 while (extradata_size > 7) {
1772 if (!memcmp(extradata,
"frmaQDM", 7))
1778 if (extradata_size < 12) {
1784 if (memcmp(extradata,
"frmaQDM", 7)) {
1789 if (extradata[7] ==
'C') {
1796 extradata_size -= 8;
1800 if(size > extradata_size){
1802 extradata_size, size);
1852 case 0: tmp = 40;
break;
1853 case 1: tmp = 48;
break;
1854 case 2: tmp = 56;
break;
1855 case 3: tmp = 72;
break;
1856 case 4: tmp = 80;
break;
1857 case 5: tmp = 100;
break;
1861 if ((tmp * 1000) < avctx->
bit_rate) tmp_val = 1;
1862 if ((tmp * 1440) < avctx->
bit_rate) tmp_val = 2;
1863 if ((tmp * 1760) < avctx->
bit_rate) tmp_val = 3;
1864 if ((tmp * 2240) < avctx->
bit_rate) tmp_val = 4;
1878 else if (tmp <= 16000)
1921 memset(&q->
output_buffer[frame_size], 0, frame_size *
sizeof(
float));
1939 for (ch = 0; ch < q->
channels; ch++) {
1970 int *got_frame_ptr,
AVPacket *avpkt)
1974 int buf_size = avpkt->
size;
1981 if(buf_size < s->checksum_size)
1990 out = (int16_t *)frame->
data[0];
1992 for (i = 0; i < 16; i++) {
static av_cold void qdm2_init_static_data(AVCodec *codec)
Init static data (does not depend on specific file)
av_cold void ff_rdft_end(RDFTContext *s)
static const uint16_t vlc_tab_tone_level_idx_mid_huffcodes[24]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
FFTTone fft_tones[1000]
FFT and tones.
static const uint8_t vlc_tab_level_huffbits[24]
A node in the subpacket list.
This structure describes decoded (raw) audio or video data.
static int fix_coding_method_array(int sb, int channels, sb_int8_array coding_method)
Called while processing data from subpackets 11 and 12.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static const float fft_tone_level_table[2][64]
static void average_quantized_coeffs(QDM2Context *q)
Replace 8 elements with their average value.
static void synthfilt_build_sb_samples(QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max)
Called by process_subpacket_11 to process more data from subpacket 11 with sb 0-8.
#define QDM2_MAX_FRAME_SIZE
float synth_buf[MPA_MAX_CHANNELS][512 *2]
static const uint8_t vlc_tab_type34_huffbits[10]
static const uint8_t fft_level_exp_alt_huffbits[28]
#define DECLARE_ALIGNED(n, t, v)
static const uint16_t vlc_tab_fft_tone_offset_0_huffcodes[23]
int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8]
static const uint8_t fft_stereo_phase_huffbits[9]
int coeff_per_sb_select
selector for "num. of coeffs. per subband" tables. Can be 0, 1, 2
static av_cold int qdm2_decode_close(AVCodecContext *avctx)
unsigned int size
subpacket size
int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26]
#define FF_ARRAY_ELEMS(a)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
float sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]
#define AV_CH_LAYOUT_STEREO
static void qdm2_decode_sub_packet_header(GetBitContext *gb, QDM2SubPacket *sub_packet)
Fill a QDM2SubPacket structure with packet type, size, and data pointer.
static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD+1]
static void qdm2_fft_init_coefficient(QDM2Context *q, int sub_packet, int offset, int duration, int channel, int exp, int phase)
QDM2SubPNode sub_packet_list_C[16]
packets with errors?
static QDM2SubPNode * qdm2_search_subpacket_type_in_list(QDM2SubPNode *list, int type)
Return node pointer to first packet of requested type in list.
static VLC vlc_tab_tone_level_idx_hi1
static VLC vlc_tab_type30
static av_cold int qdm2_decode_init(AVCodecContext *avctx)
Init parameters from codec extradata.
static VLC vlc_tab_fft_tone_offset[5]
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
enum AVSampleFormat sample_fmt
audio sample format
int fft_order
order of FFT (actually fftorder+1)
static void qdm2_decode_fft_packets(QDM2Context *q)
int sub_sampling
subsampling: 0=25%, 1=50%, 2=100% */
void ff_mpa_synth_init_float(float *window)
#define SOFTCLIP_THRESHOLD
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void qdm2_fft_tone_synthesizer(QDM2Context *q, int sub_packet)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static const int16_t fft_level_index_table[256]
static const float fft_tone_envelope_table[4][31]
static const uint8_t vlc_tab_tone_level_idx_hi2_huffbits[24]
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
static const uint8_t coeff_per_sb_for_dequant[3][30]
int checksum_size
size of data block, used also for checksum
static const uint16_t vlc_tab_fft_tone_offset_1_huffcodes[28]
static void process_subpacket_12(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 12.
static int qdm2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static const uint8_t fft_subpackets[32]
static const uint8_t vlc_tab_run_huffbits[6]
static const uint8_t vlc_tab_tone_level_idx_mid_huffbits[24]
static const uint8_t vlc_tab_type30_huffbits[9]
int channels
number of channels
static void fill_tone_level_array(QDM2Context *q, int flag)
Related to synthesis filter Called by process_subpacket_10.
static const uint8_t frame_size[4]
static const uint8_t fft_stereo_exp_huffbits[7]
static int get_bits_left(GetBitContext *gb)
int synth_buf_offset[MPA_MAX_CHANNELS]
static av_cold void rnd_table_init(void)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t random_dequant_type24[128][3]
static const uint8_t vlc_tab_fft_tone_offset_4_huffbits[38]
const uint8_t * data
pointer to subpacket data (points to input data buffer, it's not a private copy)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
float output_buffer[QDM2_MAX_FRAME_SIZE *2]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const int switchtable[23]
int group_size
size of frame group (16 frames per group)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void ff_mpa_synth_filter_float(MPADSPContext *s, float *synth_buf_ptr, int *synth_buf_offset, float *window, int *dither_state, float *samples, int incr, float *sb_samples)
static const uint16_t vlc_tab_level_huffcodes[24]
VLC TABLES.
int sub_packets_B
number of packets on 'B' list
QDM2SubPNode sub_packet_list_A[16]
list of all packets
void av_log(void *avcl, int level, const char *fmt,...)
int noise_idx
index for dithering noise table
const char * name
Name of the codec implementation.
static VLC fft_level_exp_alt_vlc
float tone_level[MPA_MAX_CHANNELS][30][64]
Mixed temporary data used in decoding.
static const uint16_t vlc_tab_fft_tone_offset_4_huffcodes[38]
uint64_t channel_layout
Audio channel layout.
#define init_vlc(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8]
static void qdm2_synthesis_filter(QDM2Context *q, int index)
static void output_buffer(int16_t **samples, int nchan, int blocksize, int32_t **buffer)
#define QDM2_SB_USED(sub_sampling)
int group_order
Parameters built from header parameters, do not change during playback.
int bit_rate
the average bitrate
static const uint8_t vlc_tab_run_huffcodes[6]
audio channel layout utility functions
static const uint8_t vlc_tab_fft_tone_offset_1_huffbits[28]
static float noise_samples[128]
QDM2SubPNode sub_packet_list_B[16]
FFT packets B are on list.
static const uint16_t fft_level_exp_alt_huffcodes[28]
FFT TABLES.
static const uint8_t vlc_tab_diff_huffbits[37]
struct QDM2SubPNode * next
pointer to next packet in the list, NULL if leaf node
static const int8_t tone_level_idx_offset_table[30][4]
static VLC vlc_tab_type34
float ff_mpa_synth_window_float[]
static VLC fft_stereo_exp_vlc
static void qdm2_decode_super_block(QDM2Context *q)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define SAMPLES_NEEDED_2(why)
static const int8_t coding_method_table[5][30]
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
QDM2 checksum.
static const uint16_t vlc_tab_tone_level_idx_hi1_huffcodes[20]
#define QDM2_LIST_ADD(list, size, packet)
static uint8_t random_dequant_index[256][5]
static const float type30_dequant[8]
static VLC vlc_tab_tone_level_idx_hi2
static VLC fft_level_exp_vlc
#define INIT_VLC_USE_NEW_STATIC
QDM2Complex complex[MPA_MAX_CHANNELS][256]
static const float type34_delta[10]
if(ac->has_optimized_func)
static const float dequant_1bit[2][3]
static const uint8_t fft_stereo_exp_huffcodes[7]
static void build_sb_samples_from_noise(QDM2Context *q, int sb)
Build subband samples with noise weighted by q->tone_level.
float samples[MPA_MAX_CHANNELS *MPA_FRAME_SIZE]
static const uint8_t last_coeff[3]
Libavcodec external API header.
static const int fft_cutoff_index_table[4][2]
int sample_rate
samples per second
static void qdm2_fft_decode_tones(QDM2Context *q, int duration, GetBitContext *gb, int b)
static const uint8_t coeff_per_sb_for_avg[3][30]
int8_t tone_level_idx_mid[MPA_MAX_CHANNELS][26][8]
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int fft_coefs_min_index[5]
static void process_subpacket_9(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 9, init quantized_coeffs with data from it.
FFTCoefficient fft_coefs[1000]
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
int has_errors
packet has errors
static const uint8_t dequant_table[64]
static const uint16_t vlc_tab_fft_tone_offset_2_huffcodes[32]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void fill_coding_method_array(sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp, sb_int8_array coding_method, int nb_channels, int c, int superblocktype_2_3, int cm_table_select)
Related to synthesis filter Called by process_subpacket_11 c is built with data from subpacket 11 Mos...
#define HARDCLIP_THRESHOLD
static const uint8_t vlc_tab_type34_huffcodes[10]
int8_t coding_method[MPA_MAX_CHANNELS][30][64]
static int qdm2_get_se_vlc(VLC *vlc, GetBitContext *gb, int depth)
static void process_subpacket_10(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 10 if not null, else.
static void init_quantized_coeffs_elem0(int8_t *quantized_coeffs, GetBitContext *gb)
Init the first element of a channel in quantized_coeffs with data from packet 10 (quantized_coeffs[ch...
static av_cold void softclip_table_init(void)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int fft_size
size of FFT, in complex numbers
static const uint8_t vlc_tab_fft_tone_offset_0_huffbits[23]
int fft_coefs_max_index[5]
int frame_size
size of data frame
static int qdm2_decode(QDM2Context *q, const uint8_t *in, int16_t *out)
#define FIX_NOISE_IDX(noise_idx)
static const float fft_tone_sample_table[4][16][5]
int8_t tone_level_idx_hi1[MPA_MAX_CHANNELS][3][8][8]
int nb_channels
Parameters from codec header, do not change during playback.
int superblocktype_2_3
select fft tables and some algorithm based on superblock type
static const uint8_t fft_stereo_phase_huffcodes[9]
common internal api header.
static const uint16_t vlc_tab_tone_level_idx_hi2_huffcodes[24]
static const uint16_t vlc_tab_fft_tone_offset_3_huffcodes[35]
int cm_table_select
selector for "coding method" tables. Can be 0, 1 (from init: 0-4)
QDM2SubPacket * packet
packet
QDM2SubPacket sub_packets[16]
Packets and packet lists.
static const int vlc_stage3_values[60]
static const uint8_t vlc_tab_fft_tone_offset_2_huffbits[32]
mpeg audio declarations for both encoder and decoder.
static const uint16_t vlc_tab_diff_huffcodes[37]
int do_synth_filter
used to perform or skip synthesis filter
const uint8_t * compressed_data
I/O data.
static av_cold int init(AVCodecParserContext *s)
int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64]
#define MKBETAG(a, b, c, d)
static void process_subpacket_11(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 11.
static int qdm2_get_vlc(GetBitContext *gb, VLC *vlc, int flag, int depth)
MPADSPContext mpadsp
Synthesis filter.
static void init_tone_level_dequantization(QDM2Context *q, GetBitContext *gb)
Related to synthesis filter, process data from packet 10 Init part of quantized_coeffs via function i...
static VLC fft_stereo_phase_vlc
int channels
number of audio channels
static const uint8_t vlc_tab_tone_level_idx_hi1_huffbits[20]
static void qdm2_fft_generate_tone(QDM2Context *q, FFTTone *tone)
QDM2SubPNode sub_packet_list_D[16]
DCT packets.
static VLC vlc_tab_tone_level_idx_mid
int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64]
VLC_TYPE(* table)[2]
code, bits
static const uint16_t qdm2_vlc_offs[]
static const uint8_t vlc_tab_type30_huffcodes[9]
static const uint8_t fft_level_exp_huffbits[20]
static const struct twinvq_data tab
static av_cold void qdm2_init_vlc(void)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
int8_t sb_int8_array[2][30][64]
#define SB_DITHERING_NOISE(sb, noise_idx)
static void qdm2_calculate_fft(QDM2Context *q, int channel, int sub_packet)
static const uint8_t vlc_tab_fft_tone_offset_3_huffbits[35]
static void process_synthesis_subpackets(QDM2Context *q, QDM2SubPNode *list)
#define AV_CH_LAYOUT_MONO
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
This structure stores compressed data.
av_cold void ff_mpadsp_init(MPADSPContext *s)
static const uint16_t fft_level_exp_huffcodes[20]
static av_cold void init_noise_samples(void)
int nb_samples
number of audio samples (per channel) described by this frame