51 #define JOINT_STEREO 0x12
54 #define SAMPLES_PER_FRAME 1024
145 for (i = 0; i < 128; i++)
146 FFSWAP(
float, input[i], input[255 - i]);
163 uint32_t *output = (uint32_t *)out;
165 off = (intptr_t)input & 3;
166 buf = (
const uint32_t *)(input - off);
167 c =
av_be2ne32((0x537F6103 >> (off * 8)) | (0x537F6103 << (32 - (off * 8))));
169 for (i = 0; i < bytes / 4; i++)
170 output[i] = c ^ buf[i];
184 for (i = 0, j = 255; i < 128; i++, j--) {
185 float wi = sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
186 float wj = sin(((j + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
187 float w = 0.5 * (wi * wi + wj * wj);
214 int coding_flag,
int *mantissas,
217 int i, code, huff_symb;
222 if (coding_flag != 0) {
227 for (i = 0; i < num_codes; i++) {
235 for (i = 0; i < num_codes; i++) {
247 for (i = 0; i < num_codes; i++) {
248 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector-1].
table,
249 spectral_coeff_tab[selector-1].
bits, 3);
251 code = huff_symb >> 1;
257 for (i = 0; i < num_codes; i++) {
258 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector - 1].
table,
259 spectral_coeff_tab[selector - 1].
bits, 3);
274 int num_subbands, coding_mode, i, j, first, last, subband_size;
275 int subband_vlc_index[32], sf_index[32];
283 for (i = 0; i <= num_subbands; i++)
284 subband_vlc_index[i] =
get_bits(gb, 3);
287 for (i = 0; i <= num_subbands; i++) {
288 if (subband_vlc_index[i] != 0)
292 for (i = 0; i <= num_subbands; i++) {
296 subband_size = last - first;
298 if (subband_vlc_index[i] != 0) {
303 mantissas, subband_size);
310 for (j = 0; first < last; first++, j++)
311 output[first] = mantissas[j] * scale_factor;
314 memset(output + first, 0, subband_size *
sizeof(*output));
334 int nb_components, coding_mode_selector, coding_mode;
335 int band_flags[4], mantissa[8];
336 int component_count = 0;
341 if (nb_components == 0)
344 coding_mode_selector =
get_bits(gb, 2);
345 if (coding_mode_selector == 2)
348 coding_mode = coding_mode_selector & 1;
350 for (i = 0; i < nb_components; i++) {
351 int coded_values_per_component, quant_step_index;
353 for (b = 0; b <= num_bands; b++)
356 coded_values_per_component =
get_bits(gb, 3);
359 if (quant_step_index <= 1)
362 if (coding_mode_selector == 3)
365 for (b = 0; b < (num_bands + 1) * 4; b++) {
366 int coded_components;
368 if (band_flags[b >> 2] == 0)
373 for (c = 0; c < coded_components; c++) {
375 int sf_index, coded_values, max_coded_values;
379 if (component_count >= 64)
385 coded_values = coded_values_per_component + 1;
386 coded_values =
FFMIN(max_coded_values, coded_values);
392 mantissa, coded_values);
397 for (m = 0; m < coded_values; m++)
398 cmp->
coef[m] = mantissa[m] * scale_factor;
405 return component_count;
422 for (i = 0; i <= num_bands; i++) {
431 if (cf && loc[cf] <= loc[cf - 1])
438 gain[i].num_gain_data = 0;
456 float g1, g2, gain_inc;
457 int i, j, num_data, start_loc, end_loc;
466 for (i = 0; i < 256; i++)
467 output[i] = input[i] * g1 + prev[i];
473 for (i = 0, j = 0; i < num_data; i++) {
475 end_loc = start_loc + 8;
482 for (; j < start_loc; j++)
483 output[j] = (input[j] * g1 + prev[j]) * g2;
486 for (; j < end_loc; j++) {
487 output[j] = (input[j] * g1 + prev[j]) * g2;
493 output[j] = input[j] * g1 + prev[j];
497 memcpy(prev, &input[256], 256 *
sizeof(*prev));
511 int i, j, last_pos = -1;
512 float *input, *output;
514 for (i = 0; i < num_components; i++) {
515 last_pos =
FFMAX(components[i].pos + components[i].num_coefs, last_pos);
516 input = components[i].
coef;
517 output = &spectrum[components[i].
pos];
519 for (j = 0; j < components[i].num_coefs; j++)
520 output[j] += input[j];
526 #define INTERPOLATE(old, new, nsample) \
527 ((old) + (nsample) * 0.125 * ((new) - (old)))
532 int i, nsample,
band;
533 float mc1_l, mc1_r, mc2_l, mc2_r;
535 for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
536 int s1 = prev_code[i];
537 int s2 = curr_code[i];
548 for (; nsample < band + 8; nsample++) {
549 float c1 = su1[nsample];
550 float c2 = su2[nsample];
551 c2 = c1 *
INTERPOLATE(mc1_l, mc2_l, nsample - band) +
554 su2[nsample] = c1 * 2.0 -
c2;
561 for (; nsample < band + 256; nsample++) {
562 float c1 = su1[nsample];
563 float c2 = su2[nsample];
564 su1[nsample] = c2 * 2.0;
565 su2[nsample] = (c1 -
c2) * 2.0;
569 for (; nsample < band + 256; nsample++) {
570 float c1 = su1[nsample];
571 float c2 = su2[nsample];
572 su1[nsample] = (c1 +
c2) * 2.0;
573 su2[nsample] = c2 * -2.0;
578 for (; nsample < band + 256; nsample++) {
579 float c1 = su1[nsample];
580 float c2 = su2[nsample];
581 su1[nsample] = c1 +
c2;
582 su2[nsample] = c1 -
c2;
597 ch[0] = (index & 7) / 7.0;
598 ch[1] = sqrt(2 - ch[0] * ch[0]);
600 FFSWAP(
float, ch[0], ch[1]);
610 if (p3[1] != 7 || p3[3] != 7) {
614 for (band = 256; band < 4 * 256; band += 256) {
615 for (nsample = band; nsample < band + 8; nsample++) {
616 su1[nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample - band);
617 su2[nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample - band);
619 for(; nsample < band + 256; nsample++) {
620 su1[nsample] *= w[1][0];
621 su2[nsample] *= w[1][1];
637 int channel_num,
int coding_mode)
639 int band, ret, num_subbands, last_tonal, num_bands;
678 num_bands =
FFMAX((last_tonal + 256) >> 8, num_bands);
682 for (band = 0; band < 4; band++) {
684 if (band <= num_bands)
725 for (i = 0; i < avctx->
block_align / 2; i++, ptr1++, ptr2--)
735 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
750 for (i = 0; i < 4; i++) {
771 for (i = 0; i < avctx->
channels; i++) {
785 for (i = 0; i < avctx->
channels; i++) {
786 float *p1 = out_samples[i];
787 float *p2 = p1 + 256;
788 float *p3 = p2 + 256;
789 float *p4 = p3 + 256;
799 int *got_frame_ptr,
AVPacket *avpkt)
803 int buf_size = avpkt->
size;
808 if (buf_size < avctx->block_align) {
810 "Frame too small (%d bytes). Truncated file?\n", buf_size);
848 for (i = 0; i < 7; i++) {
858 for (i = 0; i < 16; i++)
861 for (i = -15; i < 16; i++)
867 static int static_init_done;
869 int version, delay, samples_per_frame, frame_factor;
878 if (!static_init_done)
880 static_init_done = 1;
886 bytestream_get_le16(&edata_ptr));
890 bytestream_get_le16(&edata_ptr));
891 frame_factor = bytestream_get_le16(&edata_ptr);
893 bytestream_get_le16(&edata_ptr));
912 version = bytestream_get_be32(&edata_ptr);
913 samples_per_frame = bytestream_get_be16(&edata_ptr);
914 delay = bytestream_get_be16(&edata_ptr);
943 if (delay != 0x88E) {
984 for (i = 0; i < 4; i++) {