[soc]: r4374 - wmapro/wma3dec.c
Author: faust3 Date: Mon Jun 1 17:04:18 2009 New Revision: 4374 Log: unify curly bracket and condition placement Modified: wmapro/wma3dec.c Modified: wmapro/wma3dec.c ============================================================================== --- wmapro/wma3dec.c Mon Jun 1 16:37:10 2009 (r4373) +++ wmapro/wma3dec.c Mon Jun 1 17:04:18 2009 (r4374) @@ -166,7 +166,7 @@ static av_cold int wma_decode_end(AVCode av_free(s->def_decorrelation_mat); - for(i=0 ; i<BLOCK_NB_SIZES ; i++) + for (i=0 ; i<BLOCK_NB_SIZES ; i++) ff_mdct_end(&s->mdct_ctx[i]); return 0; @@ -214,7 +214,7 @@ static av_cold int wma_decode_init(AVCod s->packet_loss = 1; s->len_prefix = (s->decode_flags & 0x40) >> 6; - if(!s->len_prefix){ + if (!s->len_prefix) { av_log(avctx, AV_LOG_ERROR, "no length prefix, please report\n"); return -1; } @@ -224,7 +224,7 @@ static av_cold int wma_decode_init(AVCod s->decode_flags); /** init previous block len */ - for(i=0;i<avctx->channels;i++) + for (i=0;i<avctx->channels;i++) s->channel[i].prev_block_len = s->samples_per_frame; /** subframe info */ @@ -233,7 +233,7 @@ static av_cold int wma_decode_init(AVCod s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes; s->dynamic_range_compression = (s->decode_flags & 0x80) >> 7; - if(s->max_num_subframes > MAX_SUBFRAMES){ + if (s->max_num_subframes > MAX_SUBFRAMES) { av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n", s->max_num_subframes); return -1; @@ -244,18 +244,18 @@ static av_cold int wma_decode_init(AVCod /** extract lfe channel position */ s->lfe_channel = -1; - if(channel_mask & 8){ + if (channel_mask & 8) { unsigned int mask = 1; - for(i=0;i<32;i++){ - if(channel_mask & mask) + for (i=0;i<32;i++) { + if (channel_mask & mask) ++s->lfe_channel; - if(mask & 8) + if (mask & 8) break; mask <<= 1; } } - if(s->num_channels < 0 || s->num_channels > MAX_CHANNELS){ + if (s->num_channels < 0 || s->num_channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "invalid number of channels %i\n", s->num_channels); return -1; @@ -301,8 +301,8 @@ static av_cold int wma_decode_init(AVCod s->sf_offsets = av_mallocz(MAX_BANDS * s->num_possible_block_sizes * s->num_possible_block_sizes * sizeof(int16_t)); - if(!s->num_sfb || - !s->sfb_offsets || !s->subwoofer_cutoffs || !s->sf_offsets){ + if (!s->num_sfb || + !s->sfb_offsets || !s->subwoofer_cutoffs || !s->sf_offsets) { av_log(avctx, AV_LOG_ERROR, "failed to allocate scale factor offset tables\n"); wma_decode_end(avctx); @@ -313,18 +313,18 @@ static av_cold int wma_decode_init(AVCod for every possible block size */ sfb_offsets = s->sfb_offsets; - for(i=0;i<s->num_possible_block_sizes;i++){ + for (i=0;i<s->num_possible_block_sizes;i++) { int subframe_len = s->samples_per_frame / (1 << i); int x; int band = 1; sfb_offsets[0] = 0; - for(x=0;x < MAX_BANDS-1 && sfb_offsets[band-1] < subframe_len;x++){ + for (x=0;x < MAX_BANDS-1 && sfb_offsets[band-1] < subframe_len;x++) { int offset = (subframe_len * 2 * ff_wma3_critical_freq[x]) / s->avctx->sample_rate + 2; offset -= offset % 4; - if ( offset > sfb_offsets[band - 1] ){ + if ( offset > sfb_offsets[band - 1] ) { sfb_offsets[band] = offset; ++band; } @@ -340,15 +340,15 @@ static av_cold int wma_decode_init(AVCod The matrix sf_offsets is needed to find the correct scale factor. */ - for(i=0;i<s->num_possible_block_sizes;i++){ + for (i=0;i<s->num_possible_block_sizes;i++) { int b; - for(b=0;b< s->num_sfb[i];b++){ + for (b=0;b< s->num_sfb[i];b++) { int x; int offset = ((s->sfb_offsets[MAX_BANDS * i + b] + s->sfb_offsets[MAX_BANDS * i + b + 1] - 1)<<i) >> 1; - for(x=0;x<s->num_possible_block_sizes;x++){ + for (x=0;x<s->num_possible_block_sizes;x++) { int v = 0; - while(s->sfb_offsets[MAX_BANDS * x + v +1] << x < offset) + while (s->sfb_offsets[MAX_BANDS * x + v +1] << x < offset) ++v; s->sf_offsets[ i * s->num_possible_block_sizes * MAX_BANDS + x * MAX_BANDS + b] = v; @@ -357,12 +357,12 @@ static av_cold int wma_decode_init(AVCod } /** init MDCT, FIXME: only init needed sizes */ - for(i = 0; i < BLOCK_NB_SIZES; i++) + for (i = 0; i < BLOCK_NB_SIZES; i++) ff_mdct_init(&s->mdct_ctx[i], BLOCK_MIN_BITS+1+i, 1, 1.0 / (1<<(BLOCK_MIN_BITS+i-1))); /** init MDCT windows: simple sinus window */ - for(i=0 ; i<BLOCK_NB_SIZES ; i++) { + for (i=0 ; i<BLOCK_NB_SIZES ; i++) { const int n = 1 << (BLOCK_MAX_BITS - i); const int win_idx = BLOCK_MAX_BITS - i - 7; ff_sine_window_init(ff_sine_windows[win_idx], n); @@ -371,7 +371,7 @@ static av_cold int wma_decode_init(AVCod /** calculate subwoofer cutoff values */ - for(i=0;i< s->num_possible_block_sizes;i++){ + for (i=0;i< s->num_possible_block_sizes;i++) { int block_size = s->samples_per_frame / (1 << i); int cutoff = ceil(block_size * 440.0 / (double)s->avctx->sample_rate + 0.5); @@ -380,7 +380,7 @@ static av_cold int wma_decode_init(AVCod /** set up decorrelation matrixes */ s->def_decorrelation_mat = av_mallocz(sizeof(float*) * (MAX_CHANNELS + 1)); - if(!s->def_decorrelation_mat){ + if (!s->def_decorrelation_mat) { av_log(avctx, AV_LOG_ERROR, "failed to allocate decorrelation matrix\n"); wma_decode_end(avctx); @@ -396,7 +396,7 @@ static av_cold int wma_decode_init(AVCod s->def_decorrelation_mat[6] = &ff_wma3_default_decorrelation_matrices[55]; /** calculate sine values for the decorrelation matrix */ - for(i=0;i<33;i++) + for (i=0;i<33;i++) sin64[i] = sin(i*M_PI / 64.0); wma_dump_context(s); @@ -436,14 +436,14 @@ static int wma_decode_tilehdr(WMA3Decode */ /** reset tiling information */ - for(c=0;c<s->num_channels;c++){ + for (c=0;c<s->num_channels;c++) { s->channel[c].num_subframes = 0; s->channel[c].channel_len = 0; } /** handle the easy case with one constant-sized subframe per channel */ - if(s->max_num_subframes == 1){ - for(c=0;c<s->num_channels;c++){ + if (s->max_num_subframes == 1) { + for (c=0;c<s->num_channels;c++) { s->channel[c].num_subframes = 1; s->channel[c].subframe_len[0] = s->samples_per_frame; s->channel[c].channel_len = 0; @@ -459,16 +459,16 @@ static int wma_decode_tilehdr(WMA3Decode fixed_channel_layout = get_bits1(&s->gb); /** calculate subframe len bits */ - if(s->lossless) + if (s->lossless) subframe_len_bits = av_log2(s->max_num_subframes - 1) + 1; - else if(s->max_num_subframes == 16){ + else if (s->max_num_subframes == 16) { subframe_len_zero_bit = 1; subframe_len_bits = 3; }else subframe_len_bits = av_log2(av_log2(s->max_num_subframes)) + 1; /** loop until the frame data is split between the subframes */ - while(missing_samples > 0){ + while (missing_samples > 0) { unsigned int channel_mask = 0; int min_channel_len = s->samples_per_frame; int read_channel_mask = 1; @@ -477,16 +477,16 @@ static int wma_decode_tilehdr(WMA3Decode /** minimum number of samples that need to be read */ int min_samples = s->min_samples_per_subframe; - if(fixed_channel_layout){ + if (fixed_channel_layout) { read_channel_mask = 0; channels_for_cur_subframe = s->num_channels; min_samples *= channels_for_cur_subframe; min_channel_len = s->channel[0].channel_len; }else{ /** find channels with the smallest overall length */ - for(c=0;c<s->num_channels;c++){ - if(s->channel[c].channel_len <= min_channel_len){ - if(s->channel[c].channel_len < min_channel_len){ + for (c=0;c<s->num_channels;c++) { + if (s->channel[c].channel_len <= min_channel_len) { + if (s->channel[c].channel_len < min_channel_len) { channels_for_cur_subframe = 0; min_channel_len = s->channel[c].channel_len; } @@ -495,7 +495,7 @@ static int wma_decode_tilehdr(WMA3Decode } min_samples *= channels_for_cur_subframe; - if(channels_for_cur_subframe == 1 || + if (channels_for_cur_subframe == 1 || min_samples == missing_samples) read_channel_mask = 0; } @@ -503,9 +503,9 @@ static int wma_decode_tilehdr(WMA3Decode /** For every channel with the minimum length, 1 bit might be transmitted that informs us if the channel contains a subframe with the next subframe_len. */ - if(read_channel_mask){ + if (read_channel_mask) { channel_mask = get_bits(&s->gb,channels_for_cur_subframe); - if(!channel_mask){ + if (!channel_mask) { av_log(s->avctx, AV_LOG_ERROR, "broken frame: zero frames for subframe_len\n"); return -1; @@ -514,11 +514,11 @@ static int wma_decode_tilehdr(WMA3Decode /** if we have the choice get next subframe length from the bitstream */ - if(min_samples != missing_samples){ + if (min_samples != missing_samples) { int log2_subframe_len = 0; /* 1 bit indicates if the subframe length is zero */ - if(subframe_len_zero_bit){ - if(get_bits1(&s->gb)){ + if (subframe_len_zero_bit) { + if (get_bits1(&s->gb)) { log2_subframe_len = get_bits(&s->gb,subframe_len_bits-1); ++log2_subframe_len; @@ -526,7 +526,7 @@ static int wma_decode_tilehdr(WMA3Decode }else log2_subframe_len = get_bits(&s->gb,subframe_len_bits); - if(s->lossless){ + if (s->lossless) { subframe_len = s->samples_per_frame / s->max_num_subframes; subframe_len *= log2_subframe_len + 1; @@ -535,8 +535,8 @@ static int wma_decode_tilehdr(WMA3Decode s->samples_per_frame / (1 << log2_subframe_len); /** sanity check the length */ - if(subframe_len < s->min_samples_per_subframe - || subframe_len > s->samples_per_frame){ + if (subframe_len < s->min_samples_per_subframe + || subframe_len > s->samples_per_frame) { av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n", subframe_len); return -1; @@ -544,15 +544,15 @@ static int wma_decode_tilehdr(WMA3Decode }else subframe_len = s->min_samples_per_subframe; - for(c=0; c<s->num_channels;c++){ + for (c=0; c<s->num_channels;c++) { WMA3ChannelCtx* chan = &s->channel[c]; /** add subframes to the individual channels */ - if(min_channel_len == chan->channel_len){ + if (min_channel_len == chan->channel_len) { --channels_for_cur_subframe; - if(!read_channel_mask || - channel_mask & (1<<channels_for_cur_subframe)){ - if(chan->num_subframes > 31){ + if (!read_channel_mask || + channel_mask & (1<<channels_for_cur_subframe)) { + if (chan->num_subframes > 31) { av_log(s->avctx, AV_LOG_ERROR, "broken frame: num subframes > 31\n"); return -1; @@ -561,8 +561,8 @@ static int wma_decode_tilehdr(WMA3Decode chan->channel_len += subframe_len; missing_samples -= subframe_len; ++chan->num_subframes; - if(missing_samples < 0 - || chan->channel_len > s->samples_per_frame){ + if (missing_samples < 0 + || chan->channel_len > s->samples_per_frame) { av_log(s->avctx, AV_LOG_ERROR,"broken frame: " "channel len > samples_per_frame\n"); return -1; @@ -573,10 +573,10 @@ static int wma_decode_tilehdr(WMA3Decode } } - for(c=0;c<s->num_channels;c++){ + for (c=0;c<s->num_channels;c++) { int i; int offset = 0; - for(i=0;i<s->channel[c].num_subframes;i++){ + for (i=0;i<s->channel[c].num_subframes;i++) { av_log(s->avctx, AV_LOG_DEBUG,"frame[%i] channel[%i] subframe[%i]" " len %i\n",s->frame_num,c,i,s->channel[c].subframe_len[i]); s->channel[c].subframe_offset[i] = offset; @@ -601,19 +601,19 @@ static void wma_decode_decorrelation_mat memset(chgroup->decorrelation_matrix,0, sizeof(float) *s->num_channels * s->num_channels); - for(i=0;i<chgroup->num_channels * (chgroup->num_channels - 1) >> 1;i++) + for (i=0;i<chgroup->num_channels * (chgroup->num_channels - 1) >> 1;i++) rotation_offset[i] = get_bits(&s->gb,6); - for(i=0;i<chgroup->num_channels;i++){ - if(get_bits1(&s->gb)) + for (i=0;i<chgroup->num_channels;i++) { + if (get_bits1(&s->gb)) chgroup->decorrelation_matrix[chgroup->num_channels * i + i]= 1.0; else chgroup->decorrelation_matrix[chgroup->num_channels * i + i]= -1.0; } - for(i=1;i<chgroup->num_channels;i++){ + for (i=1;i<chgroup->num_channels;i++) { int x; - for(x=0;x<i;x++){ + for (x=0;x<i;x++) { int y; float tmp1[MAX_CHANNELS]; float tmp2[MAX_CHANNELS]; @@ -623,14 +623,14 @@ static void wma_decode_decorrelation_mat memcpy(tmp2, &chgroup->decorrelation_matrix[i * chgroup->num_channels], sizeof(float) * (i + 1)); - for(y=0;y < i + 1 ; y++){ + for (y=0;y < i + 1 ; y++) { float v1 = tmp1[y]; float v2 = tmp2[y]; int n = rotation_offset[offset + x]; float sinv; float cosv; - if(n<32){ + if (n<32) { sinv = sin64[n]; cosv = sin64[32-n]; }else{ @@ -663,28 +663,28 @@ static int wma_decode_channel_transform( /** in the one channel case channel transforms are pointless */ s->num_chgroups = 0; - if(s->num_channels > 1){ + if (s->num_channels > 1) { int remaining_channels = s->channels_for_cur_subframe; - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { av_log(s->avctx,AV_LOG_ERROR, "unsupported channel transform bit\n"); return 0; } - for(s->num_chgroups = 0; remaining_channels && - s->num_chgroups < s->channels_for_cur_subframe;s->num_chgroups++){ + for (s->num_chgroups = 0; remaining_channels && + s->num_chgroups < s->channels_for_cur_subframe;s->num_chgroups++) { WMA3ChannelGroup* chgroup = &s->chgroup[s->num_chgroups]; float** channel_data = chgroup->channel_data; chgroup->num_channels = 0; chgroup->transform = 0; /** decode channel mask */ - if(remaining_channels > 2){ - for(i=0;i<s->channels_for_cur_subframe;i++){ + if (remaining_channels > 2) { + for (i=0;i<s->channels_for_cur_subframe;i++) { int channel_idx = s->channel_indexes_for_cur_subframe[i]; - if(!s->channel[channel_idx].grouped - && get_bits1(&s->gb)){ + if (!s->channel[channel_idx].grouped + && get_bits1(&s->gb)) { ++chgroup->num_channels; s->channel[channel_idx].grouped = 1; *channel_data++ = s->channel[channel_idx].coeffs; @@ -692,23 +692,23 @@ static int wma_decode_channel_transform( } }else{ chgroup->num_channels = remaining_channels; - for(i=0;i<s->channels_for_cur_subframe ;i++){ + for (i=0;i<s->channels_for_cur_subframe ;i++) { int channel_idx = s->channel_indexes_for_cur_subframe[i]; - if(!s->channel[channel_idx].grouped) + if (!s->channel[channel_idx].grouped) *channel_data++ = s->channel[channel_idx].coeffs; s->channel[channel_idx].grouped = 1; } } /** decode transform type */ - if(chgroup->num_channels == 2){ - if(get_bits1(&s->gb)){ - if(get_bits1(&s->gb)){ + if (chgroup->num_channels == 2) { + if (get_bits1(&s->gb)) { + if (get_bits1(&s->gb)) { av_log(s->avctx, AV_LOG_ERROR, "unsupported channel transform type\n"); } }else{ - if(s->num_channels == 2){ + if (s->num_channels == 2) { chgroup->transform = 1; }else{ chgroup->transform = 2; @@ -719,14 +719,14 @@ static int wma_decode_channel_transform( chgroup->decorrelation_matrix[3] = 0.70703125; } } - }else if(chgroup->num_channels > 2){ - if(get_bits1(&s->gb)){ + }else if (chgroup->num_channels > 2) { + if (get_bits1(&s->gb)) { chgroup->transform = 2; - if(get_bits1(&s->gb)) + if (get_bits1(&s->gb)) wma_decode_decorrelation_matrix(s, chgroup); else{ /** FIXME: more than 6 coupled channels not supported */ - if(chgroup->num_channels > 6){ + if (chgroup->num_channels > 6) { av_log(s->avctx,AV_LOG_ERROR, "coupled channels > 6\n"); }else{ @@ -740,11 +740,11 @@ static int wma_decode_channel_transform( } /** decode transform on / off */ - if(chgroup->transform){ - if(!get_bits1(&s->gb)){ + if (chgroup->transform) { + if (!get_bits1(&s->gb)) { int i; /** transform can be enabled for individual bands */ - for(i=0;i< s->num_bands;i++){ + for (i=0;i< s->num_bands;i++) { chgroup->transform_band[i] = get_bits1(&s->gb); } }else{ @@ -767,11 +767,11 @@ static unsigned int wma_get_large_val(WM /** consumes up to 34 bits */ int n_bits = 8; /** decode length */ - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { n_bits += 8; - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { n_bits += 8; - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { n_bits += 7; } } @@ -805,7 +805,7 @@ static int wma_decode_coeffs(WMA3DecodeC vlc = &coef_vlc[vlctable]; vlcmax = s->coef_max[vlctable]; - if(vlctable){ + if (vlctable) { run = ff_wma3_coef1_run; level = ff_wma3_coef1_level; }else{ @@ -815,14 +815,14 @@ static int wma_decode_coeffs(WMA3DecodeC /** for subframe_len 128 the first zero coefficient will switch to the run level mode */ - if(s->subframe_len == 128){ + if (s->subframe_len == 128) { zero_init = num_zeros = 1; rl_switchmask = 1; } /** decode vector coefficients (consumes up to 167 bits per iteration for 4 vector coded large values) */ - while(!rl_mode && cur_coeff + 3 < s->subframe_len){ + while (!rl_mode && cur_coeff + 3 < s->subframe_len) { int vals[4]; int i; unsigned int idx; @@ -830,19 +830,19 @@ static int wma_decode_coeffs(WMA3DecodeC idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, ((FF_WMA3_HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)); - if ( idx == FF_WMA3_HUFF_VEC4_SIZE - 1 ){ + if ( idx == FF_WMA3_HUFF_VEC4_SIZE - 1 ) { i = 0; - while(i < 4){ + while (i < 4) { idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, ((FF_WMA3_HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)); - if ( idx == FF_WMA3_HUFF_VEC2_SIZE - 1 ){ + if ( idx == FF_WMA3_HUFF_VEC2_SIZE - 1 ) { vals[i] = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, ((FF_WMA3_HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)); - if(vals[i] == FF_WMA3_HUFF_VEC1_SIZE - 1) + if (vals[i] == FF_WMA3_HUFF_VEC1_SIZE - 1) vals[i] += wma_get_large_val(s); vals[i+1] = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, ((FF_WMA3_HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)); - if(vals[i+1] == FF_WMA3_HUFF_VEC1_SIZE - 1) + if (vals[i+1] == FF_WMA3_HUFF_VEC1_SIZE - 1) vals[i+1] += wma_get_large_val(s); }else{ vals[i] = (ff_wma3_symbol_to_vec2[idx] >> 4) & 0xF; @@ -858,8 +858,8 @@ static int wma_decode_coeffs(WMA3DecodeC } /** decode sign */ - for(i=0;i<4;i++){ - if(vals[i]){ + for (i=0;i<4;i++) { + if (vals[i]) { int sign = get_bits1(&s->gb) - 1; ci->coeffs[cur_coeff] = (vals[i]^sign) - sign; num_zeros = zero_init; @@ -874,25 +874,25 @@ static int wma_decode_coeffs(WMA3DecodeC } /** decode run level coded coefficients */ - if(rl_mode){ + if (rl_mode) { const unsigned int coeff_mask = s->subframe_len - 1; - while(cur_coeff < s->subframe_len){ + while (cur_coeff < s->subframe_len) { unsigned int idx; int sign; int val; idx = get_vlc2(&s->gb, vlc->table, VLCBITS, vlcmax); - if( idx > 1){ + if ( idx > 1) { cur_coeff += run[idx]; val = level[idx]; - }else if( idx == 1) + }else if ( idx == 1) break; else{ val = wma_get_large_val(s); /** escape decode */ - if(get_bits1(&s->gb)){ - if(get_bits1(&s->gb)){ - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { + if (get_bits1(&s->gb)) { + if (get_bits1(&s->gb)) { av_log(s->avctx,AV_LOG_ERROR, "broken escape sequence\n"); return 0; @@ -925,13 +925,13 @@ static int wma_decode_scale_factors(WMA3 * MAX_CHANNELS * (1 + MAX_BANDS * 23) */ - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; int* sf; int* sf_end = s->channel[c].scale_factors + s->num_bands; /** resample scale factors for the new block size */ - if(s->channel[c].reuse_sf){ + if (s->channel[c].reuse_sf) { const int blocks_per_frame = s->samples_per_frame/s->subframe_len; const int res_blocks_per_frame = s->samples_per_frame / s->channel[c].scale_factor_block_len; @@ -941,28 +941,28 @@ static int wma_decode_scale_factors(WMA3 &s->sf_offsets[s->num_possible_block_sizes * MAX_BANDS * idx0 + MAX_BANDS * idx1]; int b; - for(b=0;b<s->num_bands;b++) + for (b=0;b<s->num_bands;b++) s->channel[c].resampled_scale_factors[b] = s->channel[c].scale_factors[*sf_offsets++]; s->channel[c].max_scale_factor = s->channel[c].resampled_scale_factors[0]; sf = s->channel[c].resampled_scale_factors + 1; - while(sf < s->channel[c].resampled_scale_factors + s->num_bands){ - if(*sf > s->channel[c].max_scale_factor) + while (sf < s->channel[c].resampled_scale_factors + s->num_bands) { + if (*sf > s->channel[c].max_scale_factor) s->channel[c].max_scale_factor = *sf; ++sf; } } - if(s->channel[c].cur_subframe > 0){ + if (s->channel[c].cur_subframe > 0) { s->channel[c].transmit_sf = get_bits1(&s->gb); }else s->channel[c].transmit_sf = 1; - if(s->channel[c].transmit_sf){ + if (s->channel[c].transmit_sf) { - if(!s->channel[c].reuse_sf){ + if (!s->channel[c].reuse_sf) { int val; /** decode DPCM coded scale factors */ s->channel[c].scale_factor_step = get_bits(&s->gb,2) + 1; @@ -970,7 +970,7 @@ static int wma_decode_scale_factors(WMA3 ((FF_WMA3_HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)); s->channel[c].scale_factors[0] = 45 / s->channel[c].scale_factor_step + val - 60; - for(sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) { + for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) { val = get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, ((FF_WMA3_HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)); *sf = *(sf - 1) + val - 60; @@ -983,7 +983,7 @@ static int wma_decode_scale_factors(WMA3 s->channel[c].resampled_scale_factors, sizeof(int) * s->num_bands); - for(i=0;i<s->num_bands;i++){ + for (i=0;i<s->num_bands;i++) { int idx; short skip; short val; @@ -992,12 +992,12 @@ static int wma_decode_scale_factors(WMA3 idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, ((FF_WMA3_HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)); - if( !idx ){ + if ( !idx ) { uint32_t code = get_bits(&s->gb,14); val = code >> 6; sign = (code & 1) - 1; skip = (code & 0x3f)>>1; - }else if(idx == 1){ + }else if (idx == 1) { break; }else{ skip = ff_wma3_scale_rl_run[idx]; @@ -1006,7 +1006,7 @@ static int wma_decode_scale_factors(WMA3 } i += skip; - if(i >= s->num_bands){ + if (i >= s->num_bands) { av_log(s->avctx,AV_LOG_ERROR, "invalid scale factor coding\n"); return 0; @@ -1017,8 +1017,8 @@ static int wma_decode_scale_factors(WMA3 s->channel[c].reuse_sf = 1; s->channel[c].max_scale_factor = s->channel[c].scale_factors[0]; - for(sf=s->channel[c].scale_factors + 1; sf < sf_end; sf++){ - if(s->channel[c].max_scale_factor < *sf) + for (sf=s->channel[c].scale_factors + 1; sf < sf_end; sf++) { + if (s->channel[c].max_scale_factor < *sf) s->channel[c].max_scale_factor = *sf; } s->channel[c].scale_factor_block_len = s->subframe_len; @@ -1035,9 +1035,9 @@ static void wma_inverse_channel_transfor { int i; - for(i=0;i<s->num_chgroups;i++){ + for (i=0;i<s->num_chgroups;i++) { - if(s->chgroup[i].transform == 1){ + if (s->chgroup[i].transform == 1) { /** M/S stereo decoding */ int16_t* sfb_offsets = s->cur_sfb_offsets; float* ch0 = *sfb_offsets + s->channel[0].coeffs; @@ -1045,25 +1045,25 @@ static void wma_inverse_channel_transfor const char* tb = s->chgroup[i].transform_band; const char* tb_end = tb + s->num_bands; - while(tb < tb_end){ + while (tb < tb_end) { const float* ch0_end = s->channel[0].coeffs + FFMIN(*sfb_offsets,s->subframe_len); - if(*tb++ == 1){ - while(ch0 < ch0_end){ + if (*tb++ == 1) { + while (ch0 < ch0_end) { const float v1 = *ch0; const float v2 = *ch1; *ch0++ = v1 - v2; *ch1++ = v1 + v2; } }else{ - while(ch0 < ch0_end){ + while (ch0 < ch0_end) { *ch0++ *= 181.0 / 128; *ch1++ *= 181.0 / 128; } } ++sfb_offsets; } - }else if(s->chgroup[i].transform){ + }else if (s->chgroup[i].transform) { float data[MAX_CHANNELS]; const int num_channels = s->chgroup[i].num_channels; float** ch_data = s->chgroup[i].channel_data; @@ -1072,24 +1072,24 @@ static void wma_inverse_channel_transfor int16_t* sfb; /** multichannel decorrelation */ - for(sfb = s->cur_sfb_offsets ; - sfb < s->cur_sfb_offsets + s->num_bands;sfb++){ - if(*tb++ == 1){ + for (sfb = s->cur_sfb_offsets ; + sfb < s->cur_sfb_offsets + s->num_bands;sfb++) { + if (*tb++ == 1) { int y; /** multiply values with the decorrelation_matrix */ - for(y=sfb[0];y<FFMIN(sfb[1], s->subframe_len);y++){ + for (y=sfb[0];y<FFMIN(sfb[1], s->subframe_len);y++) { const float* mat = s->chgroup[i].decorrelation_matrix; const float* data_end= data + num_channels; float* data_ptr= data; float** ch; - for(ch = ch_data;ch < ch_end; ch++) + for (ch = ch_data;ch < ch_end; ch++) *data_ptr++ = (*ch)[y]; - for(ch = ch_data; ch < ch_end; ch++){ + for (ch = ch_data; ch < ch_end; ch++) { float sum = 0; data_ptr = data; - while(data_ptr < data_end) + while (data_ptr < data_end) sum += *data_ptr++ * *mat++; (*ch)[y] = sum; @@ -1108,14 +1108,14 @@ static void wma_inverse_channel_transfor static void wma_window(WMA3DecodeContext *s) { int i; - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; float* start; float* window; int winlen = s->channel[c].prev_block_len; start = s->channel[c].coeffs - (winlen >> 1); - if(s->subframe_len < winlen){ + if (s->subframe_len < winlen) { start += (winlen - s->subframe_len)>>1; winlen = s->subframe_len; } @@ -1150,9 +1150,9 @@ static int wma_decode_subframe(WMA3Decod == the next block of the channel with the smallest number of decoded samples */ - for(i=0;i<s->num_channels;i++){ + for (i=0;i<s->num_channels;i++) { s->channel[i].grouped = 0; - if(offset > s->channel[i].decoded_samples){ + if (offset > s->channel[i].decoded_samples) { offset = s->channel[i].decoded_samples; subframe_len = s->channel[i].subframe_len[s->channel[i].cur_subframe]; @@ -1164,14 +1164,14 @@ static int wma_decode_subframe(WMA3Decod /** get a list of all channels that contain the estimated block */ s->channels_for_cur_subframe = 0; - for(i=0;i<s->num_channels;i++){ + for (i=0;i<s->num_channels;i++) { const int cur_subframe = s->channel[i].cur_subframe; /** substract already processed samples */ total_samples -= s->channel[i].decoded_samples; /** and count if there are multiple subframes that match our profile */ - if(offset == s->channel[i].decoded_samples && - subframe_len == s->channel[i].subframe_len[cur_subframe]){ + if (offset == s->channel[i].decoded_samples && + subframe_len == s->channel[i].subframe_len[cur_subframe]) { total_samples -= s->channel[i].subframe_len[cur_subframe]; s->channel[i].decoded_samples += s->channel[i].subframe_len[cur_subframe]; @@ -1182,7 +1182,7 @@ static int wma_decode_subframe(WMA3Decod /** check if the frame will be complete after processing the estimated block */ - if(!total_samples) + if (!total_samples) s->parsed_all_subframes = 1; @@ -1190,7 +1190,7 @@ static int wma_decode_subframe(WMA3Decod s->channels_for_cur_subframe); /** calculate number of scale factor bands and their offsets */ - if(subframe_len == s->samples_per_frame){ + if (subframe_len == s->samples_per_frame) { s->num_bands = s->num_sfb[0]; s->cur_sfb_offsets = s->sfb_offsets; s->cur_subwoofer_cutoff = s->subwoofer_cutoffs[0]; @@ -1202,7 +1202,7 @@ static int wma_decode_subframe(WMA3Decod } /** configure the decoder for the current subframe */ - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; s->channel[c].coeffs = &s->channel[c].out[(s->samples_per_frame>>1) @@ -1210,7 +1210,7 @@ static int wma_decode_subframe(WMA3Decod memset(s->channel[c].coeffs,0,sizeof(float) * subframe_len); /** init some things if this is the first subframe */ - if(!s->channel[c].cur_subframe){ + if (!s->channel[c].cur_subframe) { s->channel[c].scale_factor_step = 1; s->channel[c].max_scale_factor = 0; memset(s->channel[c].scale_factors, 0, @@ -1225,15 +1225,15 @@ static int wma_decode_subframe(WMA3Decod s->esc_len = av_log2(s->subframe_len - 1) + 1; /** skip extended header if any */ - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { int num_fill_bits; - if(!(num_fill_bits = get_bits(&s->gb,2))){ + if (!(num_fill_bits = get_bits(&s->gb,2))) { num_fill_bits = get_bits(&s->gb,4); num_fill_bits = get_bits(&s->gb,num_fill_bits) + 1; } - if(num_fill_bits >= 0){ - if(get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits){ + if (num_fill_bits >= 0) { + if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) { av_log(s->avctx,AV_LOG_ERROR,"invalid number of fill bits\n"); return 0; } @@ -1243,48 +1243,48 @@ static int wma_decode_subframe(WMA3Decod } /** no idea for what the following bit is used */ - if(get_bits1(&s->gb)){ + if (get_bits1(&s->gb)) { av_log(s->avctx,AV_LOG_ERROR,"reserved bit set\n"); return 0; } - if(!wma_decode_channel_transform(s)) + if (!wma_decode_channel_transform(s)) return 0; - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; - if((s->channel[c].transmit_coefs = get_bits1(&s->gb))) + if ((s->channel[c].transmit_coefs = get_bits1(&s->gb))) transmit_coeffs = 1; } s->quant_step = 90 * s->sample_bit_depth >> 4; - if(transmit_coeffs){ + if (transmit_coeffs) { int quant; int sign = 1; - if((get_bits1(&s->gb))){ + if ((get_bits1(&s->gb))) { /** FIXME: might change run level mode decision */ av_log(s->avctx,AV_LOG_ERROR,"unsupported quant step coding\n"); return 0; } /** decode quantization step */ quant = get_bits(&s->gb,6); - if(quant & 0x20){ + if (quant & 0x20) { quant |= 0xFFFFFFC0u; sign = -1; } s->quant_step += quant; - if(quant <= -32 || quant > 30){ - while(get_bits_count(&s->gb) + 5 < s->num_saved_bits){ + if (quant <= -32 || quant > 30) { + while (get_bits_count(&s->gb) + 5 < s->num_saved_bits) { quant = get_bits(&s->gb,5); - if(quant != 31){ + if (quant != 31) { s->quant_step += quant * sign; break; } s->quant_step += 31 * sign; - if(s->quant_step < 0){ + if (s->quant_step < 0) { av_log(s->avctx,AV_LOG_DEBUG,"negative quant step\n"); } } @@ -1292,15 +1292,15 @@ static int wma_decode_subframe(WMA3Decod /** decode quantization step modifiers for every channel */ - if(s->channels_for_cur_subframe == 1) + if (s->channels_for_cur_subframe == 1) s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step_modifier = 0; else{ int modifier_len = get_bits(&s->gb,3); - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; s->channel[c].quant_step_modifier = 0; - if(get_bits1(&s->gb)){ - if(modifier_len) + if (get_bits1(&s->gb)) { + if (modifier_len) s->channel[c].quant_step_modifier = get_bits(&s->gb,modifier_len) + 1; else @@ -1312,7 +1312,7 @@ static int wma_decode_subframe(WMA3Decod } /** decode scale factors */ - if(!wma_decode_scale_factors(s)) + if (!wma_decode_scale_factors(s)) return 0; } @@ -1320,9 +1320,9 @@ static int wma_decode_subframe(WMA3Decod get_bits_count(&s->gb) - s->subframe_offset); /** parse coefficients */ - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; - if(s->channel[c].transmit_coefs && + if (s->channel[c].transmit_coefs && get_bits_count(&s->gb) < s->num_saved_bits) wma_decode_coeffs(s,c); } @@ -1330,33 +1330,33 @@ static int wma_decode_subframe(WMA3Decod av_log(s->avctx,AV_LOG_DEBUG,"BITSTREAM: subframe length was %i\n", get_bits_count(&s->gb) - s->subframe_offset); - if(transmit_coeffs){ + if (transmit_coeffs) { /** reconstruct the per channel data */ wma_inverse_channel_transform(s); - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; int b; - if(c == s->lfe_channel) + if (c == s->lfe_channel) memset(&s->tmp[s->cur_subwoofer_cutoff],0, sizeof(float) * (subframe_len - s->cur_subwoofer_cutoff)); /** inverse quantization and rescaling */ - for(b=0;b<s->num_bands;b++){ + for (b=0;b<s->num_bands;b++) { int start = s->cur_sfb_offsets[b]; int end = s->cur_sfb_offsets[b+1]; int sf = s->channel[c].max_scale_factor; float quant; - if(end > s->subframe_len) + if (end > s->subframe_len) end = s->subframe_len; - if(s->channel[c].transmit_sf) + if (s->channel[c].transmit_sf) sf -= s->channel[c].scale_factors[b]; else sf -= s->channel[c].resampled_scale_factors[b]; sf *= -s->channel[c].scale_factor_step; sf += s->quant_step + s->channel[c].quant_step_modifier; quant = pow(10.0,sf / 20.0); - while(start < end){ + while (start < end) { s->tmp[start] = s->channel[c].coeffs[start] * quant; ++start; } @@ -1372,9 +1372,9 @@ static int wma_decode_subframe(WMA3Decod wma_window(s); /** handled one subframe */ - for(i=0;i<s->channels_for_cur_subframe;i++){ + for (i=0;i<s->channels_for_cur_subframe;i++) { int c = s->channel_indexes_for_cur_subframe[i]; - if(s->channel[c].cur_subframe >= s->channel[c].num_subframes){ + if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) { av_log(s->avctx,AV_LOG_ERROR,"broken subframe\n"); return 0; } @@ -1398,7 +1398,7 @@ static int wma_decode_frame(WMA3DecodeCo int i; /** check for potential output buffer overflow */ - if(s->samples + s->num_channels * s->samples_per_frame > s->samples_end){ + if (s->samples + s->num_channels * s->samples_per_frame > s->samples_end) { av_log(s->avctx,AV_LOG_ERROR, "not enough space for the output samples\n"); s->packet_loss = 1; @@ -1406,43 +1406,43 @@ static int wma_decode_frame(WMA3DecodeCo } /** get frame length */ - if(s->len_prefix) + if (s->len_prefix) len = get_bits(gb,s->log2_frame_size); av_log(s->avctx,AV_LOG_DEBUG,"decoding frame with length %x\n",len); /** decode tile information */ - if(wma_decode_tilehdr(s)){ + if (wma_decode_tilehdr(s)) { s->packet_loss = 1; return 0; } /** read postproc transform */ - if(s->num_channels > 1 && get_bits1(gb)){ + if (s->num_channels > 1 && get_bits1(gb)) { av_log(s->avctx,AV_LOG_ERROR,"Unsupported postproc transform found\n"); s->packet_loss = 1; return 0; } /** read drc info */ - if(s->dynamic_range_compression){ + if (s->dynamic_range_compression) { s->drc_gain = get_bits(gb,8); av_log(s->avctx,AV_LOG_DEBUG,"drc_gain %i\n",s->drc_gain); } /** no idea what these are for, might be the number of samples that need to be skipped at the beginning or end of a stream */ - if(get_bits1(gb)){ + if (get_bits1(gb)) { int skip; /** usually true for the first frame */ - if(get_bits1(gb)){ + if (get_bits1(gb)) { skip = get_bits(gb,av_log2(s->samples_per_frame * 2)); av_log(s->avctx,AV_LOG_DEBUG,"start skip: %i\n",skip); } /** sometimes true for the last frame */ - if(get_bits1(gb)){ + if (get_bits1(gb)) { skip = get_bits(gb,av_log2(s->samples_per_frame * 2)); av_log(s->avctx,AV_LOG_DEBUG,"end skip: %i\n",skip); } @@ -1454,22 +1454,22 @@ static int wma_decode_frame(WMA3DecodeCo /** reset subframe states */ s->parsed_all_subframes = 0; - for(i=0;i<s->num_channels;i++){ + for (i=0;i<s->num_channels;i++) { s->channel[i].decoded_samples = 0; s->channel[i].cur_subframe = 0; s->channel[i].reuse_sf = 0; } /** decode all subframes */ - while(!s->parsed_all_subframes){ - if(!wma_decode_subframe(s)){ + while (!s->parsed_all_subframes) { + if (!wma_decode_subframe(s)) { s->packet_loss = 1; return 0; } } /** convert samples to short and write them to the output buffer */ - for(i = 0; i < s->num_channels; i++) { + for (i = 0; i < s->num_channels; i++) { int16_t* ptr; int incr = s->num_channels; float* iptr = s->channel[i].out; @@ -1477,7 +1477,7 @@ static int wma_decode_frame(WMA3DecodeCo ptr = s->samples + i; - for(x=0;x<s->samples_per_frame;x++) { + for (x=0;x<s->samples_per_frame;x++) { *ptr = av_clip_int16(lrintf(*iptr++)); ptr += incr; } @@ -1488,12 +1488,12 @@ static int wma_decode_frame(WMA3DecodeCo s->samples_per_frame * sizeof(float)); } - if(s->skip_frame) + if (s->skip_frame) s->skip_frame = 0; else s->samples += s->num_channels * s->samples_per_frame; - if(len != (get_bits_count(gb) - s->frame_offset) + 2){ + if (len != (get_bits_count(gb) - s->frame_offset) + 2) { /** FIXME: not sure if this is always an error */ av_log(s->avctx,AV_LOG_ERROR,"frame[%i] would have to skip %i bits\n", s->frame_num,len - (get_bits_count(gb) - s->frame_offset) - 1); @@ -1536,20 +1536,20 @@ static void wma_save_bits(WMA3DecodeCont int bit_offset; int pos; - if(!append){ + if (!append) { s->frame_offset = get_bits_count(gb) & 7; s->num_saved_bits = s->frame_offset; } buflen = (s->num_saved_bits + len + 8) >> 3; - if(len <= 0 || buflen > MAX_FRAMESIZE){ + if (len <= 0 || buflen > MAX_FRAMESIZE) { av_log(s->avctx, AV_LOG_ERROR, "input buffer to small\n"); s->packet_loss = 1; return; } - if(!append){ + if (!append) { s->num_saved_bits += len; memcpy(s->frame_data, gb->buffer + (get_bits_count(gb) >> 3), (s->num_saved_bits + 8)>> 3); @@ -1561,7 +1561,7 @@ static void wma_save_bits(WMA3DecodeCont s->num_saved_bits += len; /** byte align prev_frame buffer */ - if(bit_offset){ + if (bit_offset) { int missing = 8 - bit_offset; missing = FFMIN(len, missing); s->frame_data[pos++] |= @@ -1570,13 +1570,13 @@ static void wma_save_bits(WMA3DecodeCont } /** copy full bytes */ - while(len > 7){ + while (len > 7) { s->frame_data[pos++] = get_bits(gb,8); len -= 8; } /** copy remaining bits */ - if(len > 0) + if (len > 0) s->frame_data[pos++] = get_bits(gb,len) << (8 - len); } @@ -1612,7 +1612,7 @@ static int wma_decode_packet(AVCodecCont *data_size = 0; /** sanity check for the buffer length */ - if(buf_size < avctx->block_align) + if (buf_size < avctx->block_align) return 0; buf_size = avctx->block_align; @@ -1644,34 +1644,34 @@ static int wma_decode_packet(AVCodecCont s->num_saved_bits - s->frame_offset); /** decode the cross packet frame if it is valid */ - if(!s->packet_loss) + if (!s->packet_loss) wma_decode_frame(s); - }else if(s->num_saved_bits - s->frame_offset){ + }else if (s->num_saved_bits - s->frame_offset) { av_log(avctx, AV_LOG_DEBUG, "ignoring %x previously saved bits\n", s->num_saved_bits - s->frame_offset); } s->packet_loss = 0; /** decode the rest of the packet */ - while(!s->packet_loss && more_frames && - wma_remaining_bits(s,&gb) > s->log2_frame_size){ + while (!s->packet_loss && more_frames && + wma_remaining_bits(s,&gb) > s->log2_frame_size) { int frame_size = show_bits(&gb, s->log2_frame_size); /** there is enough data for a full frame */ - if(wma_remaining_bits(s,&gb) >= frame_size && frame_size > 0){ + if (wma_remaining_bits(s,&gb) >= frame_size && frame_size > 0) { wma_save_bits(s, &gb, frame_size, 0); /** decode the frame */ more_frames = wma_decode_frame(s); - if(!more_frames){ + if (!more_frames) { av_log(avctx, AV_LOG_DEBUG, "no more frames\n"); } }else more_frames = 0; } - if(!s->packet_loss){ + if (!s->packet_loss) { /** save the rest of the data so that it can be decoded with the next packet */ wma_save_bits(s, &gb, wma_remaining_bits(s,&gb), 0); @@ -1692,7 +1692,7 @@ static void wma_flush(AVCodecContext *av int i; /** reset output buffer as a part of it is used during the windowing of a new frame */ - for(i=0;i<s->num_channels;i++) + for (i=0;i<s->num_channels;i++) memset(s->channel[i].out, 0, s->samples_per_frame * sizeof(float)); s->packet_loss = 1; }
participants (1)
-
faust3