51 #define JOINT_STEREO 0x12
54 #define SAMPLES_PER_FRAME 1024
136 for (i = 0; i < 128; i++)
137 FFSWAP(
float, input[i], input[255 - i]);
154 uint32_t *output = (uint32_t *)out;
156 off = (intptr_t)input & 3;
157 buf = (
const uint32_t *)(input - off);
159 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
163 for (i = 0; i < bytes / 4; i++)
164 output[i] = c ^ buf[i];
178 for (i = 0, j = 255; i < 128; i++, j--) {
179 float wi = sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
180 float wj = sin(((j + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
181 float w = 0.5 * (wi * wi + wj * wj);
209 int coding_flag,
int *mantissas,
212 int i, code, huff_symb;
217 if (coding_flag != 0) {
222 for (i = 0; i < num_codes; i++) {
230 for (i = 0; i < num_codes; i++) {
242 for (i = 0; i < num_codes; i++) {
243 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector-1].
table,
244 spectral_coeff_tab[selector-1].
bits, 3);
246 code = huff_symb >> 1;
252 for (i = 0; i < num_codes; i++) {
253 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector - 1].
table,
254 spectral_coeff_tab[selector - 1].
bits, 3);
269 int num_subbands, coding_mode, i, j, first, last, subband_size;
270 int subband_vlc_index[32], sf_index[32];
278 for (i = 0; i <= num_subbands; i++)
279 subband_vlc_index[i] =
get_bits(gb, 3);
282 for (i = 0; i <= num_subbands; i++) {
283 if (subband_vlc_index[i] != 0)
287 for (i = 0; i <= num_subbands; i++) {
291 subband_size = last - first;
293 if (subband_vlc_index[i] != 0) {
298 mantissas, subband_size);
305 for (j = 0; first < last; first++, j++)
306 output[first] = mantissas[j] * scale_factor;
309 memset(output + first, 0, subband_size *
sizeof(*output));
329 int nb_components, coding_mode_selector, coding_mode;
330 int band_flags[4], mantissa[8];
331 int component_count = 0;
336 if (nb_components == 0)
339 coding_mode_selector =
get_bits(gb, 2);
340 if (coding_mode_selector == 2)
343 coding_mode = coding_mode_selector & 1;
345 for (i = 0; i < nb_components; i++) {
346 int coded_values_per_component, quant_step_index;
348 for (b = 0; b <= num_bands; b++)
351 coded_values_per_component =
get_bits(gb, 3);
354 if (quant_step_index <= 1)
357 if (coding_mode_selector == 3)
360 for (b = 0; b < (num_bands + 1) * 4; b++) {
361 int coded_components;
363 if (band_flags[b >> 2] == 0)
368 for (c = 0; c < coded_components; c++) {
370 int sf_index, coded_values, max_coded_values;
374 if (component_count >= 64)
380 coded_values = coded_values_per_component + 1;
381 coded_values =
FFMIN(max_coded_values, coded_values);
387 mantissa, coded_values);
392 for (m = 0; m < coded_values; m++)
393 cmp->
coef[m] = mantissa[m] * scale_factor;
400 return component_count;
417 for (b = 0; b <= num_bands; b++) {
425 if (j && loc[j] <= loc[j - 1])
432 gain[b].num_points = 0;
448 int i, j, last_pos = -1;
449 float *input, *output;
451 for (i = 0; i < num_components; i++) {
452 last_pos =
FFMAX(components[i].pos + components[i].num_coefs, last_pos);
453 input = components[i].
coef;
454 output = &spectrum[components[i].
pos];
456 for (j = 0; j < components[i].num_coefs; j++)
457 output[j] += input[j];
463 #define INTERPOLATE(old, new, nsample) \
464 ((old) + (nsample) * 0.125 * ((new) - (old)))
469 int i, nsample,
band;
470 float mc1_l, mc1_r, mc2_l, mc2_r;
472 for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
473 int s1 = prev_code[i];
474 int s2 = curr_code[i];
485 for (; nsample < band + 8; nsample++) {
486 float c1 = su1[nsample];
487 float c2 = su2[nsample];
488 c2 = c1 *
INTERPOLATE(mc1_l, mc2_l, nsample - band) +
491 su2[nsample] = c1 * 2.0 -
c2;
498 for (; nsample < band + 256; nsample++) {
499 float c1 = su1[nsample];
500 float c2 = su2[nsample];
501 su1[nsample] = c2 * 2.0;
502 su2[nsample] = (c1 -
c2) * 2.0;
506 for (; nsample < band + 256; nsample++) {
507 float c1 = su1[nsample];
508 float c2 = su2[nsample];
509 su1[nsample] = (c1 +
c2) * 2.0;
510 su2[nsample] = c2 * -2.0;
515 for (; nsample < band + 256; nsample++) {
516 float c1 = su1[nsample];
517 float c2 = su2[nsample];
518 su1[nsample] = c1 +
c2;
519 su2[nsample] = c1 -
c2;
534 ch[0] = (index & 7) / 7.0;
535 ch[1] = sqrt(2 - ch[0] * ch[0]);
537 FFSWAP(
float, ch[0], ch[1]);
547 if (p3[1] != 7 || p3[3] != 7) {
551 for (band = 256; band < 4 * 256; band += 256) {
552 for (nsample = band; nsample < band + 8; nsample++) {
553 su1[nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample - band);
554 su2[nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample - band);
556 for(; nsample < band + 256; nsample++) {
557 su1[nsample] *= w[1][0];
558 su2[nsample] *= w[1][1];
574 int channel_num,
int coding_mode)
576 int band,
ret, num_subbands, last_tonal, num_bands;
615 num_bands =
FFMAX((last_tonal + 256) >> 8, num_bands);
619 for (band = 0; band < 4; band++) {
621 if (band <= num_bands)
630 256, &output[band * 256]);
661 for (i = 0; i < avctx->
block_align / 2; i++, ptr1++, ptr2--)
671 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
686 for (i = 0; i < 4; i++) {
707 for (i = 0; i < avctx->
channels; i++) {
721 for (i = 0; i < avctx->
channels; i++) {
722 float *p1 = out_samples[i];
723 float *p2 = p1 + 256;
724 float *p3 = p2 + 256;
725 float *p4 = p3 + 256;
735 int *got_frame_ptr,
AVPacket *avpkt)
739 int buf_size = avpkt->
size;
744 if (buf_size < avctx->block_align) {
746 "Frame too small (%d bytes). Truncated file?\n", buf_size);
782 for (i = 0; i < 7; i++) {
794 static int static_init_done;
796 int version, delay, samples_per_frame, frame_factor;
805 if (!static_init_done)
807 static_init_done = 1;
813 bytestream_get_le16(&edata_ptr));
817 bytestream_get_le16(&edata_ptr));
818 frame_factor = bytestream_get_le16(&edata_ptr);
820 bytestream_get_le16(&edata_ptr));
839 version = bytestream_get_be32(&edata_ptr);
840 samples_per_frame = bytestream_get_be16(&edata_ptr);
841 delay = bytestream_get_be16(&edata_ptr);
865 if (delay != 0x88E) {
910 for (i = 0; i < 4; i++) {