[FFmpeg-soc] [soc]: r2438 - in aacenc: aacenc.c aacpsy.c
kostya
subversion at mplayerhq.hu
Sat Jun 14 19:13:02 CEST 2008
Author: kostya
Date: Sat Jun 14 19:13:02 2008
New Revision: 2438
Log:
Take number of windows into account when encoding
Modified:
aacenc/aacenc.c
aacenc/aacpsy.c
Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c (original)
+++ aacenc/aacenc.c Sat Jun 14 19:13:02 2008
@@ -274,18 +274,19 @@ static void put_ics_info(AVCodecContext
*/
static void encode_ms_info(PutBitContext *pb, cpe_struct *cpe)
{
- int i;
+ int i, w;
put_bits(pb, 2, cpe->ms.present);
if(cpe->ms.present == 1)
- for(i = 0; i < cpe->ch[0].ics.max_sfb; i++)
- put_bits(pb, 1, cpe->ms.mask[0][i]);
+ for(w = 0; w < cpe->ch[0].ics.num_windows; w++)
+ for(i = 0; i < cpe->ch[0].ics.max_sfb; i++)
+ put_bits(pb, 1, cpe->ms.mask[w][i]);
}
/**
* Scan spectral band and determine optimal codebook for it.
*/
-static int determine_section_info(AACEncContext *s, cpe_struct *cpe, int channel, int band, int start, int size)
+static int determine_section_info(AACEncContext *s, cpe_struct *cpe, int channel, int win, int band, int start, int size)
{
int i, j;
int maxval, sign;
@@ -309,7 +310,7 @@ static int determine_section_info(AACEnc
for(; cb < 12; cb++){
score = 0;
dim = (aac_cb_info[cb].flags & CB_PAIRS) ? 2 : 4;
- if(!band || cpe->ch[channel].cb[0][band - 1] != cb)
+ if(!band || cpe->ch[channel].cb[win][band - 1] != cb)
score += 9; //that's for new codebook entry
if(aac_cb_info[cb].flags & CB_UNSIGNED){
for(i = start; i < start + size; i += dim){
@@ -389,12 +390,13 @@ static void encode_codebook(AACEncContex
static void encode_section_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
{
- int i;
- int bits = 5; //for long window
+ int i, w;
+ int bits = cpe->ch[channel].ics.num_windows == 1 ? 5 : 3;
int count = 0;
+ for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
- if(!i || cpe->ch[channel].cb[0][i] != cpe->ch[channel].cb[0][i-1]){
+ if(!i || cpe->ch[channel].cb[w][i] != cpe->ch[channel].cb[w][i-1]){
if(count){
while(count >= (1 << bits) - 1){
put_bits(&s->pb, bits, (1 << bits) - 1);
@@ -402,7 +404,7 @@ static void encode_section_data(AVCodecC
}
put_bits(&s->pb, bits, count);
}
- put_bits(&s->pb, 4, cpe->ch[channel].cb[0][i]);
+ put_bits(&s->pb, 4, cpe->ch[channel].cb[w][i]);
count = 1;
}else
count++;
@@ -414,30 +416,35 @@ static void encode_section_data(AVCodecC
}
put_bits(&s->pb, bits, count);
}
+ }
}
static void encode_scale_factor_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
{
int off = cpe->ch[channel].gain, diff;
- int i;
+ int i, w;
- for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
- if(!cpe->ch[channel].zeroes[0][i]){
- diff = cpe->ch[channel].sf_idx[0][i] - off + SCALE_DIFF_ZERO;
- off = cpe->ch[channel].sf_idx[0][i];
- put_bits(&s->pb, bits[diff], code[diff]);
+ for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
+ for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
+ if(!cpe->ch[channel].zeroes[w][i]){
+ diff = cpe->ch[channel].sf_idx[w][i] - off + SCALE_DIFF_ZERO;
+ off = cpe->ch[channel].sf_idx[w][i];
+ put_bits(&s->pb, bits[diff], code[diff]);
+ }
}
}
}
static void encode_spectral_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
{
- int start = 0, i;
+ int start = 0, i, w;
- for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
- if(!cpe->ch[channel].zeroes[0][i])
- encode_codebook(s, cpe, channel, start, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].cb[0][i]);
- start += cpe->ch[channel].ics.swb_sizes[i];
+ for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
+ for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
+ if(!cpe->ch[channel].zeroes[w][i])
+ encode_codebook(s, cpe, channel, start, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].cb[w][i]);
+ start += cpe->ch[channel].ics.swb_sizes[i];
+ }
}
}
@@ -447,17 +454,18 @@ static void encode_spectral_data(AVCodec
static int encode_individual_channel(AVCodecContext *avctx, cpe_struct *cpe, int channel)
{
AACEncContext *s = avctx->priv_data;
- int i, j, g = 0;
+ int i, j, g, w;
- i = 0;
- while(i < 1024){
- if(!cpe->ch[channel].zeroes[0][g]){
- cpe->ch[channel].cb[0][g] = determine_section_info(s, cpe, channel, g, i, cpe->ch[channel].ics.swb_sizes[g]);
- cpe->ch[channel].zeroes[0][g] = !cpe->ch[channel].cb[0][g];
- }else
- cpe->ch[channel].cb[0][g] = 0;
- i += cpe->ch[channel].ics.swb_sizes[g];
- g++;
+ for(w = 0; w < cpe->ch[channel].ics.num_windows; w++){
+ i = w << 7;
+ for(g = 0; g < cpe->ch[channel].ics.max_sfb; g++){
+ if(!cpe->ch[channel].zeroes[w][g]){
+ cpe->ch[channel].cb[w][g] = determine_section_info(s, cpe, channel, w, g, i, cpe->ch[channel].ics.swb_sizes[g]);
+ cpe->ch[channel].zeroes[w][g] = !cpe->ch[channel].cb[w][g];
+ }else
+ cpe->ch[channel].cb[w][g] = 0;
+ i += cpe->ch[channel].ics.swb_sizes[g];
+ }
}
put_bits(&s->pb, 8, cpe->ch[channel].gain); //global gain
Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c (original)
+++ aacenc/aacpsy.c Sat Jun 14 19:13:02 2008
@@ -43,6 +43,7 @@ static void psy_null_window(AACPsyContex
for(ch = 0; ch < apc->avctx->channels; ch++){
cpe->ch[ch].ics.window_sequence = 0;
cpe->ch[ch].ics.window_shape = 1;
+ cpe->ch[ch].ics.num_windows = 1;
cpe->ch[ch].ics.swb_sizes = apc->bands1024;
cpe->ch[ch].ics.num_swb = apc->num_bands1024;
}
More information about the FFmpeg-soc
mailing list