90 #include "libavutil/intfloat.h"
91 #include "libavutil/intreadwrite.h"
102 #define WMAPRO_MAX_CHANNELS 8
103 #define MAX_SUBFRAMES 32
105 #define MAX_FRAMESIZE 32768
107 #define WMAPRO_BLOCK_MIN_BITS 6
108 #define WMAPRO_BLOCK_MAX_BITS 13
109 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)
110 #define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1)
114 #define SCALEVLCBITS 8
115 #define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
116 #define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
117 #define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
118 #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
119 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
238 #define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
239 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
275 unsigned int channel_mask;
277 int log2_max_num_subframes;
278 int num_possible_block_sizes;
289 channel_mask =
AV_RL32(edata_ptr+2);
318 log2_max_num_subframes = ((s->
decode_flags & 0x38) >> 3);
324 num_possible_block_sizes = log2_max_num_subframes + 1;
355 for (i = 0; i < avctx->
channels; i++)
361 if (channel_mask & 8) {
363 for (mask = 1; mask < 16; mask <<= 1) {
364 if (channel_mask & mask)
399 for (i = 0; i < num_possible_block_sizes; i++) {
413 if (offset >= subframe_len)
430 for (i = 0; i < num_possible_block_sizes; i++) {
432 for (b = 0; b < s->
num_sfb[i]; b++) {
436 for (x = 0; x < num_possible_block_sizes; x++) {
459 for (i = 0; i < num_possible_block_sizes; i++) {
467 for (i = 0; i < 33; i++)
486 int frame_len_shift = 0;
503 if (subframe_len < s->min_samples_per_subframe ||
537 int fixed_channel_layout = 0;
538 int min_channel_len = 0;
552 fixed_channel_layout = 1;
560 if (num_samples[c] == min_channel_len) {
561 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
563 contains_subframe[
c] = 1;
567 contains_subframe[
c] = 0;
575 min_channel_len += subframe_len;
579 if (contains_subframe[c]) {
582 "broken frame: num subframes > 31\n");
586 num_samples[
c] += subframe_len;
590 "channel len > samples_per_frame\n");
593 }
else if (num_samples[c] <= min_channel_len) {
594 if (num_samples[c] < min_channel_len) {
595 channels_for_cur_subframe = 0;
596 min_channel_len = num_samples[
c];
598 ++channels_for_cur_subframe;
601 }
while (min_channel_len < s->samples_per_frame);
641 for (x = 0; x < i; x++) {
643 for (y = 0; y < i + 1; y++) {
646 int n = rotation_offset[offset + x];
652 cosv =
sin64[32 - n];
654 sinv =
sin64[64 - n];
655 cosv = -
sin64[n - 32];
659 (v1 * sinv) - (v2 * cosv);
661 (v1 * cosv) + (v2 * sinv);
688 "unsupported channel transform bit\n");
700 if (remaining_channels > 2) {
725 "unsupported channel transform type\n");
751 "coupled channels > 6\n");
791 static const uint32_t fval_tab[16] = {
792 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
793 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
794 0x41000000, 0x41100000, 0x41200000, 0x41300000,
795 0x41400000, 0x41500000, 0x41600000, 0x41700000,
806 av_dlog(s->
avctx,
"decode coefficients for channel %i\n", c);
809 vlc = &coef_vlc[vlctable];
830 for (i = 0; i < 4; i += 2) {
844 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
849 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
850 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
851 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
855 for (i = 0; i < 4; i++) {
861 ci->
coeffs[cur_coeff] = 0;
871 if (cur_coeff < s->subframe_len) {
872 memset(&ci->
coeffs[cur_coeff], 0,
875 level, run, 1, ci->
coeffs,
942 sign = (code & 1) - 1;
943 skip = (code & 0x3f) >> 1;
944 }
else if (idx == 1) {
955 "invalid scale factor coding\n");
991 float** ch_end = ch_data + num_channels;
997 sfb < s->cur_sfb_offsets + s->
num_bands; sfb++) {
1003 const float* data_end = data + num_channels;
1004 float* data_ptr =
data;
1007 for (ch = ch_data; ch < ch_end; ch++)
1008 *data_ptr++ = (*ch)[
y];
1010 for (ch = ch_data; ch < ch_end; ch++) {
1013 while (data_ptr < data_end)
1014 sum += *data_ptr++ * *mat++;
1022 ch_data[0] + sfb[0],
1025 ch_data[1] + sfb[0],
1073 int transmit_coeffs = 0;
1074 int cur_subwoofer_cutoff;
1092 "processing subframe with offset %i len %i\n", offset, subframe_len);
1141 if (!(num_fill_bits =
get_bits(&s->
gb, 2))) {
1143 num_fill_bits = (len ?
get_bits(&s->
gb, len) : 0) + 1;
1146 if (num_fill_bits >= 0) {
1170 transmit_coeffs = 1;
1174 if (transmit_coeffs) {
1183 int num_vec_coeffs =
get_bits(&s->
gb, num_bits) << 2;
1199 if (step == -32 || step == 31) {
1200 const int sign = (step == 31) - 1;
1206 quant_step += ((quant + step) ^ sign) - sign;
1208 if (quant_step < 0) {
1235 av_dlog(s->
avctx,
"BITSTREAM: subframe header length was %i\n",
1249 av_dlog(s->
avctx,
"BITSTREAM: subframe length was %i\n",
1252 if (transmit_coeffs) {
1262 memset(&s->
tmp[cur_subwoofer_cutoff], 0,
sizeof(*s->
tmp) *
1263 (subframe_len - cur_subwoofer_cutoff));
1271 const float quant = pow(10.0, exp / 20.0);
1275 quant, end - start);
1309 int more_frames = 0;
1317 av_dlog(s->
avctx,
"decoding frame with length %x\n", len);
1358 av_dlog(s->
avctx,
"BITSTREAM: frame header length was %i\n",
1363 for (i = 0; i < avctx->
channels; i++) {
1386 for (i = 0; i < avctx->
channels; i++)
1390 for (i = 0; i < avctx->
channels; i++) {
1408 "frame[%i] would have to skip %i bits\n", s->
frame_num,
1475 align =
FFMIN(align, len);
1499 int *got_frame_ptr,
AVPacket* avpkt)
1504 int buf_size = avpkt->
size;
1505 int num_bits_prev_frame;
1506 int packet_sequence_number;
1514 if (buf_size < avctx->block_align)
1523 packet_sequence_number =
get_bits(gb, 4);
1529 num_bits_prev_frame);
1540 if (num_bits_prev_frame > 0) {
1542 if (num_bits_prev_frame >= remaining_packet_bits) {
1543 num_bits_prev_frame = remaining_packet_bits;
1549 save_bits(s, gb, num_bits_prev_frame, 1);
1550 av_dlog(avctx,
"accumulated %x bits of frame data\n",
1557 av_dlog(avctx,
"ignoring %x previously saved bits\n",
1618 for (i = 0; i < avctx->
channels; i++)