shithub: opus

Download patch

ref: 2ff6556f1fbf93be4f58b3e132859082941890f8
parent: 76674feae22db03848a40446beb2fcec70d2180d
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Thu Aug 11 07:05:51 EDT 2016

Making stereo_itheta() use the same atan2() approximation as tonality_analysis()

--- a/celt/mathops.h
+++ b/celt/mathops.h
@@ -43,6 +43,37 @@
 
 unsigned isqrt32(opus_uint32 _val);
 
+/* CELT doesn't need it for fixed-point, by analysis.c does. */
+#if !defined(FIXED_POINT) || defined(ANALYSIS_C)
+#define cA 0.43157974f
+#define cB 0.67848403f
+#define cC 0.08595542f
+#define cE ((float)M_PI/2)
+static OPUS_INLINE float fast_atan2f(float y, float x) {
+   float x2, y2;
+   x2 = x*x;
+   y2 = y*y;
+   /* For very small values, we don't care about the answer, so
+      we can just return 0. */
+   if (x2 + y2 < 1e-18f)
+   {
+      return 0;
+   }
+   if(x2<y2){
+      float den = (y2 + cB*x2) * (y2 + cC*x2);
+      return -x*y*(y2 + cA*x2) / den + (y<0 ? -cE : cE);
+   }else{
+      float den = (x2 + cB*y2) * (x2 + cC*y2);
+      return  x*y*(x2 + cA*y2) / den + (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE);
+   }
+}
+#undef cA
+#undef cB
+#undef cC
+#undef cD
+#endif
+
+
 #ifndef OVERRIDE_CELT_MAXABS16
 static OPUS_INLINE opus_val32 celt_maxabs16(const opus_val16 *x, int len)
 {
--- a/celt/vq.c
+++ b/celt/vq.c
@@ -426,7 +426,7 @@
    /* 0.63662 = 2/pi */
    itheta = MULT16_16_Q15(QCONST16(0.63662f,15),celt_atan2p(side, mid));
 #else
-   itheta = (int)floor(.5f+16384*0.63662f*atan2(side,mid));
+   itheta = (int)floor(.5f+16384*0.63662f*fast_atan2f(side,mid));
 #endif
 
    return itheta;
--- a/src/analysis.c
+++ b/src/analysis.c
@@ -29,12 +29,16 @@
 #include "config.h"
 #endif
 
+#define ANALYSIS_C
+
+#include <stdio.h>
+
+#include "mathops.h"
 #include "kiss_fft.h"
 #include "celt.h"
 #include "modes.h"
 #include "arch.h"
 #include "quant_bands.h"
-#include <stdio.h>
 #include "analysis.h"
 #include "mlp.h"
 #include "stack_alloc.h"
@@ -109,28 +113,6 @@
 
 #define NB_TONAL_SKIP_BANDS 9
 
-#define cA 0.43157974f
-#define cB 0.67848403f
-#define cC 0.08595542f
-#define cE ((float)M_PI/2)
-static OPUS_INLINE float fast_atan2f(float y, float x) {
-   float x2, y2;
-   x2 = x*x;
-   y2 = y*y;
-   /* For very small values, we don't care about the answer, so
-      we can just return 0. */
-   if (x2 + y2 < 1e-18f)
-   {
-      return 0;
-   }
-   if(x2<y2){
-      float den = (y2 + cB*x2) * (y2 + cC*x2);
-      return -x*y*(y2 + cA*x2) / den + (y<0 ? -cE : cE);
-   }else{
-      float den = (x2 + cB*y2) * (x2 + cC*y2);
-      return  x*y*(x2 + cA*y2) / den + (y<0 ? -cE : cE) - (x*y<0 ? -cE : cE);
-   }
-}
 
 void tonality_analysis_init(TonalityAnalysisState *tonal)
 {