shithub: opus

Download patch

ref: e082ddc18fef82217799fc5dd6bedc4ebbcc72ee
parent: 2941f08a616290f291579df9c8dbc0801d8d3f18
author: Jean-Marc Valin <jeanmarcv@google.com>
date: Thu May 29 08:07:43 EDT 2025

Moving transient analysis before the prefilter

Shouldn't make a huge difference, but would prevent the prefilter from
interfering with the transient analysis and (most importantly) would
allow us to disable the prefilter on strong transients.

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1857,10 +1857,22 @@
 #endif
       celt_preemphasis(pcm+c, in+c*(N+overlap)+overlap, N, CC, st->upsample,
                   mode->preemph, st->preemph_memE+c, need_clip);
+      OPUS_COPY(in+c*(N+overlap), &prefilter_mem[(1+c)*COMBFILTER_MAXPERIOD-overlap], overlap);
    } while (++c<CC);
 
 
    tone_freq = tone_detect(in+overlap, prefilter_mem, 1, N, overlap, &toneishness, mode->Fs);
+   isTransient = 0;
+   shortBlocks = 0;
+   if (st->complexity >= 1 && !st->lfe)
+   {
+      /* Reduces the likelihood of energy instability on fricatives at low bitrate
+         in hybrid mode. It seems like we still want to have real transients on vowels
+         though (small SILK quantization offset value). */
+      int allow_weak_transients = hybrid && effectiveBytes<15 && st->silk_info.signalType != 2;
+      isTransient = transient_analysis(in, N+overlap, CC,
+            &tf_estimate, &tf_chan, allow_weak_transients, &weak_transient, tone_freq, toneishness);
+   }
    /* Find pitch period and gain */
    {
       int enabled;
@@ -1890,18 +1902,6 @@
          ec_enc_bits(enc, qg, 3);
          ec_enc_icdf(enc, prefilter_tapset, tapset_icdf, 2);
       }
-   }
-
-   isTransient = 0;
-   shortBlocks = 0;
-   if (st->complexity >= 1 && !st->lfe)
-   {
-      /* Reduces the likelihood of energy instability on fricatives at low bitrate
-         in hybrid mode. It seems like we still want to have real transients on vowels
-         though (small SILK quantization offset value). */
-      int allow_weak_transients = hybrid && effectiveBytes<15 && st->silk_info.signalType != 2;
-      isTransient = transient_analysis(in, N+overlap, CC,
-            &tf_estimate, &tf_chan, allow_weak_transients, &weak_transient, tone_freq, toneishness);
    }
    if (LM>0 && ec_tell(enc)+3<=total_bits)
    {
--