51 #define JOINT_STEREO 0x12
54 #define SAMPLES_PER_FRAME 1024
146 for (i = 0; i < 128; i++)
147 FFSWAP(
float, input[i], input[255 - i]);
164 uint32_t *output = (uint32_t *)out;
166 off = (intptr_t)input & 3;
167 buf = (
const uint32_t *)(input - off);
169 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
173 for (i = 0; i < bytes / 4; i++)
174 output[i] = c ^ buf[i];
188 for (i = 0, j = 255; i < 128; i++, j--) {
189 float wi = sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
190 float wj = sin(((j + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
191 float w = 0.5 * (wi * wi + wj * wj);
218 int coding_flag,
int *mantissas,
221 int i, code, huff_symb;
226 if (coding_flag != 0) {
231 for (i = 0; i < num_codes; i++) {
239 for (i = 0; i < num_codes; i++) {
251 for (i = 0; i < num_codes; i++) {
252 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector-1].
table,
253 spectral_coeff_tab[selector-1].
bits, 3);
255 code = huff_symb >> 1;
261 for (i = 0; i < num_codes; i++) {
262 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector - 1].
table,
263 spectral_coeff_tab[selector - 1].
bits, 3);
278 int num_subbands, coding_mode, i, j, first, last, subband_size;
279 int subband_vlc_index[32], sf_index[32];
287 for (i = 0; i <= num_subbands; i++)
288 subband_vlc_index[i] =
get_bits(gb, 3);
291 for (i = 0; i <= num_subbands; i++) {
292 if (subband_vlc_index[i] != 0)
296 for (i = 0; i <= num_subbands; i++) {
300 subband_size = last - first;
302 if (subband_vlc_index[i] != 0) {
307 mantissas, subband_size);
314 for (j = 0; first < last; first++, j++)
315 output[first] = mantissas[j] * scale_factor;
318 memset(output + first, 0, subband_size *
sizeof(*output));
338 int nb_components, coding_mode_selector, coding_mode;
339 int band_flags[4], mantissa[8];
340 int component_count = 0;
345 if (nb_components == 0)
348 coding_mode_selector =
get_bits(gb, 2);
349 if (coding_mode_selector == 2)
352 coding_mode = coding_mode_selector & 1;
354 for (i = 0; i < nb_components; i++) {
355 int coded_values_per_component, quant_step_index;
357 for (b = 0; b <= num_bands; b++)
360 coded_values_per_component =
get_bits(gb, 3);
363 if (quant_step_index <= 1)
366 if (coding_mode_selector == 3)
369 for (b = 0; b < (num_bands + 1) * 4; b++) {
370 int coded_components;
372 if (band_flags[b >> 2] == 0)
377 for (c = 0; c < coded_components; c++) {
379 int sf_index, coded_values, max_coded_values;
383 if (component_count >= 64)
389 coded_values = coded_values_per_component + 1;
390 coded_values =
FFMIN(max_coded_values, coded_values);
396 mantissa, coded_values);
401 for (m = 0; m < coded_values; m++)
402 cmp->
coef[m] = mantissa[m] * scale_factor;
409 return component_count;
426 for (i = 0; i <= num_bands; i++) {
435 if (cf && loc[cf] <= loc[cf - 1])
442 gain[i].num_gain_data = 0;
460 float g1, g2, gain_inc;
461 int i, j, num_data, start_loc, end_loc;
470 for (i = 0; i < 256; i++)
471 output[i] = input[i] * g1 + prev[i];
477 for (i = 0, j = 0; i < num_data; i++) {
479 end_loc = start_loc + 8;
486 for (; j < start_loc; j++)
487 output[j] = (input[j] * g1 + prev[j]) * g2;
490 for (; j < end_loc; j++) {
491 output[j] = (input[j] * g1 + prev[j]) * g2;
497 output[j] = input[j] * g1 + prev[j];
501 memcpy(prev, &input[256], 256 *
sizeof(*prev));
515 int i, j, last_pos = -1;
516 float *input, *output;
518 for (i = 0; i < num_components; i++) {
519 last_pos =
FFMAX(components[i].pos + components[i].num_coefs, last_pos);
520 input = components[i].
coef;
521 output = &spectrum[components[i].
pos];
523 for (j = 0; j < components[i].num_coefs; j++)
524 output[j] += input[j];
530 #define INTERPOLATE(old, new, nsample) \
531 ((old) + (nsample) * 0.125 * ((new) - (old)))
536 int i, nsample, band;
537 float mc1_l, mc1_r, mc2_l, mc2_r;
539 for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
540 int s1 = prev_code[i];
541 int s2 = curr_code[i];
552 for (; nsample < band + 8; nsample++) {
553 float c1 = su1[nsample];
554 float c2 = su2[nsample];
555 c2 = c1 *
INTERPOLATE(mc1_l, mc2_l, nsample - band) +
558 su2[nsample] = c1 * 2.0 -
c2;
565 for (; nsample < band + 256; nsample++) {
566 float c1 = su1[nsample];
567 float c2 = su2[nsample];
568 su1[nsample] = c2 * 2.0;
569 su2[nsample] = (c1 -
c2) * 2.0;
573 for (; nsample < band + 256; nsample++) {
574 float c1 = su1[nsample];
575 float c2 = su2[nsample];
576 su1[nsample] = (c1 +
c2) * 2.0;
577 su2[nsample] = c2 * -2.0;
582 for (; nsample < band + 256; nsample++) {
583 float c1 = su1[nsample];
584 float c2 = su2[nsample];
585 su1[nsample] = c1 +
c2;
586 su2[nsample] = c1 -
c2;
601 ch[0] = (index & 7) / 7.0;
602 ch[1] = sqrt(2 - ch[0] * ch[0]);
604 FFSWAP(
float, ch[0], ch[1]);
614 if (p3[1] != 7 || p3[3] != 7) {
618 for (band = 256; band < 4 * 256; band += 256) {
619 for (nsample = band; nsample < band + 8; nsample++) {
620 su1[nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample - band);
621 su2[nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample - band);
623 for(; nsample < band + 256; nsample++) {
624 su1[nsample] *= w[1][0];
625 su2[nsample] *= w[1][1];
641 int channel_num,
int coding_mode)
643 int band, ret, num_subbands, last_tonal, num_bands;
682 num_bands =
FFMAX((last_tonal + 256) >> 8, num_bands);
686 for (band = 0; band < 4; band++) {
688 if (band <= num_bands)
729 for (i = 0; i < avctx->
block_align / 2; i++, ptr1++, ptr2--)
739 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
754 for (i = 0; i < 4; i++) {
775 for (i = 0; i < avctx->
channels; i++) {
789 for (i = 0; i < avctx->
channels; i++) {
790 float *p1 = out_samples[i];
791 float *p2 = p1 + 256;
792 float *p3 = p2 + 256;
793 float *p4 = p3 + 256;
803 int *got_frame_ptr,
AVPacket *avpkt)
806 int buf_size = avpkt->
size;
811 if (buf_size < avctx->block_align) {
813 "Frame too small (%d bytes). Truncated file?\n", buf_size);
852 for (i = 0; i < 7; i++) {
862 for (i = 0; i < 16; i++)
865 for (i = -15; i < 16; i++)
871 static int static_init_done;
873 int version, delay, samples_per_frame, frame_factor;
882 if (!static_init_done)
884 static_init_done = 1;
890 bytestream_get_le16(&edata_ptr));
894 bytestream_get_le16(&edata_ptr));
895 frame_factor = bytestream_get_le16(&edata_ptr);
897 bytestream_get_le16(&edata_ptr));
916 version = bytestream_get_be32(&edata_ptr);
917 samples_per_frame = bytestream_get_be16(&edata_ptr);
918 delay = bytestream_get_be16(&edata_ptr);
947 if (delay != 0x88E) {
988 for (i = 0; i < 4; i++) {