History

added inductor, inverted (both untested) and nonlinear components; single diode seems to work; should maybe not have separate WDF nonlinear class

Matthew Wang committed 7 years ago

Commit 4a5f1861 parent 17938cf3 files · +340 −128Browse files

Unified · Split

3 files
  1. LEAF/Inc/leaf-WDF.h +112 −71
  2. LEAF/Src/leaf-WDF.c +198 −43
  3. LEAF_JUCEPlugin/Source/MyTest.cpp +30 −14
LEAF/Inc/leaf-WDF.h+112−71
@@ -19,9 +19,119 @@ extern "C" { · 18 unmodified lines
19 19
20//==============================================================================20//==============================================================================
21 21
22//---22typedef enum WDFComponentType
23//WDF resistor23{
24 SeriesAdaptor = 0,
25 ParallelAdaptor,
26 Resistor,
27 Capacitor,
28 Inductor,
29 Inverter,
30 ResistiveSource,
31 ComponentNil
32} WDFComponentType;
33
34typedef enum WDFRootType
35{
36 IdealSource = 0,
37 Diode,
38 DiodePair,
39 RootNil
40} WDFRootType;
41
42typedef struct _tWDF tWDF; // needed to allow tWDF pointers in struct
43struct _tWDF
44{
45 WDFComponentType type;
46 float port_resistance_up;
47 float port_resistance_left;
48 float port_resistance_right;
49 float port_conductance_up;
50 float port_conductance_left;
51 float port_conductance_right;
52 float incident_wave_up;
53 float incident_wave_left;
54 float incident_wave_right;
55 float reflected_wave_up;
56 float reflected_wave_left;
57 float reflected_wave_right;
58 float gamma_zero;
59 float sample_rate;
60 float value;
61 tWDF* child_left;
62 tWDF* child_right;
63 tWDF* outpoint;
64 float (*get_port_resistance)(tWDF* const);
65 float (*get_reflected_wave)(tWDF* const);
66 void (*set_incident_wave)(tWDF* const, float);
67};
68
69typedef struct _tWDFNonlinear tWDFNonlinear;
70struct _tWDFNonlinear
71{
72 WDFRootType type;
73 tWDF* child;
74 float (*calculate_reflected_wave)(tWDFNonlinear* const, float, float);
75};
76
77//WDF Linear Components
78void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR);
79float tWDF_tick(tWDF* const r, tWDFNonlinear* const n, float sample, uint8_t paramsChanged);
80
81void tWDF_setValue(tWDF* const r, float value);
82void tWDF_setSampleRate(tWDF* const r, float sample_rate);
83void tWDF_setOutputPoint(tWDF* const r, tWDF* const outpoint);
84uint8_t tWDF_isLeaf(tWDF* const r);
85
86tWDF* tWDF_findOutputPoint(tWDF* const r);
87
88float tWDF_getPortResistance(tWDF* const r);
89float tWDF_getReflectedWave(tWDF* const r);
90void tWDF_setIncidentWave(tWDF* const r, float incident_wave);
24 91
92float tWDF_getVoltage(tWDF* const r);
93float tWDF_getCurrent(tWDF* const r);
94
95static float get_port_resistance_for_resistor(tWDF* const r);
96static float get_port_resistance_for_capacitor(tWDF* const r);
97static float get_port_resistance_for_inductor(tWDF* const r);
98static float get_port_resistance_for_resistive(tWDF* const r);
99static float get_port_resistance_for_inverter(tWDF* const r);
100static float get_port_resistance_for_series(tWDF* const r);
101static float get_port_resistance_for_parallel(tWDF* const r);
102
103static void set_incident_wave_for_leaf(tWDF* const r, float incident_wave);
104static void set_incident_wave_for_leaf_inverted(tWDF* const r, float incident_wave);
105static void set_incident_wave_for_inverter(tWDF* const r, float incident_wave);
106static void set_incident_wave_for_series(tWDF* const r, float incident_wave);
107static void set_incident_wave_for_parallel(tWDF* const r, float incident_wave);
108
109static float get_reflected_wave_for_resistor(tWDF* const r);
110static float get_reflected_wave_for_capacitor(tWDF* const r);
111static float get_reflected_wave_for_resistive(tWDF* const r);
112static float get_reflected_wave_for_inverter(tWDF* const r);
113static float get_reflected_wave_for_series(tWDF* const r);
114static float get_reflected_wave_for_parallel(tWDF* const r);
115
116//WDF Nonlinear Roots
117void tWDFNonlinear_init(tWDFNonlinear* const n, WDFRootType type, tWDF* const child);
118float tWDFNonlinear_calculateReflectedWave(tWDFNonlinear* const n, float input, float incident_wave);
119
120static float calculate_reflected_wave_for_ideal(tWDFNonlinear* const n, float input, float incident_wave);
121static float calculate_reflected_wave_for_diode(tWDFNonlinear* const n, float input, float incident_wave);
122
123
124
125
126
127
128
129
130
131
132
133
134//WDF resistor
25typedef struct _tWDFresistor135typedef struct _tWDFresistor
26{136{
27 float port_resistance;137 float port_resistance;
@@ -111,75 +221,6 @@ float tWDFseriesAdaptor_getReflectedWave(tWDFseriesAdaptor* const r); · 83 unmodified lines
111float tWDFseriesAdaptor_getVoltage(tWDFseriesAdaptor* const r);221float tWDFseriesAdaptor_getVoltage(tWDFseriesAdaptor* const r);
112float tWDFseriesAdaptor_getCurrent(tWDFseriesAdaptor* const r);222float tWDFseriesAdaptor_getCurrent(tWDFseriesAdaptor* const r);
113 223
114//WDF component
115typedef enum WDFComponentType
116{
117 SeriesAdaptor = 0,
118 ParallelAdaptor,
119 Resistor,
120 Capacitor,
121 ResistiveSource,
122 ComponentNil
123} WDFComponentType;
124
125typedef struct _tWDF tWDF; // needed to allow tWDF pointers in struct
126struct _tWDF
127{
128 WDFComponentType type;
129 float port_resistance_up;
130 float port_resistance_left;
131 float port_resistance_right;
132 float port_conductance_up;
133 float port_conductance_left;
134 float port_conductance_right;
135 float incident_wave_up;
136 float incident_wave_left;
137 float incident_wave_right;
138 float reflected_wave_up;
139 float reflected_wave_left;
140 float reflected_wave_right;
141 float gamma_zero;
142 float sample_rate;
143 float value;
144 tWDF* child_left;
145 tWDF* child_right;
146 tWDF* outpoint;
147 float (*get_port_resistance)(tWDF* const);
148 float (*get_reflected_wave)(tWDF* const);
149 void (*set_incident_wave)(tWDF* const, float);
150};
151
152void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR);
153float tWDF_tick(tWDF* const r, float sample, uint8_t paramsChanged);
154
155void tWDF_setValue(tWDF* const r, float value);
156void tWDF_setSampleRate(tWDF* const r, float sample_rate);
157void tWDF_setOutputPoint(tWDF* const r, tWDF* const outpoint);
158uint8_t tWDF_isLeaf(tWDF* const r);
159
160tWDF* tWDF_findOutputPoint(tWDF* const r);
161
162float tWDF_getPortResistance(tWDF* const r);
163float tWDF_getReflectedWave(tWDF* const r);
164void tWDF_setIncidentWave(tWDF* const r, float incident_wave);
165
166float tWDF_getVoltage(tWDF* const r);
167float tWDF_getCurrent(tWDF* const r);
168
169static float get_port_resistance_for_resistor(tWDF* const r);
170static float get_port_resistance_for_capacitor(tWDF* const r);
171static float get_port_resistance_for_series(tWDF* const r);
172static float get_port_resistance_for_parallel(tWDF* const r);
173
174static void set_incident_wave_for_leaf(tWDF* const r, float incident_wave);
175static void set_incident_wave_for_series(tWDF* const r, float incident_wave);
176static void set_incident_wave_for_parallel(tWDF* const r, float incident_wave);
177
178static float get_reflected_wave_for_resistor(tWDF* const r);
179static float get_reflected_wave_for_capacitor(tWDF* const r);
180static float get_reflected_wave_for_series(tWDF* const r);
181static float get_reflected_wave_for_parallel(tWDF* const r);
182
183//==============================================================================224//==============================================================================
184 225
185#ifdef __cplusplus226#ifdef __cplusplus
LEAF/Src/leaf-WDF.c+198−43
@@ -9,7 +9,6 @@ · 8 unmodified lines
9#include "../Inc/leaf-WDF.h"9#include "../Inc/leaf-WDF.h"
10 10
11//WDF11//WDF
12
13void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR)12void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR)
14{13{
15 r->type = type;14 r->type = type;
@@ -24,35 +23,7 @@ void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL · 8 unmodified lines
24 r->reflected_wave_right = 0.0f;23 r->reflected_wave_right = 0.0f;
25 r->sample_rate = leaf.sampleRate;24 r->sample_rate = leaf.sampleRate;
26 r->value = value;25 r->value = value;
27 if (r->type == SeriesAdaptor)26 if (r->type == Resistor)
28 {
29 r->port_resistance_left = tWDF_getPortResistance(rL);
30 r->port_resistance_right = tWDF_getPortResistance(rR);
31 r->port_resistance_up = r->port_resistance_left + r->port_resistance_right;
32 r->port_conductance_up = 1.0f / r->port_resistance_up;
33 r->port_conductance_left = 1.0f / r->port_resistance_left;
34 r->port_conductance_right = 1.0f / r->port_resistance_right;
35 r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
36
37 r->get_port_resistance = &get_port_resistance_for_series;
38 r->get_reflected_wave = &get_reflected_wave_for_series;
39 r->set_incident_wave = &set_incident_wave_for_series;
40 }
41 else if (r->type == ParallelAdaptor)
42 {
43 r->port_resistance_left = tWDF_getPortResistance(rL);
44 r->port_resistance_right = tWDF_getPortResistance(rR);
45 r->port_resistance_up = (r->port_resistance_left * r->port_resistance_right) / (r->port_resistance_left + r->port_resistance_right);
46 r->port_conductance_up = 1.0f / r->port_resistance_up;
47 r->port_conductance_left = 1.0f / r->port_resistance_left;
48 r->port_conductance_right = 1.0f / r->port_resistance_right;
49 r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
50
51 r->get_port_resistance = &get_port_resistance_for_parallel;
52 r->get_reflected_wave = &get_reflected_wave_for_parallel;
53 r->set_incident_wave = &set_incident_wave_for_parallel;
54 }
55 else if (r->type == Resistor)
56 {27 {
57 r->port_resistance_up = r->value;28 r->port_resistance_up = r->value;
58 r->port_conductance_up = 1.0f / r->value;29 r->port_conductance_up = 1.0f / r->value;
@@ -63,20 +34,71 @@ void tWDF_init(tWDF* const r, WDFComponentType type, float value, tWDF* const rL · 4 unmodified lines
63 }34 }
64 else if (r->type == Capacitor)35 else if (r->type == Capacitor)
65 {36 {
66 r->port_resistance_up = 1.0f / (r->sample_rate * 2.0f * r->value); //based on trapezoidal discretization37 r->port_conductance_up = r->sample_rate * 2.0f * r->value;
67 r->port_conductance_up = (1.0f / r->port_resistance_up);38 r->port_resistance_up = 1.0f / r->port_conductance_up; //based on trapezoidal discretization
68 39
69 r->get_port_resistance = &get_port_resistance_for_capacitor;40 r->get_port_resistance = &get_port_resistance_for_capacitor;
70 r->get_reflected_wave = &get_reflected_wave_for_capacitor;41 r->get_reflected_wave = &get_reflected_wave_for_capacitor;
71 r->set_incident_wave = &set_incident_wave_for_leaf;42 r->set_incident_wave = &set_incident_wave_for_leaf;
72 }43 }
44 else if (r->type == Inductor)
45 {
46 r->port_resistance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
47 r->port_conductance_up = 1.0f / r->port_resistance_up;
48
49 r->get_port_resistance = &get_port_resistance_for_inductor;
50 r->get_reflected_wave = &get_reflected_wave_for_capacitor; // same as capacitor
51 r->set_incident_wave = &set_incident_wave_for_leaf_inverted;
52 }
73 else if (r->type == ResistiveSource)53 else if (r->type == ResistiveSource)
74 {54 {
75 55 r->port_resistance_up = 1.0f; // always use 1.0f for resistance
56 r->port_conductance_up = 1.0f / 1.0f;
57 // value is source voltage
58 r->get_port_resistance = &get_port_resistance_for_resistive;
59 r->get_reflected_wave = &get_reflected_wave_for_resistive;
60 r->set_incident_wave = &set_incident_wave_for_leaf;
76 }61 }
77}62 else if (r->type == Inverter)
78 63 {
79float tWDF_tick(tWDF* const r, float sample, uint8_t paramsChanged)64 r->port_resistance_up = tWDF_getPortResistance(r->child_left);
65 r->port_conductance_up = 1.0f / r->port_resistance_up;
66
67 r->get_port_resistance = &get_port_resistance_for_inverter;
68 r->get_reflected_wave = &get_reflected_wave_for_inverter;
69 r->set_incident_wave = &set_incident_wave_for_inverter;
70 }
71 else if (r->type == SeriesAdaptor)
72 {
73 r->port_resistance_left = tWDF_getPortResistance(r->child_left);
74 r->port_resistance_right = tWDF_getPortResistance(r->child_right);
75 r->port_resistance_up = r->port_resistance_left + r->port_resistance_right;
76 r->port_conductance_up = 1.0f / r->port_resistance_up;
77 r->port_conductance_left = 1.0f / r->port_resistance_left;
78 r->port_conductance_right = 1.0f / r->port_resistance_right;
79 r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
80
81 r->get_port_resistance = &get_port_resistance_for_series;
82 r->get_reflected_wave = &get_reflected_wave_for_series;
83 r->set_incident_wave = &set_incident_wave_for_series;
84 }
85 else if (r->type == ParallelAdaptor)
86 {
87 r->port_resistance_left = tWDF_getPortResistance(r->child_left);
88 r->port_resistance_right = tWDF_getPortResistance(r->child_right);
89 r->port_resistance_up = (r->port_resistance_left * r->port_resistance_right) / (r->port_resistance_left + r->port_resistance_right);
90 r->port_conductance_up = 1.0f / r->port_resistance_up;
91 r->port_conductance_left = 1.0f / r->port_resistance_left;
92 r->port_conductance_right = 1.0f / r->port_resistance_right;
93 r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
94
95 r->get_port_resistance = &get_port_resistance_for_parallel;
96 r->get_reflected_wave = &get_reflected_wave_for_parallel;
97 r->set_incident_wave = &set_incident_wave_for_parallel;
98 }
99}
100
101float tWDF_tick(tWDF* const r, tWDFNonlinear* const n, float sample, uint8_t paramsChanged)
80{102{
81 //step 0 : update port resistances if something changed103 //step 0 : update port resistances if something changed
82 if (paramsChanged) tWDF_getPortResistance(r);104 if (paramsChanged) tWDF_getPortResistance(r);
@@ -88,13 +110,13 @@ float tWDF_tick(tWDF* const r, float sample, uint8_t paramsChanged) · 5 unmodified lines
88 float incident_wave = tWDF_getReflectedWave(r);110 float incident_wave = tWDF_getReflectedWave(r);
89 111
90 //step 3 : do root scattering computation112 //step 3 : do root scattering computation
91 float reflected_wave = (2.0f * input) - incident_wave;113 float reflected_wave = tWDFNonlinear_calculateReflectedWave(n, input, incident_wave);
92 114
93 //step 4 : propigate waves down the tree115 //step 4 : propogate waves down the tree
94 tWDF_setIncidentWave(r, reflected_wave);116 tWDF_setIncidentWave(r, reflected_wave);
95 117
96 //step 5 : grab whatever voltages or currents we want as outputs118 //step 5 : grab whatever voltages or currents we want as outputs
97 return -1.0f * tWDF_getVoltage(r->outpoint);119 return reflected_wave*0.5f + incident_wave*0.5f;//tWDF_getVoltage(r->outpoint);
98}120}
99 121
100void tWDF_setValue(tWDF* const r, float value)122void tWDF_setValue(tWDF* const r, float value)
@@ -149,7 +171,10 @@ float tWDF_getCurrent(tWDF* const r) · 48 unmodified lines
149 return (((r->incident_wave_up * 0.5f) - (r->reflected_wave_up * 0.5f)) * r->port_conductance_up);171 return (((r->incident_wave_up * 0.5f) - (r->reflected_wave_up * 0.5f)) * r->port_conductance_up);
150}172}
151 173
152// static functions to be pointed to174//============ Static Functions to be Pointed To ====================
175//===================================================================
176//============ Get and Calculate Port Resistances ===================
177
153static float get_port_resistance_for_resistor(tWDF* const r)178static float get_port_resistance_for_resistor(tWDF* const r)
154{179{
155 r->port_resistance_up = r->value;180 r->port_resistance_up = r->value;
@@ -160,12 +185,33 @@ static float get_port_resistance_for_resistor(tWDF* const r) · 4 unmodified lines
160 185
161static float get_port_resistance_for_capacitor(tWDF* const r)186static float get_port_resistance_for_capacitor(tWDF* const r)
162{187{
163 r->port_resistance_up = 1.0f / (r->sample_rate * 2.0f * r->value); //based on trapezoidal discretization188 r->port_conductance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
164 r->port_conductance_up = (1.0f / r->port_resistance_up);189 r->port_resistance_up = (1.0f / r->port_conductance_up);
165 190
166 return r->port_resistance_up;191 return r->port_resistance_up;
167}192}
168 193
194static float get_port_resistance_for_inductor(tWDF* const r)
195{
196 r->port_resistance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
197 r->port_conductance_up = (1.0f / r->port_resistance_up);
198
199 return r->port_resistance_up;
200}
201
202static float get_port_resistance_for_resistive(tWDF* const r)
203{
204 return r->port_resistance_up;
205}
206
207static float get_port_resistance_for_inverter(tWDF* const r)
208{
209 r->port_resistance_up = tWDF_getPortResistance(r->child_left);
210 r->port_conductance_up = 1.0f / r->port_resistance_up;
211
212 return r->port_resistance_up;
213}
214
169static float get_port_resistance_for_series(tWDF* const r)215static float get_port_resistance_for_series(tWDF* const r)
170{216{
171 r->port_resistance_left = tWDF_getPortResistance(r->child_left);217 r->port_resistance_left = tWDF_getPortResistance(r->child_left);
@@ -192,11 +238,24 @@ static float get_port_resistance_for_parallel(tWDF* const r) · 20 unmodified lines
192 return r->port_resistance_up;238 return r->port_resistance_up;
193}239}
194 240
241//===================================================================
242//================ Set Incident Waves ===============================
243
195static void set_incident_wave_for_leaf(tWDF* const r, float incident_wave)244static void set_incident_wave_for_leaf(tWDF* const r, float incident_wave)
196{245{
197 r->incident_wave_up = incident_wave;246 r->incident_wave_up = incident_wave;
198}247}
199 248
249static void set_incident_wave_for_leaf_inverted(tWDF* const r, float incident_wave)
250{
251 r->incident_wave_up = -1.0f * incident_wave;
252}
253
254static void set_incident_wave_for_inverter(tWDF* const r, float incident_wave)
255{
256 tWDF_setIncidentWave(r->child_left, -1.0f * incident_wave);
257}
258
200static void set_incident_wave_for_series(tWDF* const r, float incident_wave)259static void set_incident_wave_for_series(tWDF* const r, float incident_wave)
201{260{
202 float gamma_left = r->port_resistance_left * r->gamma_zero;261 float gamma_left = r->port_resistance_left * r->gamma_zero;
@@ -225,6 +284,9 @@ static void set_incident_wave_for_parallel(tWDF* const r, float incident_wave) · 22 unmodified lines
225 tWDF_setIncidentWave(r->child_right, gamma_left * left_wave + (gamma_right - 1.0f) * right_wave + incident_wave);284 tWDF_setIncidentWave(r->child_right, gamma_left * left_wave + (gamma_right - 1.0f) * right_wave + incident_wave);
226}285}
227 286
287//===================================================================
288//================ Get Reflected Waves ==============================
289
228static float get_reflected_wave_for_resistor(tWDF* const r)290static float get_reflected_wave_for_resistor(tWDF* const r)
229{291{
230 r->reflected_wave_up = 0.0f;292 r->reflected_wave_up = 0.0f;
@@ -237,6 +299,18 @@ static float get_reflected_wave_for_capacitor(tWDF* const r) · 6 unmodified lines
237 return r->reflected_wave_up;299 return r->reflected_wave_up;
238}300}
239 301
302static float get_reflected_wave_for_resistive(tWDF* const r)
303{
304 r->reflected_wave_up = r->value;
305 return r->reflected_wave_up;
306}
307
308static float get_reflected_wave_for_inverter(tWDF* const r)
309{
310 r->reflected_wave_up = -1.0f * tWDF_getReflectedWave(r->child_left);
311 return r->reflected_wave_up;
312}
313
240static float get_reflected_wave_for_series(tWDF* const r)314static float get_reflected_wave_for_series(tWDF* const r)
241{315{
242 //-( downPorts[0]->a + downPorts[1]->a );316 //-( downPorts[0]->a + downPorts[1]->a );
@@ -251,6 +325,87 @@ static float get_reflected_wave_for_parallel(tWDF* const r) · 8 unmodified lines
251 return (gamma_left * tWDF_getReflectedWave(r->child_left) + gamma_right * tWDF_getReflectedWave(r->child_right));325 return (gamma_left * tWDF_getReflectedWave(r->child_left) + gamma_right * tWDF_getReflectedWave(r->child_right));
252}326}
253 327
328// WDF Nonlinear
329void tWDFNonlinear_init(tWDFNonlinear* const n, WDFRootType type, tWDF* const child)
330{
331 n->type = type;
332 n->child = child;
333 if (n->type == IdealSource)
334 {
335 n->calculate_reflected_wave = &calculate_reflected_wave_for_ideal;
336 }
337 else if (n->type == Diode)
338 {
339 n->calculate_reflected_wave = &calculate_reflected_wave_for_diode;
340 }
341 else if (n->type == DiodePair)
342 {
343 //n->calculate_reflected_wave = &calculate_reflected_wave_for_ideal;
344 }
345}
346
347float tWDFNonlinear_calculateReflectedWave(tWDFNonlinear* const n, float input, float incident_wave)
348{
349 return n->calculate_reflected_wave(n, input, incident_wave);
350}
351
352static float calculate_reflected_wave_for_ideal(tWDFNonlinear* const n, float input, float incident_wave)
353{
354 return (2.0f * input) - incident_wave;
355}
356
357static const float l2A = 0.1640425613334452f;
358static const float l2B = -1.098865286222744f;
359static const float l2Y = 3.148297929334117f;
360static const float l2K = -2.213475204444817f;
361static float log2Approximation(float x)
362{
363 return (l2A * x*x*x) + (l2B * x*x) + (l2Y * x) + l2K;
364}
365
366static const float wX1 = -3.684303659906469f;
367static const float wX2 = 1.972967391708859f;
368static const float wA = 0.009451797158780131f;
369static const float wB = 0.1126446405111627f;
370static const float wY = 0.4451353886588814f;
371static const float wK = 0.5836596684310648f;
372
373static float wrightOmega3(float x)
374{
375 if (x <= wX1)
376 {
377 return 0;
378 }
379 else if (x < wX2)
380 {
381 return (wA * x*x*x) + (wB * x*x) + (wY * x) + wK;
382 }
383 else
384 {
385 return x - logf(x);
386 }
387}
388
389static float wrightOmegaApproximation(float x)
390{
391 float w3 = wrightOmega3(x);
392 return w3 - ((w3 - expf(x - w3)) / (w3 + 1.0f));
393}
394
395static float lambertW(float a, float r, float I, float iVT)
396{
397 return wrightOmegaApproximation(((a + r*I) * iVT) + log((r * I) * iVT));
398}
399
400#define Is_DIODE 2.52e-9
401#define VT_DIODE 0.02585
402static float calculate_reflected_wave_for_diode(tWDFNonlinear* const n, float input, float incident_wave)
403{
404 float a = incident_wave;
405 float r = n->child->port_resistance_up;
406 return a + 2.0f*r*Is_DIODE - 2.0f*VT_DIODE*lambertW(a, r, Is_DIODE, 1.0f/VT_DIODE);
407}
408
254 409
255 410
256 411
LEAF_JUCEPlugin/Source/MyTest.cpp+30−14
@@ -20,11 +20,14 @@ tWDF r1; · 19 unmodified lines
20tWDF r2;20tWDF r2;
21tWDF c1;21tWDF c1;
22tWDF c2;22tWDF c2;
23tWDF rs1;
23tWDF p1;24tWDF p1;
24tWDF s1;25tWDF s1;
25tWDF s2;26tWDF s2;
26 27tWDFNonlinear i;
28tWDFNonlinear d;
27tNoise noise;29tNoise noise;
30tCycle sine;
28 31
29float gain;32float gain;
30bool buttonState;33bool buttonState;
@@ -35,8 +38,11 @@ void LEAFTest_init (float sampleRate, int blockSize) · 4 unmodified lines
35 LEAF_init(sampleRate, blockSize, &getRandomFloat);38 LEAF_init(sampleRate, blockSize, &getRandomFloat);
36 39
37 tNoise_init(&noise, WhiteNoise);40 tNoise_init(&noise, WhiteNoise);
41 tCycle_init(&sine);
42 tCycle_setFreq(&sine, 200);
38 43
39 //Bandpass circuit 144 //Bandpass circuit 1
45 //use c1 for output voltage
40// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);46// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);
41// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL);47// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL);
42// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL);48// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL);
@@ -46,25 +52,35 @@ void LEAFTest_init (float sampleRate, int blockSize) · 3 unmodified lines
46// tWDF_init(&s2, SeriesAdaptor, 0.0f, &s1, &p1);52// tWDF_init(&s2, SeriesAdaptor, 0.0f, &s1, &p1);
47 53
48 //Bandpass circuit 254 //Bandpass circuit 2
55// tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);
56// tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL);
57// tWDF_init(&s1, SeriesAdaptor, 0.0f, &c1, &r1);
58// tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL);
59// tWDF_init(&p1, ParallelAdaptor, 10000.0f, &s1, &r2);
60// tWDF_init(&c2, Capacitor, 0.000000159154943f, NULL, NULL);
61// tWDF_init(&s2, SeriesAdaptor, 0.0f, &c2, &p1);
62
63// tWDF_setOutputPoint(&s2, &c1);
64
65// tWDFNonlinear_init(&i, IdealSource, &s2);
66
49 tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);67 tWDF_init(&r1, Resistor, 10000.0f, NULL, NULL);
50 tWDF_init(&c1, Capacitor, 0.000000159154943f, NULL, NULL);68 tWDF_init(&rs1, ResistiveSource, 0.0f, NULL, NULL);
51 tWDF_init(&s1, SeriesAdaptor, 0.0f, &c1, &r1);69 tWDF_init(&s1, SeriesAdaptor, 0.0f, &r1, &rs1);
52 tWDF_init(&r2, Resistor, 10000.0f, NULL, NULL);
53 tWDF_init(&p1, ParallelAdaptor, 10000.0f, &s1, &r2);
54 tWDF_init(&c2, Capacitor, 0.000000159154943f, NULL, NULL);
55 tWDF_init(&s2, SeriesAdaptor, 0.0f, &c2, &p1);
56
57 70
58 tWDF_setOutputPoint(&s2, &c1);71 tWDF_setOutputPoint(&s1, &r1);
72
73 tWDFNonlinear_init(&d, Diode, &r1);
59 74
60 leaf_pool_report();75 leaf_pool_report();
61}76}
62 77
63float LEAFTest_tick (float input)78float LEAFTest_tick (float input)
64{79{
65 float sample = tNoise_tick(&noise);80 float sample = tCycle_tick(&sine);
66 81
67 sample = tWDF_tick(&s2, sample, 1);82 tWDF_setValue(&rs1, sample*gain);
83 sample = tWDF_tick(&s1, &d, sample, 1);
68 84
69 return sample;85 return sample;
70}86}
@@ -80,9 +96,9 @@ void LEAFTest_block (void) · 9 unmodified lines
80 tWDF_setValue(&r1, val);96 tWDF_setValue(&r1, val);
81 97
82 val = getSliderValue("mod depth");98 val = getSliderValue("mod depth");
83 val = 1.0f + 10000.0f * val;99 val = 10.0f * val;
84 100 gain = val;
85 tWDF_setValue(&r2, val);101 //tWDF_setValue(&r2, val);
86}102}
87 103
88void LEAFTest_controllerInput (int cnum, float cval)104void LEAFTest_controllerInput (int cnum, float cval)

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