104 #define WMAPRO_MAX_CHANNELS 8
105 #define MAX_SUBFRAMES 32
107 #define MAX_FRAMESIZE 32768
109 #define WMAPRO_BLOCK_MIN_BITS 6
110 #define WMAPRO_BLOCK_MAX_BITS 13
111 #define WMAPRO_BLOCK_MIN_SIZE (1 << WMAPRO_BLOCK_MIN_BITS)
112 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)
113 #define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1)
117 #define SCALEVLCBITS 8
118 #define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
119 #define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
120 #define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
121 #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
122 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
241 #define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
242 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %"PRIx32"\n", a, b);
280 unsigned int channel_mask;
282 int log2_max_num_subframes;
283 int num_possible_block_sizes;
301 channel_mask =
AV_RL32(edata_ptr+2);
334 log2_max_num_subframes = ((s->
decode_flags & 0x38) >> 3);
340 num_possible_block_sizes = log2_max_num_subframes + 1;
372 for (i = 0; i < avctx->
channels; i++)
378 if (channel_mask & 8) {
380 for (mask = 1; mask < 16; mask <<= 1) {
381 if (channel_mask & mask)
416 for (i = 0; i < num_possible_block_sizes; i++) {
430 if (offset >= subframe_len)
447 for (i = 0; i < num_possible_block_sizes; i++) {
449 for (b = 0; b < s->
num_sfb[i]; b++) {
453 for (x = 0; x < num_possible_block_sizes; x++) {
478 for (i = 0; i < num_possible_block_sizes; i++) {
486 for (i = 0; i < 33; i++)
505 int frame_len_shift = 0;
525 if (subframe_len < s->min_samples_per_subframe ||
559 int fixed_channel_layout = 0;
560 int min_channel_len = 0;
574 fixed_channel_layout = 1;
582 if (num_samples[c] == min_channel_len) {
583 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
585 contains_subframe[
c] = 1;
589 contains_subframe[
c] = 0;
597 min_channel_len += subframe_len;
601 if (contains_subframe[c]) {
604 "broken frame: num subframes > 31\n");
608 num_samples[
c] += subframe_len;
612 "channel len > samples_per_frame\n");
615 }
else if (num_samples[c] <= min_channel_len) {
616 if (num_samples[c] < min_channel_len) {
617 channels_for_cur_subframe = 0;
618 min_channel_len = num_samples[
c];
620 ++channels_for_cur_subframe;
623 }
while (min_channel_len < s->samples_per_frame);
663 for (x = 0; x < i; x++) {
665 for (y = 0; y < i + 1; y++) {
668 int n = rotation_offset[offset + x];
677 cosv = -
sin64[n - 32];
681 (v1 * sinv) - (v2 * cosv);
683 (v1 * cosv) + (v2 * sinv);
710 "Channel transform bit");
722 if (remaining_channels > 2) {
747 "Unknown channel transform type");
774 "Coupled channels > 6");
814 static const uint32_t fval_tab[16] = {
815 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
816 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
817 0x41000000, 0x41100000, 0x41200000, 0x41300000,
818 0x41400000, 0x41500000, 0x41600000, 0x41700000,
829 av_dlog(s->
avctx,
"decode coefficients for channel %i\n", c);
832 vlc = &coef_vlc[vlctable];
853 for (i = 0; i < 4; i += 2) {
867 vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
872 vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
873 vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
874 vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
878 for (i = 0; i < 4; i++) {
884 ci->
coeffs[cur_coeff] = 0;
894 if (cur_coeff < s->subframe_len) {
895 memset(&ci->
coeffs[cur_coeff], 0,
898 level, run, 1, ci->
coeffs,
965 sign = (code & 1) - 1;
966 skip = (code & 0x3f) >> 1;
967 }
else if (idx == 1) {
978 "invalid scale factor coding\n");
1014 float** ch_end = ch_data + num_channels;
1020 sfb < s->cur_sfb_offsets + s->
num_bands; sfb++) {
1026 const float* data_end = data + num_channels;
1027 float* data_ptr =
data;
1030 for (ch = ch_data; ch < ch_end; ch++)
1031 *data_ptr++ = (*ch)[
y];
1033 for (ch = ch_data; ch < ch_end; ch++) {
1036 while (data_ptr < data_end)
1037 sum += *data_ptr++ * *mat++;
1045 ch_data[0] + sfb[0],
1048 ch_data[1] + sfb[0],
1065 const float* window;
1096 int transmit_coeffs = 0;
1097 int cur_subwoofer_cutoff;
1115 "processing subframe with offset %i len %i\n", offset, subframe_len);
1165 if (!(num_fill_bits =
get_bits(&s->
gb, 2))) {
1167 num_fill_bits = (len ?
get_bits(&s->
gb, len) : 0) + 1;
1170 if (num_fill_bits >= 0) {
1194 transmit_coeffs = 1;
1198 if (transmit_coeffs) {
1207 int num_vec_coeffs =
get_bits(&s->
gb, num_bits) << 2;
1224 if (step == -32 || step == 31) {
1225 const int sign = (step == 31) - 1;
1231 quant_step += ((quant + step) ^ sign) - sign;
1233 if (quant_step < 0) {
1260 av_dlog(s->
avctx,
"BITSTREAM: subframe header length was %i\n",
1274 av_dlog(s->
avctx,
"BITSTREAM: subframe length was %i\n",
1277 if (transmit_coeffs) {
1287 memset(&s->
tmp[cur_subwoofer_cutoff], 0,
sizeof(*s->
tmp) *
1288 (subframe_len - cur_subwoofer_cutoff));
1296 const float quant = pow(10.0, exp / 20.0);
1300 quant, end - start);
1334 int more_frames = 0;
1342 av_dlog(s->
avctx,
"decoding frame with length %x\n", len);
1383 av_dlog(s->
avctx,
"BITSTREAM: frame header length was %i\n",
1388 for (i = 0; i < avctx->
channels; i++) {
1410 for (i = 0; i < avctx->
channels; i++)
1414 for (i = 0; i < avctx->
channels; i++) {
1433 "frame[%"PRIu32
"] would have to skip %i bits\n",
1503 align =
FFMIN(align, len);
1527 int *got_frame_ptr,
AVPacket* avpkt)
1532 int buf_size = avpkt->
size;
1533 int num_bits_prev_frame;
1534 int packet_sequence_number;
1542 if (buf_size < avctx->block_align) {
1554 packet_sequence_number =
get_bits(gb, 4);
1560 num_bits_prev_frame);
1567 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1572 if (num_bits_prev_frame > 0) {
1574 if (num_bits_prev_frame >= remaining_packet_bits) {
1575 num_bits_prev_frame = remaining_packet_bits;
1581 save_bits(s, gb, num_bits_prev_frame, 1);
1582 av_dlog(avctx,
"accumulated %x bits of frame data\n",
1589 av_dlog(avctx,
"ignoring %x previously saved bits\n",
1650 for (i = 0; i < avctx->
channels; i++)