History

more little tweaks

spiricom committed 6 years ago

Commit 41a57871 parent b6dc19e3 files · +73 −81Browse files

Unified · Split

3 files
  1. leaf/Inc/leaf-analysis.h +6 −6
  2. leaf/Src/leaf-electrical.c +66 −74
  3. leaf/Src/leaf-physical.c +1 −1
leaf/Inc/leaf-analysis.h+6−6
@@ -228,15 +228,15 @@ extern "C" { · 227 unmodified lines
228228 {
229229 tMempool mempool;
230230 float buf[ENV_WINDOW_SIZE + INITVSTAKEN];
231− uint16_t x_phase; /* number of points since last output */
232− uint16_t x_period; /* requested period of output */
233− uint16_t x_realperiod; /* period rounded up to vecsize multiple */
234− uint16_t x_npoints; /* analysis window size in samples */
231+ int x_phase; /* number of points since last output */
232+ int x_period; /* requested period of output */
233+ int x_realperiod; /* period rounded up to vecsize multiple */
234+ int x_npoints; /* analysis window size in samples */
235235 float x_result; /* result to output */
236236 float x_sumbuf[MAXOVERLAP]; /* summing buffer */
237237 float x_f;
238− uint16_t windowSize, hopSize, blockSize;
239− uint16_t x_allocforvs; /* extra buffer for DSP vector size */
238+ int windowSize, hopSize, blockSize;
239+ int x_allocforvs; /* extra buffer for DSP vector size */
240240 } _tEnvPD;
241241
242242 typedef _tEnvPD* tEnvPD;
leaf/Src/leaf-electrical.c+66−74
@@ -192,29 +192,29 @@ float tWDF_tick(tWDF* const wdf, float sample, tWDF* const outputPoint, uint8_t · 191 unmodified lines
192192 if (r->child_left != NULL) child = r->child_left;
193193 else child = r->child_right;
194194
195− //step 0 : update port resistances if something changed
196− if (paramsChanged) tWDF_getPortResistance(wdf);
195+ //step 0 : update port resistances if something changed
196+ if (paramsChanged) tWDF_getPortResistance(wdf);
197197
198− //step 1 : set inputs to what they should be
199− float input = sample;
198+ //step 1 : set inputs to what they should be
199+ float input = sample;
200200
201− //step 2 : scan the waves up the tree
202− r->incident_wave_up = tWDF_getReflectedWaveUp(child, input);
201+ //step 2 : scan the waves up the tree
202+ r->incident_wave_up = tWDF_getReflectedWaveUp(child, input);
203203
204− //step 3 : do root scattering computation
205− r->reflected_wave_up = tWDF_getReflectedWaveDown(wdf, input, r->incident_wave_up);
204+ //step 3 : do root scattering computation
205+ r->reflected_wave_up = tWDF_getReflectedWaveDown(wdf, input, r->incident_wave_up);
206206
207− //step 4 : propogate waves down the tree
208− tWDF_setIncidentWave(child, r->reflected_wave_up, input);
207+ //step 4 : propogate waves down the tree
208+ tWDF_setIncidentWave(child, r->reflected_wave_up, input);
209209
210− //step 5 : grab whatever voltages or currents we want as outputs
210+ //step 5 : grab whatever voltages or currents we want as outputs
211211 return tWDF_getVoltage(outputPoint);
212212 }
213213
214214 void tWDF_setValue(tWDF* const wdf, float value)
215215 {
216216 _tWDF* r = *wdf;
217− r->value = value;
217+ r->value = value;
218218 }
219219
220220 void tWDF_setSampleRate(tWDF* const wdf, float sample_rate)
@@ -233,19 +233,19 @@ uint8_t tWDF_isLeaf(tWDF* const wdf) · 12 unmodified lines
233233 float tWDF_getPortResistance(tWDF* const wdf)
234234 {
235235 _tWDF* r = *wdf;
236− return r->get_port_resistance(wdf);
236+ return r->get_port_resistance(wdf);
237237 }
238238
239239 void tWDF_setIncidentWave(tWDF* const wdf, float incident_wave, float input)
240240 {
241241 _tWDF* r = *wdf;
242− r->set_incident_wave(wdf, incident_wave, input);
242+ r->set_incident_wave(wdf, incident_wave, input);
243243 }
244244
245245 float tWDF_getReflectedWaveUp(tWDF* const wdf, float input)
246246 {
247247 _tWDF* r = *wdf;
248− return r->get_reflected_wave_up(wdf, input);
248+ return r->get_reflected_wave_up(wdf, input);
249249 }
250250
251251 float tWDF_getReflectedWaveDown(tWDF* const wdf, float input, float incident_wave)
@@ -257,13 +257,13 @@ float tWDF_getReflectedWaveDown(tWDF* const wdf, float input, float incident_wav · 5 unmodified lines
257257 float tWDF_getVoltage(tWDF* const wdf)
258258 {
259259 _tWDF* r = *wdf;
260− return ((r->incident_wave_up * 0.5f) + (r->reflected_wave_up * 0.5f));
260+ return ((r->incident_wave_up * 0.5f) + (r->reflected_wave_up * 0.5f));
261261 }
262262
263263 float tWDF_getCurrent(tWDF* const wdf)
264264 {
265265 _tWDF* r = *wdf;
266− return (((r->incident_wave_up * 0.5f) - (r->reflected_wave_up * 0.5f)) * r->port_conductance_up);
266+ return (((r->incident_wave_up * 0.5f) - (r->reflected_wave_up * 0.5f)) * r->port_conductance_up);
267267 }
268268
269269 //============ Static Functions to be Pointed To ====================
@@ -274,20 +274,20 @@ static float get_port_resistance_for_resistor(tWDF* const wdf) · 4 unmodified lines
274274 {
275275 _tWDF* r = *wdf;
276276
277− r->port_resistance_up = r->value;
278− r->port_conductance_up = 1.0f / r->value;
277+ r->port_resistance_up = r->value;
278+ r->port_conductance_up = 1.0f / r->value;
279279
280− return r->port_resistance_up;
280+ return r->port_resistance_up;
281281 }
282282
283283 static float get_port_resistance_for_capacitor(tWDF* const wdf)
284284 {
285285 _tWDF* r = *wdf;
286286
287− r->port_conductance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
288− r->port_resistance_up = (1.0f / r->port_conductance_up);
287+ r->port_conductance_up = r->sample_rate * 2.0f * r->value; //based on trapezoidal discretization
288+ r->port_resistance_up = (1.0f / r->port_conductance_up);
289289
290− return r->port_resistance_up;
290+ return r->port_resistance_up;
291291 }
292292
293293 static float get_port_resistance_for_inductor(tWDF* const wdf)
@@ -324,30 +324,30 @@ static float get_port_resistance_for_series(tWDF* const wdf) · 30 unmodified lines
324324 {
325325 _tWDF* r = *wdf;
326326
327− r->port_resistance_left = tWDF_getPortResistance(r->child_left);
328− r->port_resistance_right = tWDF_getPortResistance(r->child_right);
329− r->port_resistance_up = r->port_resistance_left + r->port_resistance_right;
330− r->port_conductance_up = 1.0f / r->port_resistance_up;
331− r->port_conductance_left = 1.0f / r->port_resistance_left;
332− r->port_conductance_right = 1.0f / r->port_resistance_right;
333− r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
327+ r->port_resistance_left = tWDF_getPortResistance(r->child_left);
328+ r->port_resistance_right = tWDF_getPortResistance(r->child_right);
329+ r->port_resistance_up = r->port_resistance_left + r->port_resistance_right;
330+ r->port_conductance_up = 1.0f / r->port_resistance_up;
331+ r->port_conductance_left = 1.0f / r->port_resistance_left;
332+ r->port_conductance_right = 1.0f / r->port_resistance_right;
333+ r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
334334
335− return r->port_resistance_up;
335+ return r->port_resistance_up;
336336 }
337337
338338 static float get_port_resistance_for_parallel(tWDF* const wdf)
339339 {
340340 _tWDF* r = *wdf;
341341
342− r->port_resistance_left = tWDF_getPortResistance(r->child_left);
343− r->port_resistance_right = tWDF_getPortResistance(r->child_right);
344− r->port_resistance_up = (r->port_resistance_left * r->port_resistance_right) / (r->port_resistance_left + r->port_resistance_right);
345− r->port_conductance_up = 1.0f / r->port_resistance_up;
346− r->port_conductance_left = 1.0f / r->port_resistance_left;
347− r->port_conductance_right = 1.0f / r->port_resistance_right;
348− r->gamma_zero = 1.0f / (r->port_conductance_right + r->port_conductance_left);
342+ r->port_resistance_left = tWDF_getPortResistance(r->child_left);
343+ r->port_resistance_right = tWDF_getPortResistance(r->child_right);
344+ r->port_resistance_up = (r->port_resistance_left * r->port_resistance_right) / (r->port_resistance_left + r->port_resistance_right);
345+ r->port_conductance_up = 1.0f / r->port_resistance_up;
346+ r->port_conductance_left = 1.0f / r->port_resistance_left;
347+ r->port_conductance_right = 1.0f / r->port_resistance_right;
348+ r->gamma_zero = 1.0f / (r->port_conductance_right + r->port_conductance_left);
349349
350− return r->port_resistance_up;
350+ return r->port_resistance_up;
351351 }
352352
353353 static float get_port_resistance_for_root(tWDF* const wdf)
@@ -370,7 +370,7 @@ static float get_port_resistance_for_root(tWDF* const wdf) · 16 unmodified lines
370370 static void set_incident_wave_for_leaf(tWDF* const wdf, float incident_wave, float input)
371371 {
372372 _tWDF* r = *wdf;
373− r->incident_wave_up = incident_wave;
373+ r->incident_wave_up = incident_wave;
374374 }
375375
376376 static void set_incident_wave_for_leaf_inverted(tWDF* const wdf, float incident_wave, float input)
@@ -391,17 +391,17 @@ static void set_incident_wave_for_series(tWDF* const wdf, float incident_wave, f · 14 unmodified lines
391391 _tWDF* r = *wdf;
392392
393393 r->incident_wave_up = incident_wave;
394− float gamma_left = r->port_resistance_left * r->gamma_zero;
395− float gamma_right = r->port_resistance_right * r->gamma_zero;
396− float left_wave = tWDF_getReflectedWaveUp(r->child_left, input);
397− float right_wave = tWDF_getReflectedWaveUp(r->child_right, input);
394+ float gamma_left = r->port_resistance_left * r->gamma_zero;
395+ float gamma_right = r->port_resistance_right * r->gamma_zero;
396+ float left_wave = tWDF_getReflectedWaveUp(r->child_left, input);
397+ float right_wave = tWDF_getReflectedWaveUp(r->child_right, input);
398398 // downPorts[0]->b = yl * ( downPorts[0]->a * ((1.0 / yl) - 1) - downPorts[1]->a - descendingWave );
399399 // downPorts[1]->b = yr * ( downPorts[1]->a * ((1.0 / yr) - 1) - downPorts[0]->a - descendingWave );
400− tWDF_setIncidentWave(r->child_left, (-1.0f * gamma_left * incident_wave) + (gamma_right * left_wave) - (gamma_left * right_wave), input);
401− tWDF_setIncidentWave(r->child_right, (-1.0f * gamma_right * incident_wave) + (gamma_left * right_wave) - (gamma_right * left_wave), input);
402− // From rt-wdf
403−// tWDF_setIncidentWave(r->child_left, gamma_left * (left_wave * ((1.0f / gamma_left) - 1.0f) - right_wave - incident_wave));
404−// tWDF_setIncidentWave(r->child_right, gamma_right * (right_wave * ((1.0f / gamma_right) - 1.0f) - left_wave - incident_wave));
400+ tWDF_setIncidentWave(r->child_left, (-1.0f * gamma_left * incident_wave) + (gamma_right * left_wave) - (gamma_left * right_wave), input);
401+ tWDF_setIncidentWave(r->child_right, (-1.0f * gamma_right * incident_wave) + (gamma_left * right_wave) - (gamma_right * left_wave), input);
402+ // From rt-wdf
403+// tWDF_setIncidentWave(r->child_left, gamma_left * (left_wave * ((1.0f / gamma_left) - 1.0f) - right_wave - incident_wave));
404+// tWDF_setIncidentWave(r->child_right, gamma_right * (right_wave * ((1.0f / gamma_right) - 1.0f) - left_wave - incident_wave));
405405
406406 }
407407
@@ -410,14 +410,14 @@ static void set_incident_wave_for_parallel(tWDF* const wdf, float incident_wave, · 2 unmodified lines
410410 _tWDF* r = *wdf;
411411
412412 r->incident_wave_up = incident_wave;
413− float gamma_left = r->port_conductance_left * r->gamma_zero;
414− float gamma_right = r->port_conductance_right * r->gamma_zero;
415− float left_wave = tWDF_getReflectedWaveUp(r->child_left, input);
416− float right_wave = tWDF_getReflectedWaveUp(r->child_right, input);
413+ float gamma_left = r->port_conductance_left * r->gamma_zero;
414+ float gamma_right = r->port_conductance_right * r->gamma_zero;
415+ float left_wave = tWDF_getReflectedWaveUp(r->child_left, input);
416+ float right_wave = tWDF_getReflectedWaveUp(r->child_right, input);
417417 // downPorts[0]->b = ( ( dl - 1 ) * downPorts[0]->a + dr * downPorts[1]->a + du * descendingWave );
418418 // downPorts[1]->b = ( dl * downPorts[0]->a + ( dr - 1 ) * downPorts[1]->a + du * descendingWave );
419− tWDF_setIncidentWave(r->child_left, (gamma_left - 1.0f) * left_wave + gamma_right * right_wave + incident_wave, input);
420− tWDF_setIncidentWave(r->child_right, gamma_left * left_wave + (gamma_right - 1.0f) * right_wave + incident_wave, input);
419+ tWDF_setIncidentWave(r->child_left, (gamma_left - 1.0f) * left_wave + gamma_right * right_wave + incident_wave, input);
420+ tWDF_setIncidentWave(r->child_right, gamma_left * left_wave + (gamma_right - 1.0f) * right_wave + incident_wave, input);
421421 }
422422
423423 //===================================================================
@@ -426,15 +426,15 @@ static void set_incident_wave_for_parallel(tWDF* const wdf, float incident_wave, · 2 unmodified lines
426426 static float get_reflected_wave_for_resistor(tWDF* const wdf, float input)
427427 {
428428 _tWDF* r = *wdf;
429− r->reflected_wave_up = 0.0f;
430− return r->reflected_wave_up;
429+ r->reflected_wave_up = 0.0f;
430+ return r->reflected_wave_up;
431431 }
432432
433433 static float get_reflected_wave_for_capacitor(tWDF* const wdf, float input)
434434 {
435435 _tWDF* r = *wdf;
436− r->reflected_wave_up = r->incident_wave_up;
437− return r->reflected_wave_up;
436+ r->reflected_wave_up = r->incident_wave_up;
437+ return r->reflected_wave_up;
438438 }
439439
440440 static float get_reflected_wave_for_resistive(tWDF* const wdf, float input)
@@ -454,20 +454,20 @@ static float get_reflected_wave_for_inverter(tWDF* const wdf, float input) · 13 unmodified lines
454454 static float get_reflected_wave_for_series(tWDF* const wdf, float input)
455455 {
456456 _tWDF* r = *wdf;
457− //-( downPorts[0]->a + downPorts[1]->a );
457+ //-( downPorts[0]->a + downPorts[1]->a );
458458 r->reflected_wave_up = (-1.0f * (tWDF_getReflectedWaveUp(r->child_left, input) + tWDF_getReflectedWaveUp(r->child_right, input)));
459− return r->reflected_wave_up;
459+ return r->reflected_wave_up;
460460 }
461461
462462 static float get_reflected_wave_for_parallel(tWDF* const wdf, float input)
463463 {
464464 _tWDF* r = *wdf;
465465
466− float gamma_left = r->port_conductance_left * r->gamma_zero;
467− float gamma_right = r->port_conductance_right * r->gamma_zero;
468− //return ( dl * downPorts[0]->a + dr * downPorts[1]->a );
466+ float gamma_left = r->port_conductance_left * r->gamma_zero;
467+ float gamma_right = r->port_conductance_right * r->gamma_zero;
468+ //return ( dl * downPorts[0]->a + dr * downPorts[1]->a );
469469 r->reflected_wave_up = (gamma_left * tWDF_getReflectedWaveUp(r->child_left, input) + gamma_right * tWDF_getReflectedWaveUp(r->child_right, input));
470− return r->reflected_wave_up;
470+ return r->reflected_wave_up;
471471 }
472472
473473 static float get_reflected_wave_for_ideal(tWDF* const wdf, float input, float incident_wave)
@@ -475,14 +475,6 @@ static float get_reflected_wave_for_ideal(tWDF* const wdf, float input, float in · 1 unmodified line
475475 return (2.0f * input) - incident_wave;
476476 }
477477
478−#define l2A 0.1640425613334452f
479−#define l2B -1.098865286222744f
480−#define l2Y 3.148297929334117f
481−#define l2K -2.213475204444817f
482−static float log2Approximation(float x)
483−{
484− return (l2A * x*x*x) + (l2B * x*x) + (l2Y * x) + l2K;
485−}
486478
487479 #define wX1 -3.684303659906469f
488480 #define wX2 1.972967391708859f
@@ -514,7 +506,7 @@ static float wrightOmegaApproximation(float x) · 25 unmodified lines
514506
515507 static float lambertW(float a, float r, float I, float iVT)
516508 {
517− return wrightOmegaApproximation(((a + r*I) * iVT) + log((r * I) * iVT));
509+ return wrightOmegaApproximation(((a + r*I) * iVT) + logf((r * I) * iVT));
518510 }
519511
520512 #define Is_DIODE 2.52e-9f
leaf/Src/leaf-physical.c+1−1
@@ -288,7 +288,7 @@ void tKarplusStrong_setStretch (tKarplusStrong* const pl, float stret · 287 unmodified lines
288288 tBiQuad_setB0(&p->biquad[i], coefficient);
289289 tBiQuad_setB2(&p->biquad[i], 1.0f);
290290
291− coefficient = -2.0f * temp * cos(TWO_PI * freq / leaf.sampleRate);
291+ coefficient = -2.0f * temp * cosf(TWO_PI * freq / leaf.sampleRate);
292292 tBiQuad_setA1(&p->biquad[i], coefficient);
293293 tBiQuad_setB1(&p->biquad[i], coefficient);
294294

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