AOT計算で呼び出し自体を早くする三角関数

Dependents:   NuMidi401 NuFM401

Revision:
11:19594eeb6f2b
Parent:
10:5bccb4bc4f33
--- a/AOTTrigon.h	Mon Dec 29 08:58:51 2014 +0000
+++ b/AOTTrigon.h	Wed Mar 11 14:35:12 2015 +0000
@@ -8,29 +8,28 @@
 class AOTTrigon
 {
 public:
-    AOTTrigon();
+    AOTTrigon(int c) {
+        pi = 3.14159265358979323846264;
+        rate = 40.743665431525205956834243423364;
+        for(int i = 0; i < 256; i++)
+            t_sin[i] = sin(i / 256.0 * (pi * 2.0));
+    }
 
-    inline double sin(double);
-    inline double cos(double);
-    inline double tan(double);
+    double fsin(double x) {
+        return x * rate;//t_sin[((int)(x * rate)) % 256];
+    }
+
+    double fcos(double x) {
+        return fsin(x + pi / 2.0f);
+    }
+
+    double ftan(double x) {
+        return fsin(x) / fcos(x);
+    }
 
 private:
-    double *t_sin;
+    double t_sin[256];
     double rate;
-    const double pi;
+    double pi;
 };
 
-inline double AOTTrigon::sin(double x)
-{
-    return t_sin[((int)(x * rate)) & 0xFF];
-}
-
-inline double AOTTrigon::cos(double x)
-{
-    return sin(x + pi / 2.0f);
-}
-
-inline double AOTTrigon::tan(double x)
-{
-    return sin(x) / cos(x);
-}
\ No newline at end of file