aboutsummaryrefslogtreecommitdiff
path: root/celt
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2016-08-11 11:05:51 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2016-08-11 11:05:51 -0400
commit2ff6556f1fbf93be4f58b3e132859082941890f8 (patch)
tree43094e6ae60aa1d9b14dcc8c9e15173dea3a3dbe /celt
parent76674feae22db03848a40446beb2fcec70d2180d (diff)
downloadlibopus-2ff6556f1fbf93be4f58b3e132859082941890f8.tar.gz
Making stereo_itheta() use the same atan2() approximation as tonality_analysis()
Diffstat (limited to 'celt')
-rw-r--r--celt/mathops.h31
-rw-r--r--celt/vq.c2
2 files changed, 32 insertions, 1 deletions
diff --git a/celt/mathops.h b/celt/mathops.h
index a0525a96..948df655 100644
--- 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)
{
diff --git a/celt/vq.c b/celt/vq.c
index 8d49d804..5a4a8afd 100644
--- a/celt/vq.c
+++ b/celt/vq.c
@@ -426,7 +426,7 @@ int stereo_itheta(const celt_norm *X, const celt_norm *Y, int stereo, int N, int
/* 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;