aacenc: Fix window decision logic.

This keeps the encoder from switching away from an wight short sequence
prematurely when attacks are detected two frames in a row. It also allows for
the legal and useful LONG_STOP_SEQUENCE to LONG_START_SEQUENCE transition.

Originally committed as revision 23870 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Alex Converse 2010-06-28 21:49:26 +00:00
parent 804d489c4a
commit 75ef689884
1 changed files with 12 additions and 3 deletions

View File

@ -185,6 +185,7 @@ static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
Psy3gppContext *pctx = (Psy3gppContext*) ctx->model_priv_data;
Psy3gppChannel *pch = &pctx->ch[channel];
uint8_t grouping = 0;
int next_type = pch->next_window_seq;
FFPsyWindowInfo wi;
memset(&wi, 0, sizeof(wi));
@ -193,6 +194,7 @@ static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
int switch_to_eight = 0;
float sum = 0.0, sum2 = 0.0;
int attack_n = 0;
int stay_short = 0;
for (i = 0; i < 8; i++) {
for (j = 0; j < 128; j++) {
v = iir_filter(la[(i*128+j)*ctx->avctx->channels], pch->iir_state);
@ -214,20 +216,27 @@ static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
switch (prev_type) {
case ONLY_LONG_SEQUENCE:
wi.window_type[0] = switch_to_eight ? LONG_START_SEQUENCE : ONLY_LONG_SEQUENCE;
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : ONLY_LONG_SEQUENCE;
break;
case LONG_START_SEQUENCE:
wi.window_type[0] = EIGHT_SHORT_SEQUENCE;
grouping = pch->next_grouping;
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
break;
case LONG_STOP_SEQUENCE:
wi.window_type[0] = ONLY_LONG_SEQUENCE;
wi.window_type[0] = switch_to_eight ? LONG_START_SEQUENCE : ONLY_LONG_SEQUENCE;
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : ONLY_LONG_SEQUENCE;
break;
case EIGHT_SHORT_SEQUENCE:
wi.window_type[0] = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
grouping = switch_to_eight ? pch->next_grouping : 0;
stay_short = next_type == EIGHT_SHORT_SEQUENCE || switch_to_eight;
wi.window_type[0] = stay_short ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
grouping = next_type == EIGHT_SHORT_SEQUENCE ? pch->next_grouping : 0;
next_type = switch_to_eight ? EIGHT_SHORT_SEQUENCE : LONG_STOP_SEQUENCE;
break;
}
pch->next_grouping = window_grouping[attack_n];
pch->next_window_seq = next_type;
} else {
for (i = 0; i < 3; i++)
wi.window_type[i] = prev_type;