shithub: opus

Download patch

ref: ba7dbb365ebb1acff445a017d31e1bb859f0a9fb
parent: fc1b1f9b441c2ffe090046c968e5d95f2eafb038
author: Jean-Marc Valin <[email protected]>
date: Mon Sep 9 12:39:19 EDT 2013

Analysis scaling fixes

This should make the scaling the same for fixed and float. It changes the float
scaling too by normalizing by the number of channels, which matters for
bandwidth detection.

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -822,7 +822,7 @@
 #ifndef DISABLE_FLOAT_API
    if (analysis->valid)
    {
-      trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), 2*(analysis->tonality_slope+.05f)));
+      trim -= MAX16(-QCONST16(2.f, 8), MIN16(QCONST16(2.f, 8), QCONST16(2.f, 8)*(analysis->tonality_slope+.05f)));
    }
 #endif
 
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -347,7 +347,7 @@
           tonal->highE[b]+=.5f;
           tonal->lowE[b]-=.5f;
        }
-       relativeE += (logE[b]-tonal->lowE[b])/(EPSILON+tonal->highE[b]-tonal->lowE[b]);
+       relativeE += (logE[b]-tonal->lowE[b])/(1e-15+tonal->highE[b]-tonal->lowE[b]);
 
        L1=L2=0;
        for (i=0;i<NB_FRAMES;i++)
@@ -356,12 +356,12 @@
           L2 += tonal->E[i][b];
        }
 
-       stationarity = MIN16(0.99f,L1/sqrt(EPSILON+NB_FRAMES*L2));
+       stationarity = MIN16(0.99f,L1/sqrt(1e-15+NB_FRAMES*L2));
        stationarity *= stationarity;
        stationarity *= stationarity;
        frame_stationarity += stationarity;
        /*band_tonality[b] = tE/(1e-15+E)*/;
-       band_tonality[b] = MAX16(tE/(EPSILON+E), stationarity*tonal->prev_band_tonality[b]);
+       band_tonality[b] = MAX16(tE/(1e-15+E), stationarity*tonal->prev_band_tonality[b]);
 #if 0
        if (b>=NB_TONAL_SKIP_BANDS)
        {
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -762,6 +762,7 @@
 void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C)
 {
    const float *x;
+   opus_val32 scale;
    int j;
    x = (const float *)_x;
    for (j=0;j<subframe;j++)
@@ -780,16 +781,16 @@
       }
    }
 #ifdef FIXED_POINT
-   {
-      opus_val32 scale =(1<<SIG_SHIFT);
-      if (C==-2)
-         scale /= C;
-      else
-         scale /= 2;
-      for (j=0;j<subframe;j++)
-         sub[j] *= scale;
-   }
+   scale = (1<<SIG_SHIFT);
+#else
+   scale = 1.f;
 #endif
+   if (C==-2)
+      scale /= C;
+   else
+      scale /= 2;
+   for (j=0;j<subframe;j++)
+      sub[j] *= scale;
 }
 #endif
 
@@ -796,6 +797,7 @@
 void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C)
 {
    const opus_int16 *x;
+   opus_val32 scale;
    int j;
    x = (const opus_int16 *)_x;
    for (j=0;j<subframe;j++)
@@ -814,19 +816,16 @@
       }
    }
 #ifdef FIXED_POINT
-   {
-      opus_val32 scale =(1<<SIG_SHIFT);
-      if (C==-2)
-         scale /= C;
-      else
-         scale /= 2;
-      for (j=0;j<subframe;j++)
-         sub[j] *= scale;
-   }
+   scale = (1<<SIG_SHIFT);
 #else
-   for (j=0;j<subframe;j++)
-      sub[j] *= (1.f/32768);
+   scale = 1.f/32768;
 #endif
+   if (C==-2)
+      scale /= C;
+   else
+      scale /= 2;
+   for (j=0;j<subframe;j++)
+      sub[j] *= scale;
 }
 
 opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs)