00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 #include <math.h>
00035 #include <stddef.h>
00036 #include <stdio.h>
00037
00038 #define BITSTREAM_READER_LE
00039 #include "avcodec.h"
00040 #include "get_bits.h"
00041 #include "dsputil.h"
00042 #include "rdft.h"
00043 #include "mpegaudiodsp.h"
00044 #include "mpegaudio.h"
00045
00046 #include "qdm2data.h"
00047 #include "qdm2_tablegen.h"
00048
00049 #undef NDEBUG
00050 #include <assert.h>
00051
00052
00053 #define QDM2_LIST_ADD(list, size, packet) \
00054 do { \
00055 if (size > 0) { \
00056 list[size - 1].next = &list[size]; \
00057 } \
00058 list[size].packet = packet; \
00059 list[size].next = NULL; \
00060 size++; \
00061 } while(0)
00062
00063
00064 #define QDM2_SB_USED(sub_sampling) (((sub_sampling) >= 2) ? 30 : 8 << (sub_sampling))
00065
00066 #define FIX_NOISE_IDX(noise_idx) \
00067 if ((noise_idx) >= 3840) \
00068 (noise_idx) -= 3840; \
00069
00070 #define SB_DITHERING_NOISE(sb,noise_idx) (noise_table[(noise_idx)++] * sb_noise_attenuation[(sb)])
00071
00072 #define SAMPLES_NEEDED \
00073 av_log (NULL,AV_LOG_INFO,"This file triggers some untested code. Please contact the developers.\n");
00074
00075 #define SAMPLES_NEEDED_2(why) \
00076 av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
00077
00078 #define QDM2_MAX_FRAME_SIZE 512
00079
00080 typedef int8_t sb_int8_array[2][30][64];
00081
00085 typedef struct {
00086 int type;
00087 unsigned int size;
00088 const uint8_t *data;
00089 } QDM2SubPacket;
00090
00094 typedef struct QDM2SubPNode {
00095 QDM2SubPacket *packet;
00096 struct QDM2SubPNode *next;
00097 } QDM2SubPNode;
00098
00099 typedef struct {
00100 float re;
00101 float im;
00102 } QDM2Complex;
00103
00104 typedef struct {
00105 float level;
00106 QDM2Complex *complex;
00107 const float *table;
00108 int phase;
00109 int phase_shift;
00110 int duration;
00111 short time_index;
00112 short cutoff;
00113 } FFTTone;
00114
00115 typedef struct {
00116 int16_t sub_packet;
00117 uint8_t channel;
00118 int16_t offset;
00119 int16_t exp;
00120 uint8_t phase;
00121 } FFTCoefficient;
00122
00123 typedef struct {
00124 DECLARE_ALIGNED(32, QDM2Complex, complex)[MPA_MAX_CHANNELS][256];
00125 } QDM2FFT;
00126
00130 typedef struct {
00131 AVFrame frame;
00132
00134 int nb_channels;
00135 int channels;
00136 int group_size;
00137 int fft_size;
00138 int checksum_size;
00139
00141 int group_order;
00142 int fft_order;
00143 int frame_size;
00144 int frequency_range;
00145 int sub_sampling;
00146 int coeff_per_sb_select;
00147 int cm_table_select;
00148
00150 QDM2SubPacket sub_packets[16];
00151 QDM2SubPNode sub_packet_list_A[16];
00152 QDM2SubPNode sub_packet_list_B[16];
00153 int sub_packets_B;
00154 QDM2SubPNode sub_packet_list_C[16];
00155 QDM2SubPNode sub_packet_list_D[16];
00156
00158 FFTTone fft_tones[1000];
00159 int fft_tone_start;
00160 int fft_tone_end;
00161 FFTCoefficient fft_coefs[1000];
00162 int fft_coefs_index;
00163 int fft_coefs_min_index[5];
00164 int fft_coefs_max_index[5];
00165 int fft_level_exp[6];
00166 RDFTContext rdft_ctx;
00167 QDM2FFT fft;
00168
00170 const uint8_t *compressed_data;
00171 int compressed_size;
00172 float output_buffer[QDM2_MAX_FRAME_SIZE * MPA_MAX_CHANNELS * 2];
00173
00175 MPADSPContext mpadsp;
00176 DECLARE_ALIGNED(32, float, synth_buf)[MPA_MAX_CHANNELS][512*2];
00177 int synth_buf_offset[MPA_MAX_CHANNELS];
00178 DECLARE_ALIGNED(32, float, sb_samples)[MPA_MAX_CHANNELS][128][SBLIMIT];
00179 DECLARE_ALIGNED(32, float, samples)[MPA_MAX_CHANNELS * MPA_FRAME_SIZE];
00180
00182 float tone_level[MPA_MAX_CHANNELS][30][64];
00183 int8_t coding_method[MPA_MAX_CHANNELS][30][64];
00184 int8_t quantized_coeffs[MPA_MAX_CHANNELS][10][8];
00185 int8_t tone_level_idx_base[MPA_MAX_CHANNELS][30][8];
00186 int8_t tone_level_idx_hi1[MPA_MAX_CHANNELS][3][8][8];
00187 int8_t tone_level_idx_mid[MPA_MAX_CHANNELS][26][8];
00188 int8_t tone_level_idx_hi2[MPA_MAX_CHANNELS][26];
00189 int8_t tone_level_idx[MPA_MAX_CHANNELS][30][64];
00190 int8_t tone_level_idx_temp[MPA_MAX_CHANNELS][30][64];
00191
00192
00193 int has_errors;
00194 int superblocktype_2_3;
00195 int do_synth_filter;
00196
00197 int sub_packet;
00198 int noise_idx;
00199 } QDM2Context;
00200
00201
00202 static VLC vlc_tab_level;
00203 static VLC vlc_tab_diff;
00204 static VLC vlc_tab_run;
00205 static VLC fft_level_exp_alt_vlc;
00206 static VLC fft_level_exp_vlc;
00207 static VLC fft_stereo_exp_vlc;
00208 static VLC fft_stereo_phase_vlc;
00209 static VLC vlc_tab_tone_level_idx_hi1;
00210 static VLC vlc_tab_tone_level_idx_mid;
00211 static VLC vlc_tab_tone_level_idx_hi2;
00212 static VLC vlc_tab_type30;
00213 static VLC vlc_tab_type34;
00214 static VLC vlc_tab_fft_tone_offset[5];
00215
00216 static const uint16_t qdm2_vlc_offs[] = {
00217 0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838,
00218 };
00219
00220 static av_cold void qdm2_init_vlc(void)
00221 {
00222 static int vlcs_initialized = 0;
00223 static VLC_TYPE qdm2_table[3838][2];
00224
00225 if (!vlcs_initialized) {
00226
00227 vlc_tab_level.table = &qdm2_table[qdm2_vlc_offs[0]];
00228 vlc_tab_level.table_allocated = qdm2_vlc_offs[1] - qdm2_vlc_offs[0];
00229 init_vlc (&vlc_tab_level, 8, 24,
00230 vlc_tab_level_huffbits, 1, 1,
00231 vlc_tab_level_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00232
00233 vlc_tab_diff.table = &qdm2_table[qdm2_vlc_offs[1]];
00234 vlc_tab_diff.table_allocated = qdm2_vlc_offs[2] - qdm2_vlc_offs[1];
00235 init_vlc (&vlc_tab_diff, 8, 37,
00236 vlc_tab_diff_huffbits, 1, 1,
00237 vlc_tab_diff_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00238
00239 vlc_tab_run.table = &qdm2_table[qdm2_vlc_offs[2]];
00240 vlc_tab_run.table_allocated = qdm2_vlc_offs[3] - qdm2_vlc_offs[2];
00241 init_vlc (&vlc_tab_run, 5, 6,
00242 vlc_tab_run_huffbits, 1, 1,
00243 vlc_tab_run_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00244
00245 fft_level_exp_alt_vlc.table = &qdm2_table[qdm2_vlc_offs[3]];
00246 fft_level_exp_alt_vlc.table_allocated = qdm2_vlc_offs[4] - qdm2_vlc_offs[3];
00247 init_vlc (&fft_level_exp_alt_vlc, 8, 28,
00248 fft_level_exp_alt_huffbits, 1, 1,
00249 fft_level_exp_alt_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00250
00251
00252 fft_level_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[4]];
00253 fft_level_exp_vlc.table_allocated = qdm2_vlc_offs[5] - qdm2_vlc_offs[4];
00254 init_vlc (&fft_level_exp_vlc, 8, 20,
00255 fft_level_exp_huffbits, 1, 1,
00256 fft_level_exp_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00257
00258 fft_stereo_exp_vlc.table = &qdm2_table[qdm2_vlc_offs[5]];
00259 fft_stereo_exp_vlc.table_allocated = qdm2_vlc_offs[6] - qdm2_vlc_offs[5];
00260 init_vlc (&fft_stereo_exp_vlc, 6, 7,
00261 fft_stereo_exp_huffbits, 1, 1,
00262 fft_stereo_exp_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00263
00264 fft_stereo_phase_vlc.table = &qdm2_table[qdm2_vlc_offs[6]];
00265 fft_stereo_phase_vlc.table_allocated = qdm2_vlc_offs[7] - qdm2_vlc_offs[6];
00266 init_vlc (&fft_stereo_phase_vlc, 6, 9,
00267 fft_stereo_phase_huffbits, 1, 1,
00268 fft_stereo_phase_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00269
00270 vlc_tab_tone_level_idx_hi1.table = &qdm2_table[qdm2_vlc_offs[7]];
00271 vlc_tab_tone_level_idx_hi1.table_allocated = qdm2_vlc_offs[8] - qdm2_vlc_offs[7];
00272 init_vlc (&vlc_tab_tone_level_idx_hi1, 8, 20,
00273 vlc_tab_tone_level_idx_hi1_huffbits, 1, 1,
00274 vlc_tab_tone_level_idx_hi1_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00275
00276 vlc_tab_tone_level_idx_mid.table = &qdm2_table[qdm2_vlc_offs[8]];
00277 vlc_tab_tone_level_idx_mid.table_allocated = qdm2_vlc_offs[9] - qdm2_vlc_offs[8];
00278 init_vlc (&vlc_tab_tone_level_idx_mid, 8, 24,
00279 vlc_tab_tone_level_idx_mid_huffbits, 1, 1,
00280 vlc_tab_tone_level_idx_mid_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00281
00282 vlc_tab_tone_level_idx_hi2.table = &qdm2_table[qdm2_vlc_offs[9]];
00283 vlc_tab_tone_level_idx_hi2.table_allocated = qdm2_vlc_offs[10] - qdm2_vlc_offs[9];
00284 init_vlc (&vlc_tab_tone_level_idx_hi2, 8, 24,
00285 vlc_tab_tone_level_idx_hi2_huffbits, 1, 1,
00286 vlc_tab_tone_level_idx_hi2_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00287
00288 vlc_tab_type30.table = &qdm2_table[qdm2_vlc_offs[10]];
00289 vlc_tab_type30.table_allocated = qdm2_vlc_offs[11] - qdm2_vlc_offs[10];
00290 init_vlc (&vlc_tab_type30, 6, 9,
00291 vlc_tab_type30_huffbits, 1, 1,
00292 vlc_tab_type30_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00293
00294 vlc_tab_type34.table = &qdm2_table[qdm2_vlc_offs[11]];
00295 vlc_tab_type34.table_allocated = qdm2_vlc_offs[12] - qdm2_vlc_offs[11];
00296 init_vlc (&vlc_tab_type34, 5, 10,
00297 vlc_tab_type34_huffbits, 1, 1,
00298 vlc_tab_type34_huffcodes, 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00299
00300 vlc_tab_fft_tone_offset[0].table = &qdm2_table[qdm2_vlc_offs[12]];
00301 vlc_tab_fft_tone_offset[0].table_allocated = qdm2_vlc_offs[13] - qdm2_vlc_offs[12];
00302 init_vlc (&vlc_tab_fft_tone_offset[0], 8, 23,
00303 vlc_tab_fft_tone_offset_0_huffbits, 1, 1,
00304 vlc_tab_fft_tone_offset_0_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00305
00306 vlc_tab_fft_tone_offset[1].table = &qdm2_table[qdm2_vlc_offs[13]];
00307 vlc_tab_fft_tone_offset[1].table_allocated = qdm2_vlc_offs[14] - qdm2_vlc_offs[13];
00308 init_vlc (&vlc_tab_fft_tone_offset[1], 8, 28,
00309 vlc_tab_fft_tone_offset_1_huffbits, 1, 1,
00310 vlc_tab_fft_tone_offset_1_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00311
00312 vlc_tab_fft_tone_offset[2].table = &qdm2_table[qdm2_vlc_offs[14]];
00313 vlc_tab_fft_tone_offset[2].table_allocated = qdm2_vlc_offs[15] - qdm2_vlc_offs[14];
00314 init_vlc (&vlc_tab_fft_tone_offset[2], 8, 32,
00315 vlc_tab_fft_tone_offset_2_huffbits, 1, 1,
00316 vlc_tab_fft_tone_offset_2_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00317
00318 vlc_tab_fft_tone_offset[3].table = &qdm2_table[qdm2_vlc_offs[15]];
00319 vlc_tab_fft_tone_offset[3].table_allocated = qdm2_vlc_offs[16] - qdm2_vlc_offs[15];
00320 init_vlc (&vlc_tab_fft_tone_offset[3], 8, 35,
00321 vlc_tab_fft_tone_offset_3_huffbits, 1, 1,
00322 vlc_tab_fft_tone_offset_3_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00323
00324 vlc_tab_fft_tone_offset[4].table = &qdm2_table[qdm2_vlc_offs[16]];
00325 vlc_tab_fft_tone_offset[4].table_allocated = qdm2_vlc_offs[17] - qdm2_vlc_offs[16];
00326 init_vlc (&vlc_tab_fft_tone_offset[4], 8, 38,
00327 vlc_tab_fft_tone_offset_4_huffbits, 1, 1,
00328 vlc_tab_fft_tone_offset_4_huffcodes, 2, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
00329
00330 vlcs_initialized=1;
00331 }
00332 }
00333
00334 static int qdm2_get_vlc (GetBitContext *gb, VLC *vlc, int flag, int depth)
00335 {
00336 int value;
00337
00338 value = get_vlc2(gb, vlc->table, vlc->bits, depth);
00339
00340
00341 if (value-- == 0)
00342 value = get_bits (gb, get_bits (gb, 3) + 1);
00343
00344
00345 if (flag) {
00346 int tmp;
00347
00348 if (value >= 60) {
00349 av_log(0, AV_LOG_ERROR, "value %d in qdm2_get_vlc too large\n", value);
00350 return 0;
00351 }
00352
00353 tmp= vlc_stage3_values[value];
00354
00355 if ((value & ~3) > 0)
00356 tmp += get_bits (gb, (value >> 2));
00357 value = tmp;
00358 }
00359
00360 return value;
00361 }
00362
00363
00364 static int qdm2_get_se_vlc (VLC *vlc, GetBitContext *gb, int depth)
00365 {
00366 int value = qdm2_get_vlc (gb, vlc, 0, depth);
00367
00368 return (value & 1) ? ((value + 1) >> 1) : -(value >> 1);
00369 }
00370
00371
00381 static uint16_t qdm2_packet_checksum (const uint8_t *data, int length, int value) {
00382 int i;
00383
00384 for (i=0; i < length; i++)
00385 value -= data[i];
00386
00387 return (uint16_t)(value & 0xffff);
00388 }
00389
00390
00397 static void qdm2_decode_sub_packet_header (GetBitContext *gb, QDM2SubPacket *sub_packet)
00398 {
00399 sub_packet->type = get_bits (gb, 8);
00400
00401 if (sub_packet->type == 0) {
00402 sub_packet->size = 0;
00403 sub_packet->data = NULL;
00404 } else {
00405 sub_packet->size = get_bits (gb, 8);
00406
00407 if (sub_packet->type & 0x80) {
00408 sub_packet->size <<= 8;
00409 sub_packet->size |= get_bits (gb, 8);
00410 sub_packet->type &= 0x7f;
00411 }
00412
00413 if (sub_packet->type == 0x7f)
00414 sub_packet->type |= (get_bits (gb, 8) << 8);
00415
00416 sub_packet->data = &gb->buffer[get_bits_count(gb) / 8];
00417 }
00418
00419 av_log(NULL,AV_LOG_DEBUG,"Subpacket: type=%d size=%d start_offs=%x\n",
00420 sub_packet->type, sub_packet->size, get_bits_count(gb) / 8);
00421 }
00422
00423
00431 static QDM2SubPNode* qdm2_search_subpacket_type_in_list (QDM2SubPNode *list, int type)
00432 {
00433 while (list != NULL && list->packet != NULL) {
00434 if (list->packet->type == type)
00435 return list;
00436 list = list->next;
00437 }
00438 return NULL;
00439 }
00440
00441
00448 static void average_quantized_coeffs (QDM2Context *q)
00449 {
00450 int i, j, n, ch, sum;
00451
00452 n = coeff_per_sb_for_avg[q->coeff_per_sb_select][QDM2_SB_USED(q->sub_sampling) - 1] + 1;
00453
00454 for (ch = 0; ch < q->nb_channels; ch++)
00455 for (i = 0; i < n; i++) {
00456 sum = 0;
00457
00458 for (j = 0; j < 8; j++)
00459 sum += q->quantized_coeffs[ch][i][j];
00460
00461 sum /= 8;
00462 if (sum > 0)
00463 sum--;
00464
00465 for (j=0; j < 8; j++)
00466 q->quantized_coeffs[ch][i][j] = sum;
00467 }
00468 }
00469
00470
00478 static void build_sb_samples_from_noise (QDM2Context *q, int sb)
00479 {
00480 int ch, j;
00481
00482 FIX_NOISE_IDX(q->noise_idx);
00483
00484 if (!q->nb_channels)
00485 return;
00486
00487 for (ch = 0; ch < q->nb_channels; ch++)
00488 for (j = 0; j < 64; j++) {
00489 q->sb_samples[ch][j * 2][sb] = SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j];
00490 q->sb_samples[ch][j * 2 + 1][sb] = SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j];
00491 }
00492 }
00493
00494
00503 static void fix_coding_method_array (int sb, int channels, sb_int8_array coding_method)
00504 {
00505 int j,k;
00506 int ch;
00507 int run, case_val;
00508 static const int switchtable[23] = {0,5,1,5,5,5,5,5,2,5,5,5,5,5,5,5,3,5,5,5,5,5,4};
00509
00510 for (ch = 0; ch < channels; ch++) {
00511 for (j = 0; j < 64; ) {
00512 if((coding_method[ch][sb][j] - 8) > 22) {
00513 run = 1;
00514 case_val = 8;
00515 } else {
00516 switch (switchtable[coding_method[ch][sb][j]-8]) {
00517 case 0: run = 10; case_val = 10; break;
00518 case 1: run = 1; case_val = 16; break;
00519 case 2: run = 5; case_val = 24; break;
00520 case 3: run = 3; case_val = 30; break;
00521 case 4: run = 1; case_val = 30; break;
00522 case 5: run = 1; case_val = 8; break;
00523 default: run = 1; case_val = 8; break;
00524 }
00525 }
00526 for (k = 0; k < run; k++)
00527 if (j + k < 128)
00528 if (coding_method[ch][sb + (j + k) / 64][(j + k) % 64] > coding_method[ch][sb][j])
00529 if (k > 0) {
00530 SAMPLES_NEEDED
00531
00532 memset(&coding_method[ch][sb][j + k], case_val, k * sizeof(int8_t));
00533 memset(&coding_method[ch][sb][j + k], case_val, 3 * sizeof(int8_t));
00534 }
00535 j += run;
00536 }
00537 }
00538 }
00539
00540
00548 static void fill_tone_level_array (QDM2Context *q, int flag)
00549 {
00550 int i, sb, ch, sb_used;
00551 int tmp, tab;
00552
00553
00554 if (q->nb_channels <= 0)
00555 return;
00556
00557 for (ch = 0; ch < q->nb_channels; ch++)
00558 for (sb = 0; sb < 30; sb++)
00559 for (i = 0; i < 8; i++) {
00560 if ((tab=coeff_per_sb_for_dequant[q->coeff_per_sb_select][sb]) < (last_coeff[q->coeff_per_sb_select] - 1))
00561 tmp = q->quantized_coeffs[ch][tab + 1][i] * dequant_table[q->coeff_per_sb_select][tab + 1][sb]+
00562 q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];
00563 else
00564 tmp = q->quantized_coeffs[ch][tab][i] * dequant_table[q->coeff_per_sb_select][tab][sb];
00565 if(tmp < 0)
00566 tmp += 0xff;
00567 q->tone_level_idx_base[ch][sb][i] = (tmp / 256) & 0xff;
00568 }
00569
00570 sb_used = QDM2_SB_USED(q->sub_sampling);
00571
00572 if ((q->superblocktype_2_3 != 0) && !flag) {
00573 for (sb = 0; sb < sb_used; sb++)
00574 for (ch = 0; ch < q->nb_channels; ch++)
00575 for (i = 0; i < 64; i++) {
00576 q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
00577 if (q->tone_level_idx[ch][sb][i] < 0)
00578 q->tone_level[ch][sb][i] = 0;
00579 else
00580 q->tone_level[ch][sb][i] = fft_tone_level_table[0][q->tone_level_idx[ch][sb][i] & 0x3f];
00581 }
00582 } else {
00583 tab = q->superblocktype_2_3 ? 0 : 1;
00584 for (sb = 0; sb < sb_used; sb++) {
00585 if ((sb >= 4) && (sb <= 23)) {
00586 for (ch = 0; ch < q->nb_channels; ch++)
00587 for (i = 0; i < 64; i++) {
00588 tmp = q->tone_level_idx_base[ch][sb][i / 8] -
00589 q->tone_level_idx_hi1[ch][sb / 8][i / 8][i % 8] -
00590 q->tone_level_idx_mid[ch][sb - 4][i / 8] -
00591 q->tone_level_idx_hi2[ch][sb - 4];
00592 q->tone_level_idx[ch][sb][i] = tmp & 0xff;
00593 if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
00594 q->tone_level[ch][sb][i] = 0;
00595 else
00596 q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
00597 }
00598 } else {
00599 if (sb > 4) {
00600 for (ch = 0; ch < q->nb_channels; ch++)
00601 for (i = 0; i < 64; i++) {
00602 tmp = q->tone_level_idx_base[ch][sb][i / 8] -
00603 q->tone_level_idx_hi1[ch][2][i / 8][i % 8] -
00604 q->tone_level_idx_hi2[ch][sb - 4];
00605 q->tone_level_idx[ch][sb][i] = tmp & 0xff;
00606 if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
00607 q->tone_level[ch][sb][i] = 0;
00608 else
00609 q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
00610 }
00611 } else {
00612 for (ch = 0; ch < q->nb_channels; ch++)
00613 for (i = 0; i < 64; i++) {
00614 tmp = q->tone_level_idx[ch][sb][i] = q->tone_level_idx_base[ch][sb][i / 8];
00615 if ((tmp < 0) || (!q->superblocktype_2_3 && !tmp))
00616 q->tone_level[ch][sb][i] = 0;
00617 else
00618 q->tone_level[ch][sb][i] = fft_tone_level_table[tab][tmp & 0x3f];
00619 }
00620 }
00621 }
00622 }
00623 }
00624
00625 return;
00626 }
00627
00628
00643 static void fill_coding_method_array (sb_int8_array tone_level_idx, sb_int8_array tone_level_idx_temp,
00644 sb_int8_array coding_method, int nb_channels,
00645 int c, int superblocktype_2_3, int cm_table_select)
00646 {
00647 int ch, sb, j;
00648 int tmp, acc, esp_40, comp;
00649 int add1, add2, add3, add4;
00650 int64_t multres;
00651
00652
00653 if (nb_channels <= 0)
00654 return;
00655
00656 if (!superblocktype_2_3) {
00657
00658 SAMPLES_NEEDED
00659 for (ch = 0; ch < nb_channels; ch++)
00660 for (sb = 0; sb < 30; sb++) {
00661 for (j = 1; j < 63; j++) {
00662 add1 = tone_level_idx[ch][sb][j] - 10;
00663 if (add1 < 0)
00664 add1 = 0;
00665 add2 = add3 = add4 = 0;
00666 if (sb > 1) {
00667 add2 = tone_level_idx[ch][sb - 2][j] + tone_level_idx_offset_table[sb][0] - 6;
00668 if (add2 < 0)
00669 add2 = 0;
00670 }
00671 if (sb > 0) {
00672 add3 = tone_level_idx[ch][sb - 1][j] + tone_level_idx_offset_table[sb][1] - 6;
00673 if (add3 < 0)
00674 add3 = 0;
00675 }
00676 if (sb < 29) {
00677 add4 = tone_level_idx[ch][sb + 1][j] + tone_level_idx_offset_table[sb][3] - 6;
00678 if (add4 < 0)
00679 add4 = 0;
00680 }
00681 tmp = tone_level_idx[ch][sb][j + 1] * 2 - add4 - add3 - add2 - add1;
00682 if (tmp < 0)
00683 tmp = 0;
00684 tone_level_idx_temp[ch][sb][j + 1] = tmp & 0xff;
00685 }
00686 tone_level_idx_temp[ch][sb][0] = tone_level_idx_temp[ch][sb][1];
00687 }
00688 acc = 0;
00689 for (ch = 0; ch < nb_channels; ch++)
00690 for (sb = 0; sb < 30; sb++)
00691 for (j = 0; j < 64; j++)
00692 acc += tone_level_idx_temp[ch][sb][j];
00693
00694 multres = 0x66666667 * (acc * 10);
00695 esp_40 = (multres >> 32) / 8 + ((multres & 0xffffffff) >> 31);
00696 for (ch = 0; ch < nb_channels; ch++)
00697 for (sb = 0; sb < 30; sb++)
00698 for (j = 0; j < 64; j++) {
00699 comp = tone_level_idx_temp[ch][sb][j]* esp_40 * 10;
00700 if (comp < 0)
00701 comp += 0xff;
00702 comp /= 256;
00703 switch(sb) {
00704 case 0:
00705 if (comp < 30)
00706 comp = 30;
00707 comp += 15;
00708 break;
00709 case 1:
00710 if (comp < 24)
00711 comp = 24;
00712 comp += 10;
00713 break;
00714 case 2:
00715 case 3:
00716 case 4:
00717 if (comp < 16)
00718 comp = 16;
00719 }
00720 if (comp <= 5)
00721 tmp = 0;
00722 else if (comp <= 10)
00723 tmp = 10;
00724 else if (comp <= 16)
00725 tmp = 16;
00726 else if (comp <= 24)
00727 tmp = -1;
00728 else
00729 tmp = 0;
00730 coding_method[ch][sb][j] = ((tmp & 0xfffa) + 30 )& 0xff;
00731 }
00732 for (sb = 0; sb < 30; sb++)
00733 fix_coding_method_array(sb, nb_channels, coding_method);
00734 for (ch = 0; ch < nb_channels; ch++)
00735 for (sb = 0; sb < 30; sb++)
00736 for (j = 0; j < 64; j++)
00737 if (sb >= 10) {
00738 if (coding_method[ch][sb][j] < 10)
00739 coding_method[ch][sb][j] = 10;
00740 } else {
00741 if (sb >= 2) {
00742 if (coding_method[ch][sb][j] < 16)
00743 coding_method[ch][sb][j] = 16;
00744 } else {
00745 if (coding_method[ch][sb][j] < 30)
00746 coding_method[ch][sb][j] = 30;
00747 }
00748 }
00749 } else {
00750 for (ch = 0; ch < nb_channels; ch++)
00751 for (sb = 0; sb < 30; sb++)
00752 for (j = 0; j < 64; j++)
00753 coding_method[ch][sb][j] = coding_method_table[cm_table_select][sb];
00754 }
00755
00756 return;
00757 }
00758
00759
00771 static int synthfilt_build_sb_samples (QDM2Context *q, GetBitContext *gb, int length, int sb_min, int sb_max)
00772 {
00773 int sb, j, k, n, ch, run, channels;
00774 int joined_stereo, zero_encoding, chs;
00775 int type34_first;
00776 float type34_div = 0;
00777 float type34_predictor;
00778 float samples[10], sign_bits[16];
00779
00780 if (length == 0) {
00781
00782 for (sb=sb_min; sb < sb_max; sb++)
00783 build_sb_samples_from_noise (q, sb);
00784
00785 return 0;
00786 }
00787
00788 for (sb = sb_min; sb < sb_max; sb++) {
00789 FIX_NOISE_IDX(q->noise_idx);
00790
00791 channels = q->nb_channels;
00792
00793 if (q->nb_channels <= 1 || sb < 12)
00794 joined_stereo = 0;
00795 else if (sb >= 24)
00796 joined_stereo = 1;
00797 else
00798 joined_stereo = (get_bits_left(gb) >= 1) ? get_bits1 (gb) : 0;
00799
00800 if (joined_stereo) {
00801 if (get_bits_left(gb) >= 16)
00802 for (j = 0; j < 16; j++)
00803 sign_bits[j] = get_bits1 (gb);
00804
00805 for (j = 0; j < 64; j++)
00806 if (q->coding_method[1][sb][j] > q->coding_method[0][sb][j])
00807 q->coding_method[0][sb][j] = q->coding_method[1][sb][j];
00808
00809 fix_coding_method_array(sb, q->nb_channels, q->coding_method);
00810 channels = 1;
00811 }
00812
00813 for (ch = 0; ch < channels; ch++) {
00814 zero_encoding = (get_bits_left(gb) >= 1) ? get_bits1(gb) : 0;
00815 type34_predictor = 0.0;
00816 type34_first = 1;
00817
00818 for (j = 0; j < 128; ) {
00819 switch (q->coding_method[ch][sb][j / 2]) {
00820 case 8:
00821 if (get_bits_left(gb) >= 10) {
00822 if (zero_encoding) {
00823 for (k = 0; k < 5; k++) {
00824 if ((j + 2 * k) >= 128)
00825 break;
00826 samples[2 * k] = get_bits1(gb) ? dequant_1bit[joined_stereo][2 * get_bits1(gb)] : 0;
00827 }
00828 } else {
00829 n = get_bits(gb, 8);
00830 for (k = 0; k < 5; k++)
00831 samples[2 * k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
00832 }
00833 for (k = 0; k < 5; k++)
00834 samples[2 * k + 1] = SB_DITHERING_NOISE(sb,q->noise_idx);
00835 } else {
00836 for (k = 0; k < 10; k++)
00837 samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
00838 }
00839 run = 10;
00840 break;
00841
00842 case 10:
00843 if (get_bits_left(gb) >= 1) {
00844 float f = 0.81;
00845
00846 if (get_bits1(gb))
00847 f = -f;
00848 f -= noise_samples[((sb + 1) * (j +5 * ch + 1)) & 127] * 9.0 / 40.0;
00849 samples[0] = f;
00850 } else {
00851 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
00852 }
00853 run = 1;
00854 break;
00855
00856 case 16:
00857 if (get_bits_left(gb) >= 10) {
00858 if (zero_encoding) {
00859 for (k = 0; k < 5; k++) {
00860 if ((j + k) >= 128)
00861 break;
00862 samples[k] = (get_bits1(gb) == 0) ? 0 : dequant_1bit[joined_stereo][2 * get_bits1(gb)];
00863 }
00864 } else {
00865 n = get_bits (gb, 8);
00866 for (k = 0; k < 5; k++)
00867 samples[k] = dequant_1bit[joined_stereo][random_dequant_index[n][k]];
00868 }
00869 } else {
00870 for (k = 0; k < 5; k++)
00871 samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
00872 }
00873 run = 5;
00874 break;
00875
00876 case 24:
00877 if (get_bits_left(gb) >= 7) {
00878 n = get_bits(gb, 7);
00879 for (k = 0; k < 3; k++)
00880 samples[k] = (random_dequant_type24[n][k] - 2.0) * 0.5;
00881 } else {
00882 for (k = 0; k < 3; k++)
00883 samples[k] = SB_DITHERING_NOISE(sb,q->noise_idx);
00884 }
00885 run = 3;
00886 break;
00887
00888 case 30:
00889 if (get_bits_left(gb) >= 4) {
00890 unsigned index = qdm2_get_vlc(gb, &vlc_tab_type30, 0, 1);
00891 if (index >= FF_ARRAY_ELEMS(type30_dequant)) {
00892 av_log(NULL, AV_LOG_ERROR, "index %d out of type30_dequant array\n", index);
00893 return AVERROR_INVALIDDATA;
00894 }
00895 samples[0] = type30_dequant[index];
00896 } else
00897 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
00898
00899 run = 1;
00900 break;
00901
00902 case 34:
00903 if (get_bits_left(gb) >= 7) {
00904 if (type34_first) {
00905 type34_div = (float)(1 << get_bits(gb, 2));
00906 samples[0] = ((float)get_bits(gb, 5) - 16.0) / 15.0;
00907 type34_predictor = samples[0];
00908 type34_first = 0;
00909 } else {
00910 unsigned index = qdm2_get_vlc(gb, &vlc_tab_type34, 0, 1);
00911 if (index >= FF_ARRAY_ELEMS(type34_delta)) {
00912 av_log(NULL, AV_LOG_ERROR, "index %d out of type34_delta array\n", index);
00913 return AVERROR_INVALIDDATA;
00914 }
00915 samples[0] = type34_delta[index] / type34_div + type34_predictor;
00916 type34_predictor = samples[0];
00917 }
00918 } else {
00919 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
00920 }
00921 run = 1;
00922 break;
00923
00924 default:
00925 samples[0] = SB_DITHERING_NOISE(sb,q->noise_idx);
00926 run = 1;
00927 break;
00928 }
00929
00930 if (joined_stereo) {
00931 float tmp[10][MPA_MAX_CHANNELS];
00932
00933 for (k = 0; k < run; k++) {
00934 tmp[k][0] = samples[k];
00935 tmp[k][1] = (sign_bits[(j + k) / 8]) ? -samples[k] : samples[k];
00936 }
00937 for (chs = 0; chs < q->nb_channels; chs++)
00938 for (k = 0; k < run; k++)
00939 if ((j + k) < 128)
00940 q->sb_samples[chs][j + k][sb] = q->tone_level[chs][sb][((j + k)/2)] * tmp[k][chs];
00941 } else {
00942 for (k = 0; k < run; k++)
00943 if ((j + k) < 128)
00944 q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k];
00945 }
00946
00947 j += run;
00948 }
00949 }
00950 }
00951 return 0;
00952 }
00953
00954
00963 static int init_quantized_coeffs_elem0 (int8_t *quantized_coeffs, GetBitContext *gb)
00964 {
00965 int i, k, run, level, diff;
00966
00967 if (get_bits_left(gb) < 16)
00968 return -1;
00969 level = qdm2_get_vlc(gb, &vlc_tab_level, 0, 2);
00970
00971 quantized_coeffs[0] = level;
00972
00973 for (i = 0; i < 7; ) {
00974 if (get_bits_left(gb) < 16)
00975 return -1;
00976 run = qdm2_get_vlc(gb, &vlc_tab_run, 0, 1) + 1;
00977
00978 if (i + run >= 8)
00979 return -1;
00980
00981 if (get_bits_left(gb) < 16)
00982 return -1;
00983 diff = qdm2_get_se_vlc(&vlc_tab_diff, gb, 2);
00984
00985 for (k = 1; k <= run; k++)
00986 quantized_coeffs[i + k] = (level + ((k * diff) / run));
00987
00988 level += diff;
00989 i += run;
00990 }
00991 return 0;
00992 }
00993
00994
01003 static void init_tone_level_dequantization (QDM2Context *q, GetBitContext *gb)
01004 {
01005 int sb, j, k, n, ch;
01006
01007 for (ch = 0; ch < q->nb_channels; ch++) {
01008 init_quantized_coeffs_elem0(q->quantized_coeffs[ch][0], gb);
01009
01010 if (get_bits_left(gb) < 16) {
01011 memset(q->quantized_coeffs[ch][0], 0, 8);
01012 break;
01013 }
01014 }
01015
01016 n = q->sub_sampling + 1;
01017
01018 for (sb = 0; sb < n; sb++)
01019 for (ch = 0; ch < q->nb_channels; ch++)
01020 for (j = 0; j < 8; j++) {
01021 if (get_bits_left(gb) < 1)
01022 break;
01023 if (get_bits1(gb)) {
01024 for (k=0; k < 8; k++) {
01025 if (get_bits_left(gb) < 16)
01026 break;
01027 q->tone_level_idx_hi1[ch][sb][j][k] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi1, 0, 2);
01028 }
01029 } else {
01030 for (k=0; k < 8; k++)
01031 q->tone_level_idx_hi1[ch][sb][j][k] = 0;
01032 }
01033 }
01034
01035 n = QDM2_SB_USED(q->sub_sampling) - 4;
01036
01037 for (sb = 0; sb < n; sb++)
01038 for (ch = 0; ch < q->nb_channels; ch++) {
01039 if (get_bits_left(gb) < 16)
01040 break;
01041 q->tone_level_idx_hi2[ch][sb] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_hi2, 0, 2);
01042 if (sb > 19)
01043 q->tone_level_idx_hi2[ch][sb] -= 16;
01044 else
01045 for (j = 0; j < 8; j++)
01046 q->tone_level_idx_mid[ch][sb][j] = -16;
01047 }
01048
01049 n = QDM2_SB_USED(q->sub_sampling) - 5;
01050
01051 for (sb = 0; sb < n; sb++)
01052 for (ch = 0; ch < q->nb_channels; ch++)
01053 for (j = 0; j < 8; j++) {
01054 if (get_bits_left(gb) < 16)
01055 break;
01056 q->tone_level_idx_mid[ch][sb][j] = qdm2_get_vlc(gb, &vlc_tab_tone_level_idx_mid, 0, 2) - 32;
01057 }
01058 }
01059
01066 static int process_subpacket_9 (QDM2Context *q, QDM2SubPNode *node)
01067 {
01068 GetBitContext gb;
01069 int i, j, k, n, ch, run, level, diff;
01070
01071 init_get_bits(&gb, node->packet->data, node->packet->size*8);
01072
01073 n = coeff_per_sb_for_avg[q->coeff_per_sb_select][QDM2_SB_USED(q->sub_sampling) - 1] + 1;
01074
01075 for (i = 1; i < n; i++)
01076 for (ch=0; ch < q->nb_channels; ch++) {
01077 level = qdm2_get_vlc(&gb, &vlc_tab_level, 0, 2);
01078 q->quantized_coeffs[ch][i][0] = level;
01079
01080 for (j = 0; j < (8 - 1); ) {
01081 run = qdm2_get_vlc(&gb, &vlc_tab_run, 0, 1) + 1;
01082 diff = qdm2_get_se_vlc(&vlc_tab_diff, &gb, 2);
01083
01084 if (j + run >= 8)
01085 return -1;
01086
01087 for (k = 1; k <= run; k++)
01088 q->quantized_coeffs[ch][i][j + k] = (level + ((k*diff) / run));
01089
01090 level += diff;
01091 j += run;
01092 }
01093 }
01094
01095 for (ch = 0; ch < q->nb_channels; ch++)
01096 for (i = 0; i < 8; i++)
01097 q->quantized_coeffs[ch][0][i] = 0;
01098
01099 return 0;
01100 }
01101
01102
01109 static void process_subpacket_10 (QDM2Context *q, QDM2SubPNode *node)
01110 {
01111 GetBitContext gb;
01112
01113 if (node) {
01114 init_get_bits(&gb, node->packet->data, node->packet->size * 8);
01115 init_tone_level_dequantization(q, &gb);
01116 fill_tone_level_array(q, 1);
01117 } else {
01118 fill_tone_level_array(q, 0);
01119 }
01120 }
01121
01122
01129 static void process_subpacket_11 (QDM2Context *q, QDM2SubPNode *node)
01130 {
01131 GetBitContext gb;
01132 int length = 0;
01133
01134 if (node) {
01135 length = node->packet->size * 8;
01136 init_get_bits(&gb, node->packet->data, length);
01137 }
01138
01139 if (length >= 32) {
01140 int c = get_bits (&gb, 13);
01141
01142 if (c > 3)
01143 fill_coding_method_array (q->tone_level_idx, q->tone_level_idx_temp, q->coding_method,
01144 q->nb_channels, 8*c, q->superblocktype_2_3, q->cm_table_select);
01145 }
01146
01147 synthfilt_build_sb_samples(q, &gb, length, 0, 8);
01148 }
01149
01150
01157 static void process_subpacket_12 (QDM2Context *q, QDM2SubPNode *node)
01158 {
01159 GetBitContext gb;
01160 int length = 0;
01161
01162 if (node) {
01163 length = node->packet->size * 8;
01164 init_get_bits(&gb, node->packet->data, length);
01165 }
01166
01167 synthfilt_build_sb_samples(q, &gb, length, 8, QDM2_SB_USED(q->sub_sampling));
01168 }
01169
01170
01171
01172
01173
01174
01175
01176 static void process_synthesis_subpackets (QDM2Context *q, QDM2SubPNode *list)
01177 {
01178 QDM2SubPNode *nodes[4];
01179
01180 nodes[0] = qdm2_search_subpacket_type_in_list(list, 9);
01181 if (nodes[0] != NULL)
01182 process_subpacket_9(q, nodes[0]);
01183
01184 nodes[1] = qdm2_search_subpacket_type_in_list(list, 10);
01185 if (nodes[1] != NULL)
01186 process_subpacket_10(q, nodes[1]);
01187 else
01188 process_subpacket_10(q, NULL);
01189
01190 nodes[2] = qdm2_search_subpacket_type_in_list(list, 11);
01191 if (nodes[0] != NULL && nodes[1] != NULL && nodes[2] != NULL)
01192 process_subpacket_11(q, nodes[2]);
01193 else
01194 process_subpacket_11(q, NULL);
01195
01196 nodes[3] = qdm2_search_subpacket_type_in_list(list, 12);
01197 if (nodes[0] != NULL && nodes[1] != NULL && nodes[3] != NULL)
01198 process_subpacket_12(q, nodes[3]);
01199 else
01200 process_subpacket_12(q, NULL);
01201 }
01202
01203
01204
01205
01206
01207
01208
01209 static void qdm2_decode_super_block (QDM2Context *q)
01210 {
01211 GetBitContext gb;
01212 QDM2SubPacket header, *packet;
01213 int i, packet_bytes, sub_packet_size, sub_packets_D;
01214 unsigned int next_index = 0;
01215
01216 memset(q->tone_level_idx_hi1, 0, sizeof(q->tone_level_idx_hi1));
01217 memset(q->tone_level_idx_mid, 0, sizeof(q->tone_level_idx_mid));
01218 memset(q->tone_level_idx_hi2, 0, sizeof(q->tone_level_idx_hi2));
01219
01220 q->sub_packets_B = 0;
01221 sub_packets_D = 0;
01222
01223 average_quantized_coeffs(q);
01224
01225 init_get_bits(&gb, q->compressed_data, q->compressed_size*8);
01226 qdm2_decode_sub_packet_header(&gb, &header);
01227
01228 if (header.type < 2 || header.type >= 8) {
01229 q->has_errors = 1;
01230 av_log(NULL,AV_LOG_ERROR,"bad superblock type\n");
01231 return;
01232 }
01233
01234 q->superblocktype_2_3 = (header.type == 2 || header.type == 3);
01235 packet_bytes = (q->compressed_size - get_bits_count(&gb) / 8);
01236
01237 init_get_bits(&gb, header.data, header.size*8);
01238
01239 if (header.type == 2 || header.type == 4 || header.type == 5) {
01240 int csum = 257 * get_bits(&gb, 8);
01241 csum += 2 * get_bits(&gb, 8);
01242
01243 csum = qdm2_packet_checksum(q->compressed_data, q->checksum_size, csum);
01244
01245 if (csum != 0) {
01246 q->has_errors = 1;
01247 av_log(NULL,AV_LOG_ERROR,"bad packet checksum\n");
01248 return;
01249 }
01250 }
01251
01252 q->sub_packet_list_B[0].packet = NULL;
01253 q->sub_packet_list_D[0].packet = NULL;
01254
01255 for (i = 0; i < 6; i++)
01256 if (--q->fft_level_exp[i] < 0)
01257 q->fft_level_exp[i] = 0;
01258
01259 for (i = 0; packet_bytes > 0; i++) {
01260 int j;
01261
01262 q->sub_packet_list_A[i].next = NULL;
01263
01264 if (i > 0) {
01265 q->sub_packet_list_A[i - 1].next = &q->sub_packet_list_A[i];
01266
01267
01268 init_get_bits(&gb, header.data, header.size*8);
01269 skip_bits(&gb, next_index*8);
01270
01271 if (next_index >= header.size)
01272 break;
01273 }
01274
01275
01276 packet = &q->sub_packets[i];
01277 qdm2_decode_sub_packet_header(&gb, packet);
01278 next_index = packet->size + get_bits_count(&gb) / 8;
01279 sub_packet_size = ((packet->size > 0xff) ? 1 : 0) + packet->size + 2;
01280
01281 if (packet->type == 0)
01282 break;
01283
01284 if (sub_packet_size > packet_bytes) {
01285 if (packet->type != 10 && packet->type != 11 && packet->type != 12)
01286 break;
01287 packet->size += packet_bytes - sub_packet_size;
01288 }
01289
01290 packet_bytes -= sub_packet_size;
01291
01292
01293 q->sub_packet_list_A[i].packet = packet;
01294
01295
01296 if (packet->type == 8) {
01297 SAMPLES_NEEDED_2("packet type 8");
01298 return;
01299 } else if (packet->type >= 9 && packet->type <= 12) {
01300
01301 QDM2_LIST_ADD(q->sub_packet_list_D, sub_packets_D, packet);
01302 } else if (packet->type == 13) {
01303 for (j = 0; j < 6; j++)
01304 q->fft_level_exp[j] = get_bits(&gb, 6);
01305 } else if (packet->type == 14) {
01306 for (j = 0; j < 6; j++)
01307 q->fft_level_exp[j] = qdm2_get_vlc(&gb, &fft_level_exp_vlc, 0, 2);
01308 } else if (packet->type == 15) {
01309 SAMPLES_NEEDED_2("packet type 15")
01310 return;
01311 } else if (packet->type >= 16 && packet->type < 48 && !fft_subpackets[packet->type - 16]) {
01312
01313 QDM2_LIST_ADD(q->sub_packet_list_B, q->sub_packets_B, packet);
01314 }
01315 }
01316
01317
01318 if (q->sub_packet_list_D[0].packet != NULL) {
01319 process_synthesis_subpackets(q, q->sub_packet_list_D);
01320 q->do_synth_filter = 1;
01321 } else if (q->do_synth_filter) {
01322 process_subpacket_10(q, NULL);
01323 process_subpacket_11(q, NULL);
01324 process_subpacket_12(q, NULL);
01325 }
01326
01327 }
01328
01329
01330 static void qdm2_fft_init_coefficient (QDM2Context *q, int sub_packet,
01331 int offset, int duration, int channel,
01332 int exp, int phase)
01333 {
01334 if (q->fft_coefs_min_index[duration] < 0)
01335 q->fft_coefs_min_index[duration] = q->fft_coefs_index;
01336
01337 q->fft_coefs[q->fft_coefs_index].sub_packet = ((sub_packet >= 16) ? (sub_packet - 16) : sub_packet);
01338 q->fft_coefs[q->fft_coefs_index].channel = channel;
01339 q->fft_coefs[q->fft_coefs_index].offset = offset;
01340 q->fft_coefs[q->fft_coefs_index].exp = exp;
01341 q->fft_coefs[q->fft_coefs_index].phase = phase;
01342 q->fft_coefs_index++;
01343 }
01344
01345
01346 static void qdm2_fft_decode_tones (QDM2Context *q, int duration, GetBitContext *gb, int b)
01347 {
01348 int channel, stereo, phase, exp;
01349 int local_int_4, local_int_8, stereo_phase, local_int_10;
01350 int local_int_14, stereo_exp, local_int_20, local_int_28;
01351 int n, offset;
01352
01353 local_int_4 = 0;
01354 local_int_28 = 0;
01355 local_int_20 = 2;
01356 local_int_8 = (4 - duration);
01357 local_int_10 = 1 << (q->group_order - duration - 1);
01358 offset = 1;
01359
01360 while (get_bits_left(gb)>0) {
01361 if (q->superblocktype_2_3) {
01362 while ((n = qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) {
01363 if (get_bits_left(gb)<0) {
01364 if(local_int_4 < q->group_size)
01365 av_log(0, AV_LOG_ERROR, "overread in qdm2_fft_decode_tones()\n");
01366 return;
01367 }
01368 offset = 1;
01369 if (n == 0) {
01370 local_int_4 += local_int_10;
01371 local_int_28 += (1 << local_int_8);
01372 } else {
01373 local_int_4 += 8*local_int_10;
01374 local_int_28 += (8 << local_int_8);
01375 }
01376 }
01377 offset += (n - 2);
01378 } else {
01379 offset += qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2);
01380 while (offset >= (local_int_10 - 1)) {
01381 offset += (1 - (local_int_10 - 1));
01382 local_int_4 += local_int_10;
01383 local_int_28 += (1 << local_int_8);
01384 }
01385 }
01386
01387 if (local_int_4 >= q->group_size)
01388 return;
01389
01390 local_int_14 = (offset >> local_int_8);
01391 if (local_int_14 >= FF_ARRAY_ELEMS(fft_level_index_table))
01392 return;
01393
01394 if (q->nb_channels > 1) {
01395 channel = get_bits1(gb);
01396 stereo = get_bits1(gb);
01397 } else {
01398 channel = 0;
01399 stereo = 0;
01400 }
01401
01402 exp = qdm2_get_vlc(gb, (b ? &fft_level_exp_vlc : &fft_level_exp_alt_vlc), 0, 2);
01403 exp += q->fft_level_exp[fft_level_index_table[local_int_14]];
01404 exp = (exp < 0) ? 0 : exp;
01405
01406 phase = get_bits(gb, 3);
01407 stereo_exp = 0;
01408 stereo_phase = 0;
01409
01410 if (stereo) {
01411 stereo_exp = (exp - qdm2_get_vlc(gb, &fft_stereo_exp_vlc, 0, 1));
01412 stereo_phase = (phase - qdm2_get_vlc(gb, &fft_stereo_phase_vlc, 0, 1));
01413 if (stereo_phase < 0)
01414 stereo_phase += 8;
01415 }
01416
01417 if (q->frequency_range > (local_int_14 + 1)) {
01418 int sub_packet = (local_int_20 + local_int_28);
01419
01420 qdm2_fft_init_coefficient(q, sub_packet, offset, duration, channel, exp, phase);
01421 if (stereo)
01422 qdm2_fft_init_coefficient(q, sub_packet, offset, duration, (1 - channel), stereo_exp, stereo_phase);
01423 }
01424
01425 offset++;
01426 }
01427 }
01428
01429
01430 static void qdm2_decode_fft_packets (QDM2Context *q)
01431 {
01432 int i, j, min, max, value, type, unknown_flag;
01433 GetBitContext gb;
01434
01435 if (q->sub_packet_list_B[0].packet == NULL)
01436 return;
01437
01438
01439 q->fft_coefs_index = 0;
01440 for (i=0; i < 5; i++)
01441 q->fft_coefs_min_index[i] = -1;
01442
01443
01444 for (i = 0, max = 256; i < q->sub_packets_B; i++) {
01445 QDM2SubPacket *packet= NULL;
01446
01447
01448 for (j = 0, min = 0; j < q->sub_packets_B; j++) {
01449 value = q->sub_packet_list_B[j].packet->type;
01450 if (value > min && value < max) {
01451 min = value;
01452 packet = q->sub_packet_list_B[j].packet;
01453 }
01454 }
01455
01456 max = min;
01457
01458
01459 if (!packet)
01460 return;
01461
01462 if (i == 0 && (packet->type < 16 || packet->type >= 48 || fft_subpackets[packet->type - 16]))
01463 return;
01464
01465
01466 init_get_bits (&gb, packet->data, packet->size*8);
01467
01468 if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])
01469 unknown_flag = 1;
01470 else
01471 unknown_flag = 0;
01472
01473 type = packet->type;
01474
01475 if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {
01476 int duration = q->sub_sampling + 5 - (type & 15);
01477
01478 if (duration >= 0 && duration < 4)
01479 qdm2_fft_decode_tones(q, duration, &gb, unknown_flag);
01480 } else if (type == 31) {
01481 for (j=0; j < 4; j++)
01482 qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
01483 } else if (type == 46) {
01484 for (j=0; j < 6; j++)
01485 q->fft_level_exp[j] = get_bits(&gb, 6);
01486 for (j=0; j < 4; j++)
01487 qdm2_fft_decode_tones(q, j, &gb, unknown_flag);
01488 }
01489 }
01490
01491
01492 for (i = 0, j = -1; i < 5; i++)
01493 if (q->fft_coefs_min_index[i] >= 0) {
01494 if (j >= 0)
01495 q->fft_coefs_max_index[j] = q->fft_coefs_min_index[i];
01496 j = i;
01497 }
01498 if (j >= 0)
01499 q->fft_coefs_max_index[j] = q->fft_coefs_index;
01500 }
01501
01502
01503 static void qdm2_fft_generate_tone (QDM2Context *q, FFTTone *tone)
01504 {
01505 float level, f[6];
01506 int i;
01507 QDM2Complex c;
01508 const double iscale = 2.0*M_PI / 512.0;
01509
01510 tone->phase += tone->phase_shift;
01511
01512
01513 level = fft_tone_envelope_table[tone->duration][tone->time_index] * tone->level;
01514 c.im = level * sin(tone->phase*iscale);
01515 c.re = level * cos(tone->phase*iscale);
01516
01517
01518 if (tone->duration >= 3 || tone->cutoff >= 3) {
01519 tone->complex[0].im += c.im;
01520 tone->complex[0].re += c.re;
01521 tone->complex[1].im -= c.im;
01522 tone->complex[1].re -= c.re;
01523 } else {
01524 f[1] = -tone->table[4];
01525 f[0] = tone->table[3] - tone->table[0];
01526 f[2] = 1.0 - tone->table[2] - tone->table[3];
01527 f[3] = tone->table[1] + tone->table[4] - 1.0;
01528 f[4] = tone->table[0] - tone->table[1];
01529 f[5] = tone->table[2];
01530 for (i = 0; i < 2; i++) {
01531 tone->complex[fft_cutoff_index_table[tone->cutoff][i]].re += c.re * f[i];
01532 tone->complex[fft_cutoff_index_table[tone->cutoff][i]].im += c.im *((tone->cutoff <= i) ? -f[i] : f[i]);
01533 }
01534 for (i = 0; i < 4; i++) {
01535 tone->complex[i].re += c.re * f[i+2];
01536 tone->complex[i].im += c.im * f[i+2];
01537 }
01538 }
01539
01540
01541 if (++tone->time_index < ((1 << (5 - tone->duration)) - 1)) {
01542 memcpy(&q->fft_tones[q->fft_tone_end], tone, sizeof(FFTTone));
01543 q->fft_tone_end = (q->fft_tone_end + 1) % 1000;
01544 }
01545 }
01546
01547
01548 static void qdm2_fft_tone_synthesizer (QDM2Context *q, int sub_packet)
01549 {
01550 int i, j, ch;
01551 const double iscale = 0.25 * M_PI;
01552
01553 for (ch = 0; ch < q->channels; ch++) {
01554 memset(q->fft.complex[ch], 0, q->fft_size * sizeof(QDM2Complex));
01555 }
01556
01557
01558
01559 if (q->fft_coefs_min_index[4] >= 0)
01560 for (i = q->fft_coefs_min_index[4]; i < q->fft_coefs_max_index[4]; i++) {
01561 float level;
01562 QDM2Complex c;
01563
01564 if (q->fft_coefs[i].sub_packet != sub_packet)
01565 break;
01566
01567 ch = (q->channels == 1) ? 0 : q->fft_coefs[i].channel;
01568 level = (q->fft_coefs[i].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[i].exp & 63];
01569
01570 c.re = level * cos(q->fft_coefs[i].phase * iscale);
01571 c.im = level * sin(q->fft_coefs[i].phase * iscale);
01572 q->fft.complex[ch][q->fft_coefs[i].offset + 0].re += c.re;
01573 q->fft.complex[ch][q->fft_coefs[i].offset + 0].im += c.im;
01574 q->fft.complex[ch][q->fft_coefs[i].offset + 1].re -= c.re;
01575 q->fft.complex[ch][q->fft_coefs[i].offset + 1].im -= c.im;
01576 }
01577
01578
01579 for (i = q->fft_tone_end; i != q->fft_tone_start; ) {
01580 qdm2_fft_generate_tone(q, &q->fft_tones[q->fft_tone_start]);
01581 q->fft_tone_start = (q->fft_tone_start + 1) % 1000;
01582 }
01583
01584
01585 for (i = 0; i < 4; i++)
01586 if (q->fft_coefs_min_index[i] >= 0) {
01587 for (j = q->fft_coefs_min_index[i]; j < q->fft_coefs_max_index[i]; j++) {
01588 int offset, four_i;
01589 FFTTone tone;
01590
01591 if (q->fft_coefs[j].sub_packet != sub_packet)
01592 break;
01593
01594 four_i = (4 - i);
01595 offset = q->fft_coefs[j].offset >> four_i;
01596 ch = (q->channels == 1) ? 0 : q->fft_coefs[j].channel;
01597
01598 if (offset < q->frequency_range) {
01599 if (offset < 2)
01600 tone.cutoff = offset;
01601 else
01602 tone.cutoff = (offset >= 60) ? 3 : 2;
01603
01604 tone.level = (q->fft_coefs[j].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[j].exp & 63];
01605 tone.complex = &q->fft.complex[ch][offset];
01606 tone.table = fft_tone_sample_table[i][q->fft_coefs[j].offset - (offset << four_i)];
01607 tone.phase = 64 * q->fft_coefs[j].phase - (offset << 8) - 128;
01608 tone.phase_shift = (2 * q->fft_coefs[j].offset + 1) << (7 - four_i);
01609 tone.duration = i;
01610 tone.time_index = 0;
01611
01612 qdm2_fft_generate_tone(q, &tone);
01613 }
01614 }
01615 q->fft_coefs_min_index[i] = j;
01616 }
01617 }
01618
01619
01620 static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet)
01621 {
01622 const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
01623 float *out = q->output_buffer + channel;
01624 int i;
01625 q->fft.complex[channel][0].re *= 2.0f;
01626 q->fft.complex[channel][0].im = 0.0f;
01627 q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
01628
01629 for (i = 0; i < FFALIGN(q->fft_size, 8); i++) {
01630 out[0] += q->fft.complex[channel][i].re * gain;
01631 out[q->channels] += q->fft.complex[channel][i].im * gain;
01632 out += 2 * q->channels;
01633 }
01634 }
01635
01636
01641 static void qdm2_synthesis_filter (QDM2Context *q, int index)
01642 {
01643 int i, k, ch, sb_used, sub_sampling, dither_state = 0;
01644
01645
01646 sb_used = QDM2_SB_USED(q->sub_sampling);
01647
01648 for (ch = 0; ch < q->channels; ch++)
01649 for (i = 0; i < 8; i++)
01650 for (k=sb_used; k < SBLIMIT; k++)
01651 q->sb_samples[ch][(8 * index) + i][k] = 0;
01652
01653 for (ch = 0; ch < q->nb_channels; ch++) {
01654 float *samples_ptr = q->samples + ch;
01655
01656 for (i = 0; i < 8; i++) {
01657 ff_mpa_synth_filter_float(&q->mpadsp,
01658 q->synth_buf[ch], &(q->synth_buf_offset[ch]),
01659 ff_mpa_synth_window_float, &dither_state,
01660 samples_ptr, q->nb_channels,
01661 q->sb_samples[ch][(8 * index) + i]);
01662 samples_ptr += 32 * q->nb_channels;
01663 }
01664 }
01665
01666
01667 sub_sampling = (4 >> q->sub_sampling);
01668
01669 for (ch = 0; ch < q->channels; ch++)
01670 for (i = 0; i < q->frame_size; i++)
01671 q->output_buffer[q->channels * i + ch] += (1 << 23) * q->samples[q->nb_channels * sub_sampling * i + ch];
01672 }
01673
01674
01680 static av_cold void qdm2_init(QDM2Context *q) {
01681 static int initialized = 0;
01682
01683 if (initialized != 0)
01684 return;
01685 initialized = 1;
01686
01687 qdm2_init_vlc();
01688 ff_mpa_synth_init_float(ff_mpa_synth_window_float);
01689 softclip_table_init();
01690 rnd_table_init();
01691 init_noise_samples();
01692
01693 av_log(NULL, AV_LOG_DEBUG, "init done\n");
01694 }
01695
01696
01700 static av_cold int qdm2_decode_init(AVCodecContext *avctx)
01701 {
01702 QDM2Context *s = avctx->priv_data;
01703 uint8_t *extradata;
01704 int extradata_size;
01705 int tmp_val, tmp, size;
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741 if (!avctx->extradata || (avctx->extradata_size < 48)) {
01742 av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n");
01743 return -1;
01744 }
01745
01746 extradata = avctx->extradata;
01747 extradata_size = avctx->extradata_size;
01748
01749 while (extradata_size > 7) {
01750 if (!memcmp(extradata, "frmaQDM", 7))
01751 break;
01752 extradata++;
01753 extradata_size--;
01754 }
01755
01756 if (extradata_size < 12) {
01757 av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n",
01758 extradata_size);
01759 return -1;
01760 }
01761
01762 if (memcmp(extradata, "frmaQDM", 7)) {
01763 av_log(avctx, AV_LOG_ERROR, "invalid headers, QDM? not found\n");
01764 return -1;
01765 }
01766
01767 if (extradata[7] == 'C') {
01768
01769 av_log(avctx, AV_LOG_ERROR, "stream is QDMC version 1, which is not supported\n");
01770 return -1;
01771 }
01772
01773 extradata += 8;
01774 extradata_size -= 8;
01775
01776 size = AV_RB32(extradata);
01777
01778 if(size > extradata_size){
01779 av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n",
01780 extradata_size, size);
01781 return -1;
01782 }
01783
01784 extradata += 4;
01785 av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size);
01786 if (AV_RB32(extradata) != MKBETAG('Q','D','C','A')) {
01787 av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n");
01788 return -1;
01789 }
01790
01791 extradata += 8;
01792
01793 avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
01794 extradata += 4;
01795 if (s->channels > MPA_MAX_CHANNELS) {
01796 av_log(avctx, AV_LOG_ERROR, "Too many channels\n");
01797 return AVERROR_INVALIDDATA;
01798 }
01799
01800 avctx->sample_rate = AV_RB32(extradata);
01801 extradata += 4;
01802
01803 avctx->bit_rate = AV_RB32(extradata);
01804 extradata += 4;
01805
01806 s->group_size = AV_RB32(extradata);
01807 extradata += 4;
01808
01809 s->fft_size = AV_RB32(extradata);
01810 extradata += 4;
01811
01812 s->checksum_size = AV_RB32(extradata);
01813 if (s->checksum_size >= 1U << 28) {
01814 av_log(avctx, AV_LOG_ERROR, "data block size too large (%u)\n", s->checksum_size);
01815 return AVERROR_INVALIDDATA;
01816 }
01817
01818 s->fft_order = av_log2(s->fft_size) + 1;
01819
01820
01821 s->group_order = av_log2(s->group_size) + 1;
01822 s->frame_size = s->group_size / 16;
01823
01824 if (s->frame_size > QDM2_MAX_FRAME_SIZE)
01825 return AVERROR_INVALIDDATA;
01826
01827 s->sub_sampling = s->fft_order - 7;
01828 s->frequency_range = 255 / (1 << (2 - s->sub_sampling));
01829
01830 switch ((s->sub_sampling * 2 + s->channels - 1)) {
01831 case 0: tmp = 40; break;
01832 case 1: tmp = 48; break;
01833 case 2: tmp = 56; break;
01834 case 3: tmp = 72; break;
01835 case 4: tmp = 80; break;
01836 case 5: tmp = 100;break;
01837 default: tmp=s->sub_sampling; break;
01838 }
01839 tmp_val = 0;
01840 if ((tmp * 1000) < avctx->bit_rate) tmp_val = 1;
01841 if ((tmp * 1440) < avctx->bit_rate) tmp_val = 2;
01842 if ((tmp * 1760) < avctx->bit_rate) tmp_val = 3;
01843 if ((tmp * 2240) < avctx->bit_rate) tmp_val = 4;
01844 s->cm_table_select = tmp_val;
01845
01846 if (s->sub_sampling == 0)
01847 tmp = 7999;
01848 else
01849 tmp = ((-(s->sub_sampling -1)) & 8000) + 20000;
01850
01851
01852
01853
01854
01855 if (tmp < 8000)
01856 s->coeff_per_sb_select = 0;
01857 else if (tmp <= 16000)
01858 s->coeff_per_sb_select = 1;
01859 else
01860 s->coeff_per_sb_select = 2;
01861
01862
01863 if ((s->fft_order < 7) || (s->fft_order > 9)) {
01864 av_log(avctx, AV_LOG_ERROR, "Unknown FFT order (%d), contact the developers!\n", s->fft_order);
01865 return -1;
01866 }
01867
01868 ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R);
01869 ff_mpadsp_init(&s->mpadsp);
01870
01871 qdm2_init(s);
01872
01873 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
01874
01875 avcodec_get_frame_defaults(&s->frame);
01876 avctx->coded_frame = &s->frame;
01877
01878 return 0;
01879 }
01880
01881
01882 static av_cold int qdm2_decode_close(AVCodecContext *avctx)
01883 {
01884 QDM2Context *s = avctx->priv_data;
01885
01886 ff_rdft_end(&s->rdft_ctx);
01887
01888 return 0;
01889 }
01890
01891
01892 static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)
01893 {
01894 int ch, i;
01895 const int frame_size = (q->frame_size * q->channels);
01896
01897 if((unsigned)frame_size > FF_ARRAY_ELEMS(q->output_buffer)/2)
01898 return -1;
01899
01900
01901 q->compressed_data = in;
01902 q->compressed_size = q->checksum_size;
01903
01904
01905 memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));
01906 memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));
01907
01908
01909 if (q->sub_packet == 0) {
01910 q->has_errors = 0;
01911 av_log(NULL,AV_LOG_DEBUG,"Superblock follows\n");
01912 qdm2_decode_super_block(q);
01913 }
01914
01915
01916 if (!q->has_errors) {
01917 if (q->sub_packet == 2)
01918 qdm2_decode_fft_packets(q);
01919
01920 qdm2_fft_tone_synthesizer(q, q->sub_packet);
01921 }
01922
01923
01924 for (ch = 0; ch < q->channels; ch++) {
01925 qdm2_calculate_fft(q, ch, q->sub_packet);
01926
01927 if (!q->has_errors && q->sub_packet_list_C[0].packet != NULL) {
01928 SAMPLES_NEEDED_2("has errors, and C list is not empty")
01929 return -1;
01930 }
01931 }
01932
01933
01934 if (!q->has_errors && q->do_synth_filter)
01935 qdm2_synthesis_filter(q, q->sub_packet);
01936
01937 q->sub_packet = (q->sub_packet + 1) % 16;
01938
01939
01940 for (i = 0; i < frame_size; i++) {
01941 int value = (int)q->output_buffer[i];
01942
01943 if (value > SOFTCLIP_THRESHOLD)
01944 value = (value > HARDCLIP_THRESHOLD) ? 32767 : softclip_table[ value - SOFTCLIP_THRESHOLD];
01945 else if (value < -SOFTCLIP_THRESHOLD)
01946 value = (value < -HARDCLIP_THRESHOLD) ? -32767 : -softclip_table[-value - SOFTCLIP_THRESHOLD];
01947
01948 out[i] = value;
01949 }
01950
01951 return 0;
01952 }
01953
01954
01955 static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
01956 int *got_frame_ptr, AVPacket *avpkt)
01957 {
01958 const uint8_t *buf = avpkt->data;
01959 int buf_size = avpkt->size;
01960 QDM2Context *s = avctx->priv_data;
01961 int16_t *out;
01962 int i, ret;
01963
01964 if(!buf)
01965 return 0;
01966 if(buf_size < s->checksum_size)
01967 return -1;
01968
01969
01970 s->frame.nb_samples = 16 * s->frame_size;
01971 if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
01972 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
01973 return ret;
01974 }
01975 out = (int16_t *)s->frame.data[0];
01976
01977 for (i = 0; i < 16; i++) {
01978 if (qdm2_decode(s, buf, out) < 0)
01979 return -1;
01980 out += s->channels * s->frame_size;
01981 }
01982
01983 *got_frame_ptr = 1;
01984 *(AVFrame *)data = s->frame;
01985
01986 return s->checksum_size;
01987 }
01988
01989 AVCodec ff_qdm2_decoder =
01990 {
01991 .name = "qdm2",
01992 .type = AVMEDIA_TYPE_AUDIO,
01993 .id = AV_CODEC_ID_QDM2,
01994 .priv_data_size = sizeof(QDM2Context),
01995 .init = qdm2_decode_init,
01996 .close = qdm2_decode_close,
01997 .decode = qdm2_decode_frame,
01998 .capabilities = CODEC_CAP_DR1,
01999 .long_name = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
02000 };