52 #define JOINT_STEREO 0x12
55 #define SAMPLES_PER_FRAME 1024
138 for (i = 0; i < 128; i++)
139 FFSWAP(
float, input[i], input[255 - i]);
156 uint32_t *output = (uint32_t *)out;
158 off = (intptr_t)input & 3;
159 buf = (
const uint32_t *)(input - off);
161 c =
av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
165 for (i = 0; i < bytes / 4; i++)
166 output[i] = c ^ buf[i];
180 for (i = 0, j = 255; i < 128; i++, j--) {
181 float wi = sin(((i + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
182 float wj = sin(((j + 0.5) / 256.0 - 0.5) *
M_PI) + 1.0;
183 float w = 0.5 * (wi * wi + wj * wj);
211 int coding_flag,
int *mantissas,
214 int i, code, huff_symb;
219 if (coding_flag != 0) {
224 for (i = 0; i < num_codes; i++) {
232 for (i = 0; i < num_codes; i++) {
244 for (i = 0; i < num_codes; i++) {
245 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector-1].
table,
246 spectral_coeff_tab[selector-1].
bits, 3);
248 code = huff_symb >> 1;
254 for (i = 0; i < num_codes; i++) {
255 huff_symb =
get_vlc2(gb, spectral_coeff_tab[selector - 1].
table,
256 spectral_coeff_tab[selector - 1].
bits, 3);
271 int num_subbands, coding_mode, i, j, first, last, subband_size;
272 int subband_vlc_index[32], sf_index[32];
280 for (i = 0; i <= num_subbands; i++)
281 subband_vlc_index[i] =
get_bits(gb, 3);
284 for (i = 0; i <= num_subbands; i++) {
285 if (subband_vlc_index[i] != 0)
289 for (i = 0; i <= num_subbands; i++) {
293 subband_size = last - first;
295 if (subband_vlc_index[i] != 0) {
300 mantissas, subband_size);
307 for (j = 0; first < last; first++, j++)
308 output[first] = mantissas[j] * scale_factor;
311 memset(output + first, 0, subband_size *
sizeof(*output));
331 int nb_components, coding_mode_selector, coding_mode;
332 int band_flags[4], mantissa[8];
333 int component_count = 0;
338 if (nb_components == 0)
341 coding_mode_selector =
get_bits(gb, 2);
342 if (coding_mode_selector == 2)
345 coding_mode = coding_mode_selector & 1;
347 for (i = 0; i < nb_components; i++) {
348 int coded_values_per_component, quant_step_index;
350 for (b = 0; b <= num_bands; b++)
353 coded_values_per_component =
get_bits(gb, 3);
356 if (quant_step_index <= 1)
359 if (coding_mode_selector == 3)
362 for (b = 0; b < (num_bands + 1) * 4; b++) {
363 int coded_components;
365 if (band_flags[b >> 2] == 0)
370 for (c = 0; c < coded_components; c++) {
372 int sf_index, coded_values, max_coded_values;
376 if (component_count >= 64)
382 coded_values = coded_values_per_component + 1;
383 coded_values =
FFMIN(max_coded_values, coded_values);
389 mantissa, coded_values);
394 for (m = 0; m < coded_values; m++)
395 cmp->
coef[m] = mantissa[m] * scale_factor;
402 return component_count;
419 for (b = 0; b <= num_bands; b++) {
427 if (j && loc[j] <= loc[j - 1])
434 gain[b].num_points = 0;
450 int i, j, last_pos = -1;
451 float *input, *output;
453 for (i = 0; i < num_components; i++) {
454 last_pos =
FFMAX(components[i].pos + components[i].num_coefs, last_pos);
455 input = components[i].
coef;
456 output = &spectrum[components[i].
pos];
458 for (j = 0; j < components[i].num_coefs; j++)
459 output[j] += input[j];
465 #define INTERPOLATE(old, new, nsample) \
466 ((old) + (nsample) * 0.125 * ((new) - (old)))
471 int i, nsample,
band;
472 float mc1_l, mc1_r, mc2_l, mc2_r;
474 for (i = 0, band = 0; band < 4 * 256; band += 256, i++) {
475 int s1 = prev_code[i];
476 int s2 = curr_code[i];
487 for (; nsample < band + 8; nsample++) {
488 float c1 = su1[nsample];
489 float c2 = su2[nsample];
490 c2 = c1 *
INTERPOLATE(mc1_l, mc2_l, nsample - band) +
493 su2[nsample] = c1 * 2.0 -
c2;
500 for (; nsample < band + 256; nsample++) {
501 float c1 = su1[nsample];
502 float c2 = su2[nsample];
503 su1[nsample] = c2 * 2.0;
504 su2[nsample] = (c1 -
c2) * 2.0;
508 for (; nsample < band + 256; nsample++) {
509 float c1 = su1[nsample];
510 float c2 = su2[nsample];
511 su1[nsample] = (c1 +
c2) * 2.0;
512 su2[nsample] = c2 * -2.0;
517 for (; nsample < band + 256; nsample++) {
518 float c1 = su1[nsample];
519 float c2 = su2[nsample];
520 su1[nsample] = c1 +
c2;
521 su2[nsample] = c1 -
c2;
536 ch[0] = (index & 7) / 7.0;
537 ch[1] = sqrt(2 - ch[0] * ch[0]);
539 FFSWAP(
float, ch[0], ch[1]);
549 if (p3[1] != 7 || p3[3] != 7) {
553 for (band = 256; band < 4 * 256; band += 256) {
554 for (nsample = band; nsample < band + 8; nsample++) {
555 su1[nsample] *=
INTERPOLATE(w[0][0], w[0][1], nsample - band);
556 su2[nsample] *=
INTERPOLATE(w[1][0], w[1][1], nsample - band);
558 for(; nsample < band + 256; nsample++) {
559 su1[nsample] *= w[1][0];
560 su2[nsample] *= w[1][1];
576 int channel_num,
int coding_mode)
578 int band,
ret, num_subbands, last_tonal, num_bands;
617 num_bands =
FFMAX((last_tonal + 256) >> 8, num_bands);
621 for (band = 0; band < 4; band++) {
623 if (band <= num_bands)
632 256, &output[band * 256]);
663 for (i = 0; i < avctx->
block_align / 2; i++, ptr1++, ptr2--)
673 for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
688 for (i = 0; i < 4; i++) {
709 for (i = 0; i < avctx->
channels; i++) {
723 for (i = 0; i < avctx->
channels; i++) {
724 float *p1 = out_samples[i];
725 float *p2 = p1 + 256;
726 float *p3 = p2 + 256;
727 float *p4 = p3 + 256;
737 int *got_frame_ptr,
AVPacket *avpkt)
741 int buf_size = avpkt->
size;
746 if (buf_size < avctx->block_align) {
748 "Frame too small (%d bytes). Truncated file?\n", buf_size);
784 for (i = 0; i < 7; i++) {
796 static int static_init_done;
798 int version, delay, samples_per_frame, frame_factor;
807 if (!static_init_done)
809 static_init_done = 1;
815 bytestream_get_le16(&edata_ptr));
819 bytestream_get_le16(&edata_ptr));
820 frame_factor = bytestream_get_le16(&edata_ptr);
822 bytestream_get_le16(&edata_ptr));
841 version = bytestream_get_be32(&edata_ptr);
842 samples_per_frame = bytestream_get_be16(&edata_ptr);
843 delay = bytestream_get_be16(&edata_ptr);
867 if (delay != 0x88E) {
912 for (i = 0; i < 4; i++) {