40 #define BITSTREAM_READER_LE
50 #define QDM2_LIST_ADD(list, size, packet) \
53 list[size - 1].next = &list[size]; \
55 list[size].packet = packet; \
56 list[size].next = NULL; \
61 #define QDM2_SB_USED(sub_sampling) (((sub_sampling) >= 2) ? 30 : 8 << (sub_sampling))
63 #define FIX_NOISE_IDX(noise_idx) \
64 if ((noise_idx) >= 3840) \
65 (noise_idx) -= 3840; \
67 #define SB_DITHERING_NOISE(sb,noise_idx) (noise_table[(noise_idx)++] * sb_noise_attenuation[(sb)])
69 #define SAMPLES_NEEDED \
70 av_log (NULL,AV_LOG_INFO,"This file triggers some untested code. Please contact the developers.\n");
72 #define SAMPLES_NEEDED_2(why) \
73 av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
75 #define QDM2_MAX_FRAME_SIZE 512
197 0, 5, 1, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5, 3, 5, 5, 5, 5, 5, 4
221 if ((value & ~3) > 0)
233 return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
249 for (i = 0; i <
length; i++)
252 return (uint16_t)(value & 0xffff);
266 if (sub_packet->
type == 0) {
267 sub_packet->
size = 0;
272 if (sub_packet->
type & 0x80) {
273 sub_packet->
size <<= 8;
275 sub_packet->
type &= 0x7f;
278 if (sub_packet->
type == 0x7f)
299 while (list && list->
packet) {
315 int i, j,
n,
ch, sum;
320 for (i = 0; i <
n; i++) {
323 for (j = 0; j < 8; j++)
330 for (j = 0; j < 8; j++)
352 for (j = 0; j < 64; j++) {
376 for (ch = 0; ch < channels; ch++) {
377 for (j = 0; j < 64; ) {
378 if (coding_method[ch][sb][j] < 8)
380 if ((coding_method[ch][sb][j] - 8) > 22) {
384 switch (
switchtable[coding_method[ch][sb][j] - 8]) {
408 for (k = 0; k <
run; k++) {
410 if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j]) {
414 memset(&coding_method[ch][sb][j + k], case_val,
416 memset(&coding_method[ch][sb][j + k], case_val,
437 int i, sb,
ch, sb_used;
441 for (sb = 0; sb < 30; sb++)
442 for (i = 0; i < 8; i++) {
456 for (sb = 0; sb < sb_used; sb++)
458 for (i = 0; i < 64; i++) {
467 for (sb = 0; sb < sb_used; sb++) {
468 if ((sb >= 4) && (sb <= 23)) {
470 for (i = 0; i < 64; i++) {
484 for (i = 0; i < 64; i++) {
496 for (i = 0; i < 64; i++) {
528 int c,
int superblocktype_2_3,
533 int add1, add2, add3, add4;
536 if (!superblocktype_2_3) {
541 for (sb = 0; sb < 30; sb++) {
542 for (j = 1; j < 63; j++) {
543 add1 = tone_level_idx[
ch][sb][j] - 10;
546 add2 = add3 = add4 = 0;
562 tmp = tone_level_idx[
ch][sb][j + 1] * 2 - add4 - add3 - add2 - add1;
565 tone_level_idx_temp[
ch][sb][j + 1] = tmp & 0xff;
567 tone_level_idx_temp[
ch][sb][0] = tone_level_idx_temp[
ch][sb][1];
572 for (sb = 0; sb < 30; sb++)
573 for (j = 0; j < 64; j++)
574 acc += tone_level_idx_temp[ch][sb][j];
576 multres = 0x66666667LL * (acc * 10);
577 esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31);
579 for (sb = 0; sb < 30; sb++)
580 for (j = 0; j < 64; j++) {
581 comp = tone_level_idx_temp[
ch][sb][j]* esp_40 * 10;
612 coding_method[
ch][sb][j] = ((tmp & 0xfffa) + 30 )& 0xff;
614 for (sb = 0; sb < 30; sb++)
617 for (sb = 0; sb < 30; sb++)
618 for (j = 0; j < 64; j++)
620 if (coding_method[ch][sb][j] < 10)
621 coding_method[
ch][sb][j] = 10;
624 if (coding_method[ch][sb][j] < 16)
625 coding_method[
ch][sb][j] = 16;
627 if (coding_method[ch][sb][j] < 30)
628 coding_method[
ch][sb][j] = 30;
633 for (sb = 0; sb < 30; sb++)
634 for (j = 0; j < 64; j++)
652 int length,
int sb_min,
int sb_max)
654 int sb, j, k,
n,
ch,
run, channels;
655 int joined_stereo, zero_encoding;
657 float type34_div = 0;
658 float type34_predictor;
660 int sign_bits[16] = {0};
664 for (sb=sb_min; sb < sb_max; sb++)
670 for (sb = sb_min; sb < sb_max; sb++) {
682 for (j = 0; j < 16; j++)
685 for (j = 0; j < 64; j++)
698 for (ch = 0; ch < channels; ch++) {
701 type34_predictor = 0.0;
704 for (j = 0; j < 128; ) {
709 for (k = 0; k < 5; k++) {
710 if ((j + 2 * k) >= 128)
721 for (k = 0; k < 5; k++)
724 for (k = 0; k < 5; k++)
727 for (k = 0; k < 10; k++)
739 f -=
noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;
750 for (k = 0; k < 5; k++) {
762 for (k = 0; k < 5; k++)
766 for (k = 0; k < 5; k++)
780 for (k = 0; k < 3; k++)
783 for (k = 0; k < 3; k++)
806 type34_div = (float)(1 <<
get_bits(gb, 2));
807 samples[0] = ((float)
get_bits(gb, 5) - 16.0) / 15.0;
808 type34_predictor = samples[0];
817 type34_predictor = samples[0];
832 for (k = 0; k < run && j + k < 128; k++) {
834 q->
tone_level[0][sb][(j + k) / 2] * samples[k];
836 if (sign_bits[(j + k) / 8])
838 q->
tone_level[1][sb][(j + k) / 2] * -samples[k];
841 q->
tone_level[1][sb][(j + k) / 2] * samples[k];
845 for (k = 0; k <
run; k++)
876 quantized_coeffs[0] =
level;
878 for (i = 0; i < 7; ) {
890 for (k = 1; k <=
run; k++)
891 quantized_coeffs[i + k] = (level + ((k * diff) / run));
923 for (sb = 0; sb <
n; sb++)
925 for (j = 0; j < 8; j++) {
929 for (k=0; k < 8; k++) {
935 for (k=0; k < 8; k++)
942 for (sb = 0; sb <
n; sb++)
950 for (j = 0; j < 8; j++)
956 for (sb = 0; sb <
n; sb++)
958 for (j = 0; j < 8; j++) {
980 for (i = 1; i <
n; i++)
985 for (j = 0; j < (8 - 1); ) {
992 for (k = 1; k <=
run; k++)
1001 for (i = 0; i < 8; i++)
1095 if (nodes[0] && nodes[1] && nodes[2])
1101 if (nodes[0] && nodes[1] && nodes[3])
1116 int i, packet_bytes, sub_packet_size, sub_packets_D;
1117 unsigned int next_index = 0;
1131 if (header.
type < 2 || header.
type >= 8) {
1142 if (header.
type == 2 || header.
type == 4 || header.
type == 5) {
1158 for (i = 0; i < 6; i++)
1162 for (i = 0; packet_bytes > 0; i++) {
1179 if (next_index >= header.
size)
1187 sub_packet_size = ((packet->
size > 0xff) ? 1 : 0) + packet->
size + 2;
1189 if (packet->
type == 0)
1192 if (sub_packet_size > packet_bytes) {
1193 if (packet->
type != 10 && packet->
type != 11 && packet->
type != 12)
1195 packet->
size += packet_bytes - sub_packet_size;
1198 packet_bytes -= sub_packet_size;
1204 if (packet->
type == 8) {
1207 }
else if (packet->
type >= 9 && packet->
type <= 12) {
1210 }
else if (packet->
type == 13) {
1211 for (j = 0; j < 6; j++)
1213 }
else if (packet->
type == 14) {
1214 for (j = 0; j < 6; j++)
1216 }
else if (packet->
type == 15) {
1219 }
else if (packet->
type >= 16 && packet->
type < 48 &&
1244 ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
1255 int channel, stereo, phase,
exp;
1256 int local_int_4, local_int_8, stereo_phase, local_int_10;
1257 int local_int_14, stereo_exp, local_int_20, local_int_28;
1264 local_int_10 = 1 << (q->
group_order - duration - 1);
1271 if(local_int_4 < q->group_size)
1277 local_int_4 += local_int_10;
1278 local_int_28 += (1 << local_int_8);
1280 local_int_4 += 8 * local_int_10;
1281 local_int_28 += (8 << local_int_8);
1287 while (offset >= (local_int_10 - 1)) {
1288 offset += (1 - (local_int_10 - 1));
1289 local_int_4 += local_int_10;
1290 local_int_28 += (1 << local_int_8);
1297 local_int_14 = (offset >> local_int_8);
1311 exp = (exp < 0) ? 0 : exp;
1320 if (stereo_phase < 0)
1325 int sub_packet = (local_int_20 + local_int_28);
1328 channel, exp, phase);
1332 stereo_exp, stereo_phase);
1348 for (i = 0; i < 5; i++)
1358 if (value > min && value < max) {
1371 (packet->
type < 16 || packet->
type >= 48 ||
1383 type = packet->
type;
1385 if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {
1388 if (duration >= 0 && duration < 4)
1390 }
else if (type == 31) {
1391 for (j = 0; j < 4; j++)
1393 }
else if (type == 46) {
1394 for (j = 0; j < 6; j++)
1396 for (j = 0; j < 4; j++)
1402 for (i = 0, j = -1; i < 5; i++)
1417 const double iscale = 2.0 *
M_PI / 512.0;
1423 c.
im = level * sin(tone->
phase * iscale);
1424 c.
re = level * cos(tone->
phase * iscale);
1433 f[1] = -tone->
table[4];
1435 f[2] = 1.0 - tone->
table[2] - tone->
table[3];
1436 f[3] = tone->
table[1] + tone->
table[4] - 1.0;
1438 f[5] = tone->
table[2];
1439 for (i = 0; i < 2; i++) {
1443 c.
im * ((tone->
cutoff <= i) ? -f[i] : f[i]);
1445 for (i = 0; i < 4; i++) {
1461 const double iscale = 0.25 *
M_PI;
1463 for (ch = 0; ch < q->
channels; ch++) {
1495 for (i = 0; i < 4; i++)
1508 if (offset < q->frequency_range) {
1512 tone.
cutoff = (offset >= 60) ? 3 : 2;
1551 int i, k,
ch, sb_used, sub_sampling, dither_state = 0;
1556 for (ch = 0; ch < q->
channels; ch++)
1557 for (i = 0; i < 8; i++)
1558 for (k = sb_used; k <
SBLIMIT; k++)
1564 for (i = 0; i < 8; i++) {
1577 for (ch = 0; ch < q->
channels; ch++)
1656 while (extradata_size > 7) {
1657 if (!memcmp(extradata,
"frmaQDM", 7))
1663 if (extradata_size < 12) {
1669 if (memcmp(extradata,
"frmaQDM", 7)) {
1674 if (extradata[7] ==
'C') {
1681 extradata_size -= 8;
1685 if(size > extradata_size){
1687 extradata_size, size);
1740 case 0: tmp = 40;
break;
1741 case 1: tmp = 48;
break;
1742 case 2: tmp = 56;
break;
1743 case 3: tmp = 72;
break;
1744 case 4: tmp = 80;
break;
1745 case 5: tmp = 100;
break;
1749 if ((tmp * 1000) < avctx->
bit_rate) tmp_val = 1;
1750 if ((tmp * 1440) < avctx->
bit_rate) tmp_val = 2;
1751 if ((tmp * 1760) < avctx->
bit_rate) tmp_val = 3;
1752 if ((tmp * 2240) < avctx->
bit_rate) tmp_val = 4;
1803 memset(&q->
output_buffer[frame_size], 0, frame_size *
sizeof(
float));
1821 for (ch = 0; ch < q->
channels; ch++) {
1852 int *got_frame_ptr,
AVPacket *avpkt)
1856 int buf_size = avpkt->
size;
1863 if(buf_size < s->checksum_size)
1870 out = (int16_t *)frame->
data[0];
1872 for (i = 0; i < 16; i++) {
av_cold void ff_rdft_end(RDFTContext *s)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
FFTTone fft_tones[1000]
FFT and tones.
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.
ptrdiff_t const GLvoid * data
static int 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 unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int64_t bit_rate
the average bitrate
static const float fft_tone_level_table[2][64]
static av_cold int init(AVCodecContext *avctx)
static void average_quantized_coeffs(QDM2Context *q)
Replace 8 elements with their average value.
static VLC vlc_tab_tone_level_idx_hi2
#define QDM2_MAX_FRAME_SIZE
float synth_buf[MPA_MAX_CHANNELS][512 *2]
int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8]
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]
float sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]
#define AV_CH_LAYOUT_STEREO
static VLC fft_stereo_exp_vlc
static void qdm2_decode_sub_packet_header(GetBitContext *gb, QDM2SubPacket *sub_packet)
Fill a QDM2SubPacket structure with packet type, size, and data pointer.
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_type30
static av_cold int qdm2_decode_init(AVCodecContext *avctx)
Init parameters from codec extradata.
static int qdm2_get_vlc(GetBitContext *gb, const VLC *vlc, int flag, int depth)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static const int16_t fft_level_index_table[256]
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const float fft_tone_envelope_table[4][31]
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 uint8_t header[24]
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 av_cold void qdm2_init_static_data(void)
Init static data (does not depend on specific file)
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 int 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.
static av_cold void qdm2_init_vlc(void)
static int get_bits_left(GetBitContext *gb)
int synth_buf_offset[MPA_MAX_CHANNELS]
static VLC fft_level_exp_vlc
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]
const uint8_t * data
pointer to subpacket data (points to input data buffer, it's not a private copy)
static VLC vlc_tab_tone_level_idx_mid
#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)
int sub_packets_B
number of packets on 'B' list
QDM2SubPNode sub_packet_list_A[16]
list of all packets
int noise_idx
index for dithering noise table
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
float tone_level[MPA_MAX_CHANNELS][30][64]
Mixed temporary data used in decoding.
uint64_t channel_layout
Audio channel layout.
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8]
static void qdm2_synthesis_filter(QDM2Context *q, int index)
static VLC vlc_tab_tone_level_idx_hi1
#define QDM2_SB_USED(sub_sampling)
int group_order
Parameters built from header parameters, do not change during playback.
static VLC fft_level_exp_alt_vlc
audio channel layout utility functions
static float noise_samples[128]
QDM2SubPNode sub_packet_list_B[16]
FFT packets B are on list.
struct QDM2SubPNode * next
pointer to next packet in the list, NULL if leaf node
GLsizei GLboolean const GLfloat * value
static const int8_t tone_level_idx_offset_table[30][4]
float ff_mpa_synth_window_float[]
static void qdm2_decode_super_block(QDM2Context *q)
Decode superblock, fill packet lists.
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]
static VLC fft_stereo_phase_vlc
static uint16_t qdm2_packet_checksum(const uint8_t *data, int length, int value)
QDM2 checksum.
#define QDM2_LIST_ADD(list, size, packet)
static uint8_t random_dequant_index[256][5]
static const float type30_dequant[8]
static uint16_t softclip_table[HARDCLIP_THRESHOLD-SOFTCLIP_THRESHOLD+1]
#define FF_ARRAY_ELEMS(a)
QDM2Complex complex[MPA_MAX_CHANNELS][256]
static const float type34_delta[10]
static VLC vlc_tab_fft_tone_offset[5]
static const float dequant_1bit[2][3]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
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 int qdm2_get_se_vlc(const VLC *vlc, GetBitContext *gb, int depth)
float output_buffer[QDM2_MAX_FRAME_SIZE *MPA_MAX_CHANNELS *2]
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int fft_coefs_min_index[5]
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 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
int8_t coding_method[MPA_MAX_CHANNELS][30][64]
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static void process_subpacket_10(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 10 if not null, else.
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
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
common internal api header.
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]
mpeg audio declarations for both encoder and decoder.
int do_synth_filter
used to perform or skip synthesis filter
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
const uint8_t * compressed_data
I/O data.
int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64]
static int process_subpacket_9(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 9, init quantized_coeffs with data from it.
#define MKBETAG(a, b, c, d)
static void process_subpacket_11(QDM2Context *q, QDM2SubPNode *node)
Process subpacket 11.
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 av_always_inline int diff(const uint32_t a, const uint32_t b)
int channels
number of audio channels
static void qdm2_fft_generate_tone(QDM2Context *q, FFTTone *tone)
QDM2SubPNode sub_packet_list_D[16]
DCT packets.
int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64]
VLC_TYPE(* table)[2]
code, bits
static const struct twinvq_data tab
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
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 void process_synthesis_subpackets(QDM2Context *q, QDM2SubPNode *list)
Process new subpackets for synthesis filter.
#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 av_cold void init_noise_samples(void)
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.
static VLC vlc_tab_type34