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++) {
427 for (i = 0; i < num_possible_block_sizes; i++) {
429 for (b = 0; b < s->
num_sfb[i]; b++) {
433 for (x = 0; x < num_possible_block_sizes; x++) {
456 for (i = 0; i < num_possible_block_sizes; i++) {
464 for (i = 0; i < 33; i++)
483 int frame_len_shift = 0;
500 if (subframe_len < s->min_samples_per_subframe ||
534 int fixed_channel_layout = 0;
535 int min_channel_len = 0;
549 fixed_channel_layout = 1;
557 if (num_samples[c] == min_channel_len) {
558 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
560 contains_subframe[
c] = 1;
564 contains_subframe[
c] = 0;
572 min_channel_len += subframe_len;
576 if (contains_subframe[c]) {
579 "broken frame: num subframes > 31\n");
583 num_samples[
c] += subframe_len;
587 "channel len > samples_per_frame\n");
590 }
else if (num_samples[c] <= min_channel_len) {
591 if (num_samples[c] < min_channel_len) {
592 channels_for_cur_subframe = 0;
593 min_channel_len = num_samples[
c];
595 ++channels_for_cur_subframe;
598 }
while (min_channel_len < s->samples_per_frame);
638 for (x = 0; x < i; x++) {
640 for (y = 0; y < i + 1; y++) {
643 int n = rotation_offset[offset + x];
649 cosv =
sin64[32 - n];
651 sinv =
sin64[64 - n];
652 cosv = -
sin64[n - 32];
656 (v1 * sinv) - (v2 * cosv);
658 (v1 * cosv) + (v2 * sinv);
685 "unsupported channel transform bit\n");
697 if (remaining_channels > 2) {
722 "unsupported channel transform type\n");
748 "coupled channels > 6\n");
788 static const uint32_t fval_tab[16] = {
789 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
790 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
791 0x41000000, 0x41100000, 0x41200000, 0x41300000,
792 0x41400000, 0x41500000, 0x41600000, 0x41700000,
803 av_dlog(s->
avctx,
"decode coefficients for channel %i\n", c);
806 vlc = &coef_vlc[vlctable];
827 for (i = 0; i < 4; i += 2) {
841 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
846 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
847 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
848 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
852 for (i = 0; i < 4; i++) {
858 ci->
coeffs[cur_coeff] = 0;
868 if (cur_coeff < s->subframe_len) {
869 memset(&ci->
coeffs[cur_coeff], 0,
872 level, run, 1, ci->
coeffs,
939 sign = (code & 1) - 1;
940 skip = (code & 0x3f) >> 1;
941 }
else if (idx == 1) {
952 "invalid scale factor coding\n");
988 float** ch_end = ch_data + num_channels;
994 sfb < s->cur_sfb_offsets + s->
num_bands; sfb++) {
1000 const float* data_end = data + num_channels;
1001 float* data_ptr =
data;
1004 for (ch = ch_data; ch < ch_end; ch++)
1005 *data_ptr++ = (*ch)[
y];
1007 for (ch = ch_data; ch < ch_end; ch++) {
1010 while (data_ptr < data_end)
1011 sum += *data_ptr++ * *mat++;
1019 ch_data[0] + sfb[0],
1022 ch_data[1] + sfb[0],
1070 int transmit_coeffs = 0;
1071 int cur_subwoofer_cutoff;
1089 "processing subframe with offset %i len %i\n", offset, subframe_len);
1138 if (!(num_fill_bits =
get_bits(&s->
gb, 2))) {
1140 num_fill_bits = (len ?
get_bits(&s->
gb, len) : 0) + 1;
1143 if (num_fill_bits >= 0) {
1167 transmit_coeffs = 1;
1171 if (transmit_coeffs) {
1180 int num_vec_coeffs =
get_bits(&s->
gb, num_bits) << 2;
1196 if (step == -32 || step == 31) {
1197 const int sign = (step == 31) - 1;
1203 quant_step += ((quant + step) ^ sign) - sign;
1205 if (quant_step < 0) {
1232 av_dlog(s->
avctx,
"BITSTREAM: subframe header length was %i\n",
1246 av_dlog(s->
avctx,
"BITSTREAM: subframe length was %i\n",
1249 if (transmit_coeffs) {
1259 memset(&s->
tmp[cur_subwoofer_cutoff], 0,
sizeof(*s->
tmp) *
1260 (subframe_len - cur_subwoofer_cutoff));
1268 const float quant = pow(10.0, exp / 20.0);
1272 quant, end - start);
1306 int more_frames = 0;
1314 av_dlog(s->
avctx,
"decoding frame with length %x\n", len);
1355 av_dlog(s->
avctx,
"BITSTREAM: frame header length was %i\n",
1360 for (i = 0; i < avctx->
channels; i++) {
1383 for (i = 0; i < avctx->
channels; i++)
1387 for (i = 0; i < avctx->
channels; i++) {
1405 "frame[%i] would have to skip %i bits\n", s->
frame_num,
1472 align =
FFMIN(align, len);
1496 int *got_frame_ptr,
AVPacket* avpkt)
1501 int buf_size = avpkt->
size;
1502 int num_bits_prev_frame;
1503 int packet_sequence_number;
1511 if (buf_size < avctx->block_align)
1520 packet_sequence_number =
get_bits(gb, 4);
1526 num_bits_prev_frame);
1537 if (num_bits_prev_frame > 0) {
1539 if (num_bits_prev_frame >= remaining_packet_bits) {
1540 num_bits_prev_frame = remaining_packet_bits;
1546 save_bits(s, gb, num_bits_prev_frame, 1);
1547 av_dlog(avctx,
"accumulated %x bits of frame data\n",
1554 av_dlog(avctx,
"ignoring %x previously saved bits\n",
1614 for (i = 0; i < avctx->
channels; i++)