| @@ -192,29 +192,29 @@ float tWDF_tick(tWDF* const wdf, float sample, tWDF* const outputPoint, uint8_t · 191 unmodified lines |
| 192 | 192 | if (r->child_left != NULL) child = r->child_left; |
| 193 | 193 | else child = r->child_right; |
| 194 | 194 | |
| 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); |
| 197 | 197 | |
| 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; |
| 200 | 200 | |
| 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); |
| 203 | 203 | |
| 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); |
| 206 | 206 | |
| 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); |
| 209 | 209 | |
| 210 | | − //step 5 : grab whatever voltages or currents we want as outputs |
| 210 | + //step 5 : grab whatever voltages or currents we want as outputs |
| 211 | 211 | return tWDF_getVoltage(outputPoint); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | void tWDF_setValue(tWDF* const wdf, float value) |
| 215 | 215 | { |
| 216 | 216 | _tWDF* r = *wdf; |
| 217 | | − r->value = value; |
| 217 | + r->value = value; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | void tWDF_setSampleRate(tWDF* const wdf, float sample_rate) |
| @@ -233,19 +233,19 @@ uint8_t tWDF_isLeaf(tWDF* const wdf) · 12 unmodified lines |
| 233 | 233 | float tWDF_getPortResistance(tWDF* const wdf) |
| 234 | 234 | { |
| 235 | 235 | _tWDF* r = *wdf; |
| 236 | | − return r->get_port_resistance(wdf); |
| 236 | + return r->get_port_resistance(wdf); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | void tWDF_setIncidentWave(tWDF* const wdf, float incident_wave, float input) |
| 240 | 240 | { |
| 241 | 241 | _tWDF* r = *wdf; |
| 242 | | − r->set_incident_wave(wdf, incident_wave, input); |
| 242 | + r->set_incident_wave(wdf, incident_wave, input); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | float tWDF_getReflectedWaveUp(tWDF* const wdf, float input) |
| 246 | 246 | { |
| 247 | 247 | _tWDF* r = *wdf; |
| 248 | | − return r->get_reflected_wave_up(wdf, input); |
| 248 | + return r->get_reflected_wave_up(wdf, input); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | 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 |
| 257 | 257 | float tWDF_getVoltage(tWDF* const wdf) |
| 258 | 258 | { |
| 259 | 259 | _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)); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | float tWDF_getCurrent(tWDF* const wdf) |
| 264 | 264 | { |
| 265 | 265 | _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); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | //============ Static Functions to be Pointed To ==================== |
| @@ -274,20 +274,20 @@ static float get_port_resistance_for_resistor(tWDF* const wdf) · 4 unmodified lines |
| 274 | 274 | { |
| 275 | 275 | _tWDF* r = *wdf; |
| 276 | 276 | |
| 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; |
| 279 | 279 | |
| 280 | | − return r->port_resistance_up; |
| 280 | + return r->port_resistance_up; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | static float get_port_resistance_for_capacitor(tWDF* const wdf) |
| 284 | 284 | { |
| 285 | 285 | _tWDF* r = *wdf; |
| 286 | 286 | |
| 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); |
| 289 | 289 | |
| 290 | | − return r->port_resistance_up; |
| 290 | + return r->port_resistance_up; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | 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 |
| 324 | 324 | { |
| 325 | 325 | _tWDF* r = *wdf; |
| 326 | 326 | |
| 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); |
| 334 | 334 | |
| 335 | | − return r->port_resistance_up; |
| 335 | + return r->port_resistance_up; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | static float get_port_resistance_for_parallel(tWDF* const wdf) |
| 339 | 339 | { |
| 340 | 340 | _tWDF* r = *wdf; |
| 341 | 341 | |
| 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); |
| 349 | 349 | |
| 350 | | − return r->port_resistance_up; |
| 350 | + return r->port_resistance_up; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | 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 |
| 370 | 370 | static void set_incident_wave_for_leaf(tWDF* const wdf, float incident_wave, float input) |
| 371 | 371 | { |
| 372 | 372 | _tWDF* r = *wdf; |
| 373 | | − r->incident_wave_up = incident_wave; |
| 373 | + r->incident_wave_up = incident_wave; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | 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 |
| 391 | 391 | _tWDF* r = *wdf; |
| 392 | 392 | |
| 393 | 393 | 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); |
| 398 | 398 | // downPorts[0]->b = yl * ( downPorts[0]->a * ((1.0 / yl) - 1) - downPorts[1]->a - descendingWave ); |
| 399 | 399 | // 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)); |
| 405 | 405 | |
| 406 | 406 | } |
| 407 | 407 | |
| @@ -410,14 +410,14 @@ static void set_incident_wave_for_parallel(tWDF* const wdf, float incident_wave, · 2 unmodified lines |
| 410 | 410 | _tWDF* r = *wdf; |
| 411 | 411 | |
| 412 | 412 | 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); |
| 417 | 417 | // downPorts[0]->b = ( ( dl - 1 ) * downPorts[0]->a + dr * downPorts[1]->a + du * descendingWave ); |
| 418 | 418 | // 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); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | //=================================================================== |
| @@ -426,15 +426,15 @@ static void set_incident_wave_for_parallel(tWDF* const wdf, float incident_wave, · 2 unmodified lines |
| 426 | 426 | static float get_reflected_wave_for_resistor(tWDF* const wdf, float input) |
| 427 | 427 | { |
| 428 | 428 | _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; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | static float get_reflected_wave_for_capacitor(tWDF* const wdf, float input) |
| 434 | 434 | { |
| 435 | 435 | _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; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | 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 |
| 454 | 454 | static float get_reflected_wave_for_series(tWDF* const wdf, float input) |
| 455 | 455 | { |
| 456 | 456 | _tWDF* r = *wdf; |
| 457 | | − //-( downPorts[0]->a + downPorts[1]->a ); |
| 457 | + //-( downPorts[0]->a + downPorts[1]->a ); |
| 458 | 458 | 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; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | static float get_reflected_wave_for_parallel(tWDF* const wdf, float input) |
| 463 | 463 | { |
| 464 | 464 | _tWDF* r = *wdf; |
| 465 | 465 | |
| 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 ); |
| 469 | 469 | 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; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | 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 |
| 475 | 475 | return (2.0f * input) - incident_wave; |
| 476 | 476 | } |
| 477 | 477 | |
| 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 | | −} |
| 486 | 478 | |
| 487 | 479 | #define wX1 -3.684303659906469f |
| 488 | 480 | #define wX2 1.972967391708859f |
| @@ -514,7 +506,7 @@ static float wrightOmegaApproximation(float x) · 25 unmodified lines |
| 514 | 506 | |
| 515 | 507 | static float lambertW(float a, float r, float I, float iVT) |
| 516 | 508 | { |
| 517 | | − return wrightOmegaApproximation(((a + r*I) * iVT) + log((r * I) * iVT)); |
| 509 | + return wrightOmegaApproximation(((a + r*I) * iVT) + logf((r * I) * iVT)); |
| 518 | 510 | } |
| 519 | 511 | |
| 520 | 512 | #define Is_DIODE 2.52e-9f |