# HG changeset patch # User alexc # Date 1277761766 0 # Node ID 2e7db647fef84cb6f3e2d1ff51226782ce3cfd76 # Parent 081702713f47f723f1382bb604f50f41eefa245c 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. diff -r 081702713f47 -r 2e7db647fef8 aacpsy.c --- a/aacpsy.c Mon Jun 28 21:42:57 2010 +0000 +++ b/aacpsy.c Mon Jun 28 21:49:26 2010 +0000 @@ -185,6 +185,7 @@ 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 @@ 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 @@ 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;