shithub: opus

Download patch

ref: 0be05b0335818d5dd7251fce0ae08fdbc76d4abb
parent: a2546bbf72ad545e3d108a8d0e4b3ed4f1759187
author: Jean-Marc Valin <[email protected]>
date: Fri Jul 16 10:23:03 EDT 2010

Encoding transient_time independently of the sampling rate

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -710,7 +710,7 @@
    int intra_ener = 0;
    int shortBlocks=0;
    int isTransient=0;
-   int transient_time;
+   int transient_time, transient_time_quant;
    int transient_shift;
    int resynth;
    const int C = CHANNELS(st->channels);
@@ -776,6 +776,7 @@
 
    /* Transient handling */
    transient_time = -1;
+   transient_time_quant = -1;
    transient_shift = 0;
    isTransient = 0;
 
@@ -789,6 +790,8 @@
       /* Apply the inverse shaping window */
       if (transient_shift)
       {
+         transient_time_quant = transient_time*(celt_int32)8000/st->mode->Fs;
+         transient_time = transient_time_quant*(celt_int32)st->mode->Fs/8000;
 #ifdef FIXED_POINT
          for (c=0;c<C;c++)
             for (i=0;i<16;i++)
@@ -927,8 +930,9 @@
    {
       if (transient_shift)
       {
+         int max_time = (N+st->mode->overlap)*(celt_int32)8000/st->mode->Fs;
          ec_enc_uint(enc, transient_shift, 4);
-         ec_enc_uint(enc, transient_time, N+st->overlap);
+         ec_enc_uint(enc, transient_time_quant, max_time);
       } else {
          ec_enc_uint(enc, mdct_weight_shift, 4);
          if (mdct_weight_shift && M!=2)
@@ -1732,7 +1736,10 @@
       transient_shift = ec_dec_uint(dec, 4);
       if (transient_shift == 3)
       {
-         transient_time = ec_dec_uint(dec, N+st->mode->overlap);
+         int transient_time_quant;
+         int max_time = (N+st->mode->overlap)*(celt_int32)8000/st->mode->Fs;
+         transient_time_quant = ec_dec_uint(dec, max_time);
+         transient_time = transient_time_quant*(celt_int32)st->mode->Fs/8000;
       } else {
          mdct_weight_shift = transient_shift;
          if (mdct_weight_shift && M>2)