diff --git a/libcelt/celt.c b/libcelt/celt.c index 386f1060..90c484db 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -95,6 +95,7 @@ struct CELTEncoder { celt_word16 tonal_average; int fold_decision; celt_word16 gain_prod; + celt_word32 frame_max; /* VBR-related parameters */ celt_int32 vbr_reservoir; @@ -266,48 +267,61 @@ static inline celt_word16 SIG2WORD16(celt_sig x) #endif } -static int transient_analysis(celt_word32 *in, int len, int C, int *transient_time, int *transient_shift) +static int transient_analysis(const celt_word32 * restrict in, int len, int C, + int *transient_time, int *transient_shift, + celt_word32 *frame_max) { - int c, i, n; + int i, n; celt_word32 ratio; + celt_word32 threshold; VARDECL(celt_word32, begin); SAVE_STACK; - ALLOC(begin, len, celt_word32); - for (i=0;i 1000) ratio = 1000; ratio *= ratio; - + if (ratio > 2048) *transient_shift = 3; else *transient_shift = 0; *transient_time = n; - + *frame_max = begin[len]; + RESTORE_STACK; return ratio > 20; } @@ -613,7 +627,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig resynth = st->pitch_available>0 || optional_synthesis!=NULL; - if (st->mode->nbShortMdcts > 1 && transient_analysis(in, N+st->overlap, C, &transient_time, &transient_shift)) + if (st->mode->nbShortMdcts > 1 && transient_analysis(in, N+st->overlap, C, &transient_time, &transient_shift, &st->frame_max)) { #ifndef FIXED_POINT float gain_1; @@ -1059,6 +1073,7 @@ int celt_encoder_ctl(CELTEncoder * restrict st, int request, ...) st->vbr_offset = 0; st->vbr_count = 0; st->xmem = 0; + st->frame_max = 0; CELT_MEMSET(st->pitch_buf, 0, (MAX_PERIOD>>1)+2); } break;