diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-08-11 11:05:51 -0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-08-11 11:05:51 -0400 |
commit | 2ff6556f1fbf93be4f58b3e132859082941890f8 (patch) | |
tree | 43094e6ae60aa1d9b14dcc8c9e15173dea3a3dbe | |
parent | 76674feae22db03848a40446beb2fcec70d2180d (diff) | |
download | opus-2ff6556f1fbf93be4f58b3e132859082941890f8.tar.gz |
Making stereo_itheta() use the same atan2() approximation as tonality_analysis()
-rw-r--r-- | celt/mathops.h | 31 | ||||
-rw-r--r-- | celt/vq.c | 2 | ||||
-rw-r--r-- | src/analysis.c | 28 |
3 files changed, 37 insertions, 24 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) { @@ -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; diff --git a/src/analysis.c b/src/analysis.c index 056d3771..62b39373 100644 --- 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 @@ static const int extra_bands[NB_TOT_BANDS+1] = { #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) { |