shithub: opus

Download patch

ref: 942fc816d12be9e42025f3b0e473660b4e5e89bf
parent: 1ad6f6d557d06289a58abb726f987e5e79688924
author: Jean-Marc Valin <[email protected]>
date: Tue Oct 1 15:27:30 EDT 2013

Replaces log2() with celt_log2() and fixes a potential divide-by-zero

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1179,7 +1179,7 @@
       tonal_target = target + (opus_int32)((coded_bins<<BITRES)*1.2f*tonal);
       if (pitch_change)
          tonal_target +=  (opus_int32)((coded_bins<<BITRES)*.8f);
-      /*printf("%f %f ", st->analysis.tonality, tonal);*/
+      /*printf("%f %f ", analysis->tonality, tonal);*/
       target = tonal_target;
    }
 #endif
@@ -1543,7 +1543,7 @@
       opus_val32 mask_avg=0;
       opus_val32 diff=0;
       int count=0;
-      mask_end = st->lastCodedBands;
+      mask_end = IMAX(2,st->lastCodedBands);
       for (c=0;c<C;c++)
       {
          for(i=0;i<mask_end;i++)
--- a/celt/mathops.h
+++ b/celt/mathops.h
@@ -165,6 +165,7 @@
 
 opus_val16 celt_cos_norm(opus_val32 x);
 
+/** Base-2 logarithm approximation (log2(x)). (Q14 input, Q10 output) */
 static inline opus_val16 celt_log2(opus_val32 x)
 {
    int i;
--- a/src/opus_multistream_encoder.c
+++ b/src/opus_multistream_encoder.c
@@ -227,6 +227,7 @@
    int pos[8] = {0};
    int upsample;
    int frame_size;
+   opus_val16 channel_offset;
    opus_val32 bandE[21];
    opus_val16 maskLogE[3][21];
    VARDECL(opus_val32, in);
@@ -293,7 +294,6 @@
 #if 0
       for (i=0;i<21;i++)
          printf("%f ", bandLogE[21*c+i]);
-//#else
       float sum=0;
       for (i=0;i<21;i++)
          sum += bandLogE[21*c+i];
@@ -303,9 +303,10 @@
    }
    for (i=0;i<21;i++)
       maskLogE[1][i] = MIN32(maskLogE[0][i],maskLogE[2][i]);
+   channel_offset = HALF16(celt_log2(QCONST32(2.f,14)/(channels-1)));
    for (c=0;c<3;c++)
       for (i=0;i<21;i++)
-         maskLogE[c][i] += QCONST16(.5f, DB_SHIFT)*log2(2.f/(channels-1));
+         maskLogE[c][i] += channel_offset;
 #if 0
    for (c=0;c<3;c++)
    {
@@ -334,7 +335,7 @@
       float sum=0;
       for (i=0;i<21;i++)
          sum += bandLogE[21*c+i];
-      printf("%f ", sum/21);
+      printf("%f ", sum/(float)QCONST32(21.f, DB_SHIFT));
       printf("\n");
 #endif
    }