[FFmpeg-soc] [soc]: r3660 - in aacenc: aacenc.c aacpsy.c
kostya
subversion at mplayerhq.hu
Thu Aug 28 13:38:53 CEST 2008
Author: kostya
Date: Thu Aug 28 13:38:53 2008
New Revision: 3660
Log:
Use sparse group_len[] in a way that number of window groups can be ignored
Modified:
aacenc/aacenc.c
aacenc/aacpsy.c
Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c (original)
+++ aacenc/aacenc.c Thu Aug 28 13:38:53 2008
@@ -317,7 +317,7 @@ static void apply_window_and_mdct(AVCode
*/
static void put_ics_info(AACEncContext *s, IndividualChannelStream *info)
{
- int wg;
+ int w;
put_bits(&s->pb, 1, 0); // ics_reserved bit
put_bits(&s->pb, 2, info->window_sequence[0]);
@@ -327,11 +327,8 @@ static void put_ics_info(AACEncContext *
put_bits(&s->pb, 1, 0); // no prediction
}else{
put_bits(&s->pb, 4, info->max_sfb);
- for(wg = 0; wg < info->num_window_groups; wg++){
- if(wg)
- put_bits(&s->pb, 1, 0);
- if(info->group_len[wg] > 1)
- put_sbits(&s->pb, info->group_len[wg] - 1, 0xFF);
+ for(w = 1; w < 8; w++){
+ put_bits(&s->pb, 1, !info->group_len[w]);
}
}
}
@@ -342,15 +339,13 @@ static void put_ics_info(AACEncContext *
*/
static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
{
- int i, w, wg;
+ int i, w;
put_bits(pb, 2, cpe->ms_mode);
if(cpe->ms_mode == 1){
- w = 0;
- for(wg = 0; wg < cpe->ch[0].ics.num_window_groups; wg++){
+ for(w = 0; w < cpe->ch[0].ics.num_windows; w += cpe->ch[0].ics.group_len[w]){
for(i = 0; i < cpe->ch[0].ics.max_sfb; i++)
- put_bits(pb, 1, cpe->ms_mask[w + i]);
- w += cpe->ch[0].ics.group_len[wg]*16;
+ put_bits(pb, 1, cpe->ms_mask[w*16 + i]);
}
}
}
@@ -595,12 +590,10 @@ static void encode_band_coeffs(AACEncCon
*/
static void encode_band_info(AACEncContext *s, SingleChannelElement *sce)
{
- int w, wg;
+ int w;
- w = 0;
- for(wg = 0; wg < sce->ics.num_window_groups; wg++){
- encode_window_bands_info(s, sce, w, sce->ics.group_len[wg]);
- w += sce->ics.group_len[wg];
+ for(w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]){
+ encode_window_bands_info(s, sce, w, sce->ics.group_len[w]);
}
}
@@ -610,10 +603,9 @@ static void encode_band_info(AACEncConte
static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int global_gain)
{
int off = global_gain, diff;
- int i, w, wg;
+ int i, w;
- w = 0;
- for(wg = 0; wg < sce->ics.num_window_groups; wg++){
+ for(w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]){
for(i = 0; i < sce->ics.max_sfb; i++){
if(!sce->zeroes[w*16 + i]){
diff = sce->sf_idx[w*16 + i] - off + SCALE_DIFF_ZERO;
@@ -622,7 +614,6 @@ static void encode_scale_factors(AVCodec
put_bits(&s->pb, ff_aac_scalefactor_bits[diff], ff_aac_scalefactor_code[diff]);
}
}
- w += sce->ics.group_len[wg];
}
}
@@ -649,24 +640,22 @@ static void encode_pulses(AACEncContext
*/
static void encode_spectral_coeffs(AACEncContext *s, SingleChannelElement *sce)
{
- int start, i, w, w2, wg;
+ int start, i, w, w2;
- w = 0;
- for(wg = 0; wg < sce->ics.num_window_groups; wg++){
+ for(w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]){
start = 0;
for(i = 0; i < sce->ics.max_sfb; i++){
if(sce->zeroes[w*16 + i]){
start += sce->ics.swb_sizes[i];
continue;
}
- for(w2 = w; w2 < w + sce->ics.group_len[wg]; w2++){
+ for(w2 = w; w2 < w + sce->ics.group_len[w]; w2++){
encode_band_coeffs(s, sce, start + w2*128,
sce->ics.swb_sizes[i],
sce->band_type[w*16 + i]);
}
start += sce->ics.swb_sizes[i];
}
- w += sce->ics.group_len[wg];
}
}
@@ -675,33 +664,30 @@ static void encode_spectral_coeffs(AACEn
*/
static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
{
- int g, w, wg;
+ int g, w;
int global_gain, last = 256;
//determine global gain as standard recommends - the first scalefactor value
//and assign an appropriate scalefactor index to empty bands
- w = 0;
- for(wg = 0; wg < sce->ics.num_window_groups; wg++){
+ for(w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]){
for(g = sce->ics.max_sfb - 1; g >= 0; g--){
- if(sce->sf_idx[w + g] == 256)
- sce->sf_idx[w + g] = last;
+ if(sce->sf_idx[w*16 + g] == 256)
+ sce->sf_idx[w*16 + g] = last;
else
- last = sce->sf_idx[w + g];
+ last = sce->sf_idx[w*16 + g];
}
- w += sce->ics.group_len[wg]*16;
}
//make sure global gain won't be 256
last &= 0xFF;
global_gain = last;
//assign scalefactor index to tail bands in case encoder decides to code them
- for(wg = 0; wg < sce->ics.num_window_groups; wg++){
+ for(w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]){
for(g = 0; g < sce->ics.max_sfb; g++){
- if(sce->sf_idx[w + g] == 256)
- sce->sf_idx[w + g] = last;
+ if(sce->sf_idx[w*16 + g] == 256)
+ sce->sf_idx[w*16 + g] = last;
else
- last = sce->sf_idx[w + g];
+ last = sce->sf_idx[w*16 + g];
}
- w += sce->ics.group_len[wg]*16;
}
put_bits(&s->pb, 8, global_gain);
Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c (original)
+++ aacenc/aacpsy.c Thu Aug 28 13:38:53 2008
@@ -89,7 +89,7 @@ static inline float get_approximate_quan
*/
static void psy_create_output(AACPsyContext *apc, ChannelElement *cpe, int chans)
{
- int i, w, w2, wg, g, ch;
+ int i, w, w2, g, ch;
int start, sum, maxsfb, cmaxsfb;
for(ch = 0; ch < chans; ch++){
@@ -123,19 +123,17 @@ static void psy_create_output(AACPsyCont
ics->max_sfb = maxsfb;
//adjust zero bands for window groups
- w = 0;
- for(wg = 0; wg < ics->num_window_groups; wg++){
+ for(w = 0; w < ics->num_windows; w += ics->group_len[w]){
for(g = 0; g < ics->max_sfb; g++){
i = 1;
- for(w2 = 0; w2 < ics->group_len[wg]*16; w2 += 16){
- if(!cpe->ch[ch].zeroes[w + w2 + g]){
+ for(w2 = w; w2 < w + ics->group_len[w]; w2++){
+ if(!cpe->ch[ch].zeroes[w2*16 + g]){
i = 0;
break;
}
}
- cpe->ch[ch].zeroes[w + g] = i;
+ cpe->ch[ch].zeroes[w*16 + g] = i;
}
- w += ics->group_len[wg] * 16;
}
}
@@ -390,18 +388,16 @@ static void psy_3gpp_window(AACPsyContex
ics->num_window_groups = 1;
ics->group_len[0] = 1;
}else{
+ int lastgrp = 0;
ics->num_windows = 8;
ics->swb_sizes = apc->bands128;
ics->num_swb = apc->num_bands128;
ics->num_window_groups = 0;
- ics->group_len[0] = 1;
+ memset(ics->group_len, 0, sizeof(ics->group_len));
for(i = 0; i < 8; i++){
- if((grouping[ch] >> i) & 1){
- ics->group_len[ics->num_window_groups - 1]++;
- }else{
- ics->num_window_groups++;
- ics->group_len[ics->num_window_groups - 1] = 1;
- }
+ if(!((grouping[ch] >> i) & 1))
+ lastgrp = i;
+ ics->group_len[lastgrp]++;
}
}
}
@@ -468,7 +464,7 @@ static inline int determine_scalefactor(
static void psy_3gpp_process(AACPsyContext *apc, int tag, int type, ChannelElement *cpe)
{
int start;
- int ch, w, wg, g, i;
+ int ch, w, g, i;
int prev_scale;
Psy3gppContext *pctx = (Psy3gppContext*) apc->model_priv_data;
float pe_target;
@@ -691,19 +687,17 @@ static void psy_3gpp_process(AACPsyConte
}
//adjust scalefactors for window groups
- w = 0;
- for(wg = 0; wg < ics->num_window_groups; wg++){
+ for(w = 0; w < ics->num_windows; w += ics->group_len[w]){
int min_scale = 256;
for(g = 0; g < ics->num_swb; g++){
- for(i = w; i < w + ics->group_len[wg]*16; i += 16){
- if(cpe->ch[ch].zeroes[i + g]) continue;
- min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[i + g]);
+ for(i = w; i < w + ics->group_len[w]; i++){
+ if(cpe->ch[ch].zeroes[i*16 + g]) continue;
+ min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[i*16 + g]);
}
- for(i = w; i < w + ics->group_len[wg]*16; i += 16)
- cpe->ch[ch].sf_idx[i + g] = min_scale;
+ for(i = w; i < w + ics->group_len[w]; i++)
+ cpe->ch[ch].sf_idx[i*16 + g] = min_scale;
}
- w += ics->group_len[wg] * 16;
}
}
More information about the FFmpeg-soc
mailing list