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

Dependents:   NuMidi401 NuFM401

Files at this revision

API Documentation at this revision

Comitter:
kb10uy
Date:
Wed Mar 11 14:35:12 2015 +0000
Parent:
10:5bccb4bc4f33
Commit message:
??

Changed in this revision

AOTTrigon.cpp Show annotated file Show diff for this revision Revisions of this file
AOTTrigon.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5bccb4bc4f33 -r 19594eeb6f2b AOTTrigon.cpp
--- a/AOTTrigon.cpp	Mon Dec 29 08:58:51 2014 +0000
+++ b/AOTTrigon.cpp	Wed Mar 11 14:35:12 2015 +0000
@@ -1,9 +1,2 @@
 #include "AOTTrigon.h"
 
-AOTTrigon::AOTTrigon(): pi(3.14159265358979323846264)
-{
-    rate = 256.0 / (pi * 2.0);
-    t_sin = new double[256];
-    for(int i = 0; i < 256; i++)
-        t_sin[i] = ::sin(i / 256.0 * (pi * 2.0));
-}
diff -r 5bccb4bc4f33 -r 19594eeb6f2b AOTTrigon.h
--- 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