diff --git a/celt/celt.c b/celt/celt.c index e472de80..6e0a7bcc 100644 --- a/celt/celt.c +++ b/celt/celt.c @@ -293,31 +293,32 @@ static inline opus_val16 SIG2WORD16(celt_sig x) } static int transient_analysis(const opus_val32 * restrict in, int len, int C, - int overlap, opus_val16 *tf_estimate) + int overlap, opus_val16 *tf_estimate, int *tf_chan) { int i; VARDECL(opus_val16, tmp); - opus_val32 mem0=0,mem1=0; + opus_val32 mem0,mem1; int is_transient = 0; int block; - int N; - opus_val16 maxbin; - opus_val32 L1, L2, tf_tmp; + int c, N; + opus_val16 maxbin, minbin[3]; + opus_val32 L1, L2, tf_tmp, tf_max; VARDECL(opus_val16, bins); SAVE_STACK; ALLOC(tmp, len, opus_val16); - block = overlap/2; - N=len/block; + block = overlap/8; + N=len/block-1; ALLOC(bins, N, opus_val16); - if (C==1) + + *tf_estimate = 0; + tf_max = 0; + for (c=0;c 15*minbin[2]) + is_transient = 1; L1=0; L2=0; for (i=0;i=3) + if (conseq>=12) is_transient=1; conseq = 0; for (j=i+1;j=7) + if (conseq>=28) is_transient=1; } /* sqrt(L2*N)/L1 */ tf_tmp = SHL32(DIV32( SHL32(EXTEND32(celt_sqrt(SHR16(L2,4) * N)), 14), ADD32(EPSILON, L1)), 4); - *tf_estimate = MAX16(QCONST16(1.f, 14), EXTRACT16(MIN16(QCONST32(1.99, 14), tf_tmp))); + tf_tmp = 1+MIN16(1,MAX16(0, 1-10*minbin[2]/(1+maxbin))); + if (tf_tmp>tf_max) + { + *tf_chan = c; + tf_max = tf_tmp; + } + *tf_estimate = MAX16(*tf_estimate, EXTRACT16(MIN32(QCONST32(1.99, 14), tf_tmp))); + } + *tf_estimate = MAX16(QCONST16(1.f, 14), *tf_estimate); RESTORE_STACK; #ifdef FUZZING is_transient = rand()&0x1; #endif + //printf("%d %f\n", is_transient, *tf_estimate); return is_transient; } @@ -548,24 +579,22 @@ static const signed char tf_select_table[4][8] = { {0, -2, 0, -3, 3, 0, 1,-1}, }; -static opus_val32 l1_metric(const celt_norm *tmp, int N, int LM) +static opus_val32 l1_metric(const celt_norm *tmp, int N, int LM, opus_val16 bias) { int i; opus_val32 L1; - opus_val16 bias; L1 = 0; for (i=0;ieBands[i+1]-m->eBands[i])<eBands[i]<eBands[i]<eBands[i]<eBands[i]<>k, 1<complexity > 1) { isTransient = transient_analysis(in, N+st->overlap, CC, - st->overlap, &tf_estimate); + st->overlap, &tf_estimate, &tf_chan); if (isTransient) shortBlocks = M; } @@ -1291,12 +1327,15 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f compute_band_energies(st->mode, freq, bandE, effEnd, C, M); amp2Log2(st->mode, effEnd, st->end, bandE, bandLogE, C); + /*for (i=0;i<17;i++) + printf("%f ", bandLogE[i]); + printf("\n");*/ /* Band normalisation */ normalise_bands(st->mode, freq, X, bandE, effEnd, C, M); ALLOC(tf_res, st->mode->nbEBands, int); - tf_select = tf_analysis(st->mode, effEnd, C, isTransient, tf_res, effectiveBytes, X, N, LM, &tf_sum); + tf_select = tf_analysis(st->mode, effEnd, C, isTransient, tf_res, effectiveBytes, X, N, LM, &tf_sum, tf_estimate, tf_chan); for (i=effEnd;iend;i++) tf_res[i] = tf_res[effEnd-1]; @@ -1495,18 +1534,28 @@ int celt_encode_with_ec(CELTEncoder * restrict st, const opus_val16 * pcm, int f #ifdef FIXED_POINT new_target = SHL32(MULT16_32_Q15(target, SUB16(tf_estimate, QCONST16(0.05, 14))),1); #else - new_target = target*(tf_estimate-.05); + { + //float tf_factor = 1+MIN16(1,2*MAX16(0,sqrt(tf_estimate-1)-.2)); + float tf_factor = tf_estimate; + if (isTransient) + tf_factor = MAX16(1.2f, tf_factor); + //new_target = target*(tf_estimate-.05); + new_target = target*(tf_factor-.15); + //new_target = target*MIN32(2.f,MAX16(.85f,tf_sum/21.)); + //printf("%f %f %f %f ", tf_factor, tf_sum/21., target*(tf_estimate-1.05), target*MIN32(2.f,MAX16(.85f,tf_sum/21.))-target); + } #endif #ifndef FIXED_POINT if (st->analysis.valid) { int tonal_target; float tonal; - tonal = st->analysis.tonality*st->analysis.tonality; - tonal -= .08; - tonal_target = target + (coded_bins<analysis.tonality; + tonal -= .15; + tonal_target = target + (coded_bins<activity = 0; frame_noisiness = 0; frame_stationarity = 0; @@ -257,8 +265,19 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc frame_stationarity += stationarity; /*band_tonality[b] = tE/(1e-15+E)*/; band_tonality[b] = MAX16(tE/(EPSILON+E), stationarity*tonal->prev_band_tonality[b]); + //printf("%f ", band_tonality[b]); +#if 1 if (b>=NB_TONAL_SKIP_BANDS) - frame_tonality += band_tonality[b]; + { + frame_tonality += tweight[b]*band_tonality[b]; + tw_sum += tweight[b]; + } +#else + frame_tonality += band_tonality[b]; + if (b>=NB_TBANDS-NB_TONAL_SKIP_BANDS) + frame_tonality -= band_tonality[b-NB_TBANDS+NB_TONAL_SKIP_BANDS]; +#endif + max_frame_tonality = MAX16(max_frame_tonality, frame_tonality); slope += band_tonality[b]*(b-8); /*printf("%f %f ", band_tonality[b], stationarity);*/ if (band_tonality[b] > info->boost_amount[1] && b>=7 && b < NB_TBANDS-1) @@ -276,7 +295,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc } tonal->prev_band_tonality[b] = band_tonality[b]; } - + //printf("\n"); frame_loudness = 20*log10(frame_loudness); tonal->Etracker = MAX32(tonal->Etracker-.03, frame_loudness); tonal->lowECount *= (1-alphaE); @@ -301,7 +320,7 @@ void tonality_analysis(TonalityAnalysisState *tonal, AnalysisInfo *info, CELTEnc #else info->activity = .5*(1+frame_noisiness-frame_stationarity); #endif - frame_tonality /= NB_TBANDS-NB_TONAL_SKIP_BANDS; + frame_tonality = (max_frame_tonality/(tw_sum)); frame_tonality = MAX16(frame_tonality, tonal->prev_tonality*.8); tonal->prev_tonality = frame_tonality; info->boost_amount[0] -= frame_tonality+.2;