History

First commit.

mulshine committed 7 years ago

Commit 127a1131 parent 824e8d1147 files · +49021 −-7Browse files

Showing the changes to LEAF/Src_cpp/leaf-wavefolder.cpp (1 of 147 files). Show all

Unified · Split

LEAF/Src_cpp/leaf-wavefolder.cpp+115−0
@@ -0,0 +1,115 @@
1+/*
2+ ==============================================================================
3+
4+ leaf-wavefolder.cpp
5+ Created: 30 Nov 2018 11:56:49am
6+ Author: airship
7+
8+ ==============================================================================
9+*/
10+
11+#if _WIN32 || _WIN64
12+
13+#include "..\Inc\leaf-wavefolder.h"
14+
15+#else
16+
17+#include "../Inc/leaf-wavefolder.h"
18+
19+#endif
20+
21+void tLockhartWavefolderInit(tLockhartWavefolder* const w)
22+{
23+ w->Ln1 = 0.0;
24+ w->Fn1 = 0.0;
25+ w->xn1 = 0.0;
26+}
27+
28+double tLockhartWavefolderLambert(double x, double ln)
29+{
30+ double w = ln;
31+ double expw, p, r, s, err, q;
32+
33+ for (int i = 0; i < 1000; i++)
34+ {
35+ //err = x * (logf(x) - logf(w));
36+
37+ /*
38+ r = logf(x / w) - w;
39+ q = 2.0f * (1.0f+w) * (1.0f + w + 0.666666666f*r);
40+ err = (r / (1.0f+w)) * ((q - r) / (q - 2*r));
41+ */
42+ expw = exp(w);
43+
44+ p = (w * expw) - x;
45+ r = (w + 1.0) * expw;
46+ s = (w + 2.0) / (2.0 * (w + 1.0));
47+ err = (p/(r-(p*s)));
48+
49+ if (fabs(err) < THRESH) break;
50+
51+ w -= err;
52+ //w = w * (1 + err);
53+ //w = w - err;
54+ }
55+
56+ return w;
57+}
58+
59+float tLockhartWavefolderTick(tLockhartWavefolder* const w, float samp)
60+{
61+ int l;
62+ double u, Ln, Fn, xn;
63+ float o;
64+
65+ samp=(double)samp;
66+ // Compute Antiderivative
67+ if (samp > 0) l = 1;
68+ else if (samp < 0) l = -1;
69+ else l = 0;
70+
71+ u = LOCKHART_D * exp(l*LOCKHART_B*samp);
72+ Ln = tLockhartWavefolderLambert(u, w->Ln1);
73+ Fn = (0.5 * VT_DIV_B) * (Ln*(Ln + 2.0)) - 0.5*LOCKHART_A*samp*samp;
74+
75+ // Check for ill-conditioning
76+ if (fabs(samp - w->xn1) < ILL_THRESH)
77+ {
78+ // Compute Averaged Wavefolder Output
79+ xn = 0.5*(samp + w->xn1);
80+ u = LOCKHART_D*exp(l*LOCKHART_B*xn);
81+ Ln = tLockhartWavefolderLambert(u, w->Ln1);
82+ o = (float)((l*LOCKHART_VT*Ln) - (LOCKHART_A*xn));
83+ }
84+ else
85+ {
86+ // Apply AA Form
87+ o = (float)((Fn - w->Fn1)/(samp - w->xn1));
88+ }
89+
90+ /*
91+ // Check for ill-conditioning
92+ if (abs(in1-xn1)<thresh) {
93+
94+ // Compute Averaged Wavefolder Output
95+ xn = 0.5*(in1+xn1);
96+ u = d*pow(e,l*b*xn);
97+ Ln = Lambert_W(u,Ln1);
98+ out1 = l*VT*Ln - a*xn;
99+
100+ }
101+ else {
102+
103+ // Apply AA Form
104+ out1 = (Fn-Fn1)/(in1-xn1);
105+
106+ }
107+ */
108+
109+ // Update States
110+ w->Ln1 = Ln;
111+ w->Fn1 = Fn;
112+ w->xn1 = samp;
113+
114+ return o;
115+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t