| @@ -30,7 +30,15 @@ extern "C" { · 29 unmodified lines |
| 30 | | 30 | |
| 31 | //============================================================================== | 31 | //============================================================================== |
| 32 | | 32 | |
| 33 | /* tAllpass: Schroeder allpass. Comb-filter with feedforward and feedback. */ | 33 | /*! |
| | 34 | @defgroup tallpass tAllpass |
| | 35 | @ingroup filters |
| | 36 | @brief Schroeder allpass. Comb-filter with feedforward and feedback. |
| | 37 | @{ |
| | 38 | */ |
| | 39 | |
| | 40 | /*! @} */ |
| | 41 | |
| 34 | typedef struct _tAllpass | 42 | typedef struct _tAllpass |
| 35 | { | 43 | { |
| 36 | tMempool mempool; | 44 | tMempool mempool; |
| @@ -55,7 +63,15 @@ extern "C" { · 18 unmodified lines |
| 55 | | 63 | |
| 56 | //============================================================================== | 64 | //============================================================================== |
| 57 | | 65 | |
| 58 | /* tOnePole: OnePole filter, reimplemented from STK (Cook and Scavone). */ | 66 | /*! |
| | 67 | @defgroup tonepole tOnePole |
| | 68 | @ingroup filters |
| | 69 | @brief OnePole filter, reimplemented from STK (Cook and Scavone). |
| | 70 | @{ |
| | 71 | */ |
| | 72 | |
| | 73 | /*! @} */ |
| | 74 | |
| 59 | typedef struct _tOnePole | 75 | typedef struct _tOnePole |
| 60 | { | 76 | { |
| 61 | tMempool mempool; | 77 | tMempool mempool; |
| @@ -81,7 +97,15 @@ extern "C" { · 19 unmodified lines |
| 81 | | 97 | |
| 82 | //============================================================================== | 98 | //============================================================================== |
| 83 | | 99 | |
| 84 | /* TwoPole filter, reimplemented from STK (Cook and Scavone). */ | 100 | /*! |
| | 101 | @defgroup ttwopole tTwoPole |
| | 102 | @ingroup filters |
| | 103 | @brief TwoPole filter, reimplemented from STK (Cook and Scavone). |
| | 104 | @{ |
| | 105 | */ |
| | 106 | |
| | 107 | /*! @} */ |
| | 108 | |
| 85 | typedef struct _tTwoPole | 109 | typedef struct _tTwoPole |
| 86 | { | 110 | { |
| 87 | tMempool mempool; | 111 | tMempool mempool; |
| @@ -92,7 +116,7 @@ extern "C" { · 4 unmodified lines |
| 92 | | 116 | |
| 93 | float radius, frequency; | 117 | float radius, frequency; |
| 94 | oBool normalize; | 118 | oBool normalize; |
| 95 | | 119 | |
| 96 | float lastOut[2]; | 120 | float lastOut[2]; |
| 97 | } _tTwoPole; | 121 | } _tTwoPole; |
| 98 | | 122 | |
| @@ -112,7 +136,15 @@ extern "C" { · 13 unmodified lines |
| 112 | | 136 | |
| 113 | //============================================================================== | 137 | //============================================================================== |
| 114 | | 138 | |
| 115 | /* OneZero filter, reimplemented from STK (Cook and Scavone). */ | 139 | /*! |
| | 140 | @defgroup tonezero tOneZero |
| | 141 | @ingroup filters |
| | 142 | @brief OneZero filter, reimplemented from STK (Cook and Scavone). |
| | 143 | @{ |
| | 144 | */ |
| | 145 | |
| | 146 | /*! @} */ |
| | 147 | |
| 116 | typedef struct _tOneZero | 148 | typedef struct _tOneZero |
| 117 | { | 149 | { |
| 118 | tMempool mempool; | 150 | tMempool mempool; |
| @@ -137,7 +169,15 @@ extern "C" { · 18 unmodified lines |
| 137 | | 169 | |
| 138 | //============================================================================== | 170 | //============================================================================== |
| 139 | | 171 | |
| 140 | /* TwoZero filter, reimplemented from STK (Cook and Scavone). */ | 172 | /*! |
| | 173 | @defgroup ttwozero tTwoZero |
| | 174 | @ingroup filters |
| | 175 | @brief TwoZero filter, reimplemented from STK (Cook and Scavone). |
| | 176 | @{ |
| | 177 | */ |
| | 178 | |
| | 179 | /*! @} */ |
| | 180 | |
| 141 | typedef struct _tTwoZero | 181 | typedef struct _tTwoZero |
| 142 | { | 182 | { |
| 143 | tMempool mempool; | 183 | tMempool mempool; |
| @@ -166,7 +206,15 @@ extern "C" { · 22 unmodified lines |
| 166 | | 206 | |
| 167 | //============================================================================== | 207 | //============================================================================== |
| 168 | | 208 | |
| 169 | /* PoleZero filter, reimplemented from STK (Cook and Scavone). */ | 209 | /*! |
| | 210 | @defgroup tpolezero tPoleZero |
| | 211 | @ingroup filters |
| | 212 | @brief PoleZero filter, reimplemented from STK (Cook and Scavone). |
| | 213 | @{ |
| | 214 | */ |
| | 215 | |
| | 216 | /*! @} */ |
| | 217 | |
| 170 | typedef struct _tPoleZero | 218 | typedef struct _tPoleZero |
| 171 | { | 219 | { |
| 172 | tMempool mempool; | 220 | tMempool mempool; |
| @@ -195,7 +243,15 @@ extern "C" { · 22 unmodified lines |
| 195 | | 243 | |
| 196 | //============================================================================== | 244 | //============================================================================== |
| 197 | | 245 | |
| 198 | /* BiQuad filter, reimplemented from STK (Cook and Scavone). */ | 246 | /*! |
| | 247 | @defgroup tbiquad tBiQuad |
| | 248 | @ingroup filters |
| | 249 | @brief BiQuad filter, reimplemented from STK (Cook and Scavone). |
| | 250 | @{ |
| | 251 | */ |
| | 252 | |
| | 253 | /*! @} */ |
| | 254 | |
| 199 | typedef struct _tBiQuad | 255 | typedef struct _tBiQuad |
| 200 | { | 256 | { |
| 201 | tMempool mempool; | 257 | tMempool mempool; |
| @@ -230,7 +286,15 @@ extern "C" { · 28 unmodified lines |
| 230 | | 286 | |
| 231 | //============================================================================== | 287 | //============================================================================== |
| 232 | | 288 | |
| 233 | /* State Variable Filter, algorithm from Andy Simper. */ | 289 | /*! |
| | 290 | @defgroup tsvf tSVF |
| | 291 | @ingroup filters |
| | 292 | @brief State Variable Filter, algorithm from Andy Simper. |
| | 293 | @{ |
| | 294 | */ |
| | 295 | |
| | 296 | /*! @} */ |
| | 297 | |
| 234 | typedef enum SVFType | 298 | typedef enum SVFType |
| 235 | { | 299 | { |
| 236 | SVFTypeHighpass = 0, | 300 | SVFTypeHighpass = 0, |
| @@ -263,7 +327,15 @@ extern "C" { · 26 unmodified lines |
| 263 | void tSVF_setFreqAndQ (tSVF* const svff, float freq, float Q); | 327 | void tSVF_setFreqAndQ (tSVF* const svff, float freq, float Q); |
| 264 | //============================================================================== | 328 | //============================================================================== |
| 265 | | 329 | |
| 266 | /* Efficient State Variable Filter for 14-bit control input, [0, 4096). */ | 330 | /*! |
| | 331 | @defgroup tefficientsvf tEfficientSVF |
| | 332 | @ingroup filters |
| | 333 | @brief Efficient State Variable Filter for 14-bit control input, [0, 4096). |
| | 334 | @{ |
| | 335 | */ |
| | 336 | |
| | 337 | /*! @} */ |
| | 338 | |
| 267 | typedef struct _tEfficientSVF | 339 | typedef struct _tEfficientSVF |
| 268 | { | 340 | { |
| 269 | tMempool mempool; | 341 | tMempool mempool; |
| @@ -285,7 +357,15 @@ extern "C" { · 15 unmodified lines |
| 285 | | 357 | |
| 286 | //============================================================================== | 358 | //============================================================================== |
| 287 | | 359 | |
| 288 | /* Simple Highpass filter. */ | 360 | /*! |
| | 361 | @defgroup thighpass tHighpass |
| | 362 | @ingroup filters |
| | 363 | @brief Simple Highpass filter. |
| | 364 | @{ |
| | 365 | */ |
| | 366 | |
| | 367 | /*! @} */ |
| | 368 | |
| 289 | typedef struct _tHighpass | 369 | typedef struct _tHighpass |
| 290 | { | 370 | { |
| 291 | tMempool mempool; | 371 | tMempool mempool; |
| @@ -305,7 +385,15 @@ extern "C" { · 13 unmodified lines |
| 305 | | 385 | |
| 306 | //============================================================================== | 386 | //============================================================================== |
| 307 | | 387 | |
| 308 | // Butterworth Filter | 388 | /*! |
| | 389 | @defgroup tbutterworth tButterworth |
| | 390 | @ingroup filters |
| | 391 | @brief |
| | 392 | @{ |
| | 393 | */ |
| | 394 | |
| | 395 | /*! @} */ |
| | 396 | |
| 309 | #define NUM_SVF_BW 16 | 397 | #define NUM_SVF_BW 16 |
| 310 | typedef struct _tButterworth | 398 | typedef struct _tButterworth |
| 311 | { | 399 | { |
| @@ -334,6 +422,15 @@ extern "C" { · 22 unmodified lines |
| 334 | | 422 | |
| 335 | //============================================================================== | 423 | //============================================================================== |
| 336 | | 424 | |
| | 425 | /*! |
| | 426 | @defgroup tfir tFIR |
| | 427 | @ingroup filters |
| | 428 | @brief |
| | 429 | @{ |
| | 430 | */ |
| | 431 | |
| | 432 | /*! @} */ |
| | 433 | |
| 337 | typedef struct _tFIR | 434 | typedef struct _tFIR |
| 338 | { | 435 | { |
| 339 | tMempool mempool; | 436 | tMempool mempool; |
| @@ -349,125 +446,146 @@ extern "C" { · 9 unmodified lines |
| 349 | void tFIR_free (tFIR* const); | 446 | void tFIR_free (tFIR* const); |
| 350 | | 447 | |
| 351 | float tFIR_tick (tFIR* const, float input); | 448 | float tFIR_tick (tFIR* const, float input); |
| 352 | | 449 | |
| 353 | | 450 | |
| 354 | //============================================================================== | 451 | //============================================================================== |
| 355 | | 452 | |
| 356 | | 453 | /*! |
| | 454 | @defgroup tmedianfilter tMedianFilter |
| | 455 | @ingroup filters |
| | 456 | @brief |
| | 457 | @{ |
| | 458 | */ |
| | 459 | |
| | 460 | /*! @} */ |
| | 461 | |
| 357 | typedef struct _tMedianFilter | 462 | typedef struct _tMedianFilter |
| 358 | { | 463 | { |
| 359 | tMempool mempool; | 464 | tMempool mempool; |
| 360 | float* val; | 465 | float* val; |
| 361 | int* age; | 466 | int* age; |
| 362 | int m; | 467 | int m; |
| 363 | int size; | 468 | int size; |
| 364 | int middlePosition; | 469 | int middlePosition; |
| 365 | int last; | 470 | int last; |
| 366 | int pos; | 471 | int pos; |
| 367 | } _tMedianFilter; | 472 | } _tMedianFilter; |
| 368 | | 473 | |
| 369 | typedef _tMedianFilter* tMedianFilter; | 474 | typedef _tMedianFilter* tMedianFilter; |
| 370 | | 475 | |
| 371 | void tMedianFilter_init (tMedianFilter* const, int size); | 476 | void tMedianFilter_init (tMedianFilter* const, int size); |
| 372 | void tMedianFilter_initToPool (tMedianFilter* const, int size, tMempool* const); | 477 | void tMedianFilter_initToPool (tMedianFilter* const, int size, tMempool* const); |
| 373 | void tMedianFilter_free (tMedianFilter* const); | 478 | void tMedianFilter_free (tMedianFilter* const); |
| 374 | | 479 | |
| 375 | float tMedianFilter_tick (tMedianFilter* const, float input); | 480 | float tMedianFilter_tick (tMedianFilter* const, float input); |
| 376 | | 481 | |
| 377 | | 482 | |
| 378 | | 483 | /*! |
| 379 | | 484 | @defgroup tvzfilter tVZFilter |
| 380 | | 485 | @ingroup filters |
| 381 | //Vadim Zavalishin style from VA book (from implementation in RSlib posted to kvr forum) | 486 | @brief |
| 382 | | 487 | @{ |
| | 488 | */ |
| | 489 | |
| | 490 | /*! @} */ |
| | 491 | |
| | 492 | //Vadim Zavalishin style from VA book (from implementation in RSlib posted to kvr forum) |
| | 493 | |
| 383 | typedef enum VZFilterType | 494 | typedef enum VZFilterType |
| 384 | { | 495 | { |
| 385 | Highpass = 0, | 496 | Highpass = 0, |
| 386 | Lowpass, | 497 | Lowpass, |
| 387 | BandpassSkirt, | 498 | BandpassSkirt, |
| 388 | BandpassPeak, | 499 | BandpassPeak, |
| 389 | BandReject, | 500 | BandReject, |
| 390 | Bell, | 501 | Bell, |
| 391 | Lowshelf, | 502 | Lowshelf, |
| 392 | Highshelf, | 503 | Highshelf, |
| 393 | Morph, | 504 | Morph, |
| 394 | Bypass, | 505 | Bypass, |
| 395 | Allpass | 506 | Allpass |
| 396 | } VZFilterType; | 507 | } VZFilterType; |
| 397 | | 508 | |
| 398 | | 509 | |
| 399 | typedef struct _tVZFilter | 510 | typedef struct _tVZFilter |
| 400 | { | 511 | { |
| 401 | tMempool mempool; | 512 | tMempool mempool; |
| 402 | | 513 | |
| 403 | VZFilterType type; | 514 | VZFilterType type; |
| 404 | // state: | 515 | // state: |
| 405 | float s1, s2; | 516 | float s1, s2; |
| 406 | | 517 | |
| 407 | // filter coefficients: | 518 | // filter coefficients: |
| 408 | float g; // embedded integrator gain | 519 | float g; // embedded integrator gain |
| 409 | float R2; // twice the damping coefficient (R2 == 2*R == 1/Q) | 520 | float R2; // twice the damping coefficient (R2 == 2*R == 1/Q) |
| 410 | float h; // factor for feedback (== 1/(1+2*R*g+g*g)) | 521 | float h; // factor for feedback (== 1/(1+2*R*g+g*g)) |
| 411 | float cL, cB, cH; // coefficients for low-, band-, and highpass signals | 522 | float cL, cB, cH; // coefficients for low-, band-, and highpass signals |
| 412 | | 523 | |
| 413 | // parameters: | 524 | // parameters: |
| 414 | float fc; // characteristic frequency | 525 | float fc; // characteristic frequency |
| 415 | float G; // gain | 526 | float G; // gain |
| 416 | float invG; //1/gain | 527 | float invG; //1/gain |
| 417 | float B; // bandwidth (in octaves) | 528 | float B; // bandwidth (in octaves) |
| 418 | float m; // morph parameter (0...1) | 529 | float m; // morph parameter (0...1) |
| 419 | | 530 | |
| 420 | float sr; //local sampling rate of filter (may be different from leaf sr if oversampled) | 531 | float sr; //local sampling rate of filter (may be different from leaf sr if oversampled) |
| 421 | float inv_sr; | 532 | float inv_sr; |
| 422 | } _tVZFilter; | 533 | } _tVZFilter; |
| 423 | | 534 | |
| 424 | typedef _tVZFilter* tVZFilter; | 535 | typedef _tVZFilter* tVZFilter; |
| 425 | | 536 | |
| 426 | void tVZFilter_init (tVZFilter* const, VZFilterType type, float freq, float Q); | 537 | void tVZFilter_init (tVZFilter* const, VZFilterType type, float freq, float Q); |
| 427 | void tVZFilter_initToPool (tVZFilter* const, VZFilterType type, float freq, float Q, tMempool* const); | 538 | void tVZFilter_initToPool (tVZFilter* const, VZFilterType type, float freq, float Q, tMempool* const); |
| 428 | void tVZFilter_free (tVZFilter* const); | 539 | void tVZFilter_free (tVZFilter* const); |
| 429 | | 540 | |
| 430 | void tVZFilter_setSampleRate (tVZFilter* const, float sampleRate); | 541 | void tVZFilter_setSampleRate (tVZFilter* const, float sampleRate); |
| 431 | float tVZFilter_tick (tVZFilter* const, float input); | 542 | float tVZFilter_tick (tVZFilter* const, float input); |
| 432 | float tVZFilter_tickEfficient (tVZFilter* const vf, float in); | 543 | float tVZFilter_tickEfficient (tVZFilter* const vf, float in); |
| 433 | void tVZFilter_calcCoeffs (tVZFilter* const); | 544 | void tVZFilter_calcCoeffs (tVZFilter* const); |
| 434 | void tVZFilter_setBandwidth (tVZFilter* const, float bandWidth); | 545 | void tVZFilter_setBandwidth (tVZFilter* const, float bandWidth); |
| 435 | void tVZFilter_setFreq (tVZFilter* const, float freq); | 546 | void tVZFilter_setFreq (tVZFilter* const, float freq); |
| 436 | void tVZFilter_setFreqAndBandwidth (tVZFilter* const vf, float freq, float bw); | 547 | void tVZFilter_setFreqAndBandwidth (tVZFilter* const vf, float freq, float bw); |
| 437 | void tVZFilter_setGain (tVZFilter* const, float gain); | 548 | void tVZFilter_setGain (tVZFilter* const, float gain); |
| 438 | void tVZFilter_setType (tVZFilter* const, VZFilterType type); | 549 | void tVZFilter_setType (tVZFilter* const, VZFilterType type); |
| 439 | float tVZFilter_BandwidthToR (tVZFilter* const vf, float B); | 550 | float tVZFilter_BandwidthToR (tVZFilter* const vf, float B); |
| 440 | | 551 | |
| 441 | | 552 | |
| 442 | | 553 | /*! |
| 443 | | 554 | @defgroup tdiodefilter tDiodeFilter |
| 444 | //diode ladder filter | 555 | @ingroup filters |
| 445 | typedef struct _tDiodeFilter | 556 | @brief |
| 446 | { | 557 | @{ |
| 447 | tMempool mempool; | 558 | */ |
| 448 | float f; | 559 | |
| 449 | float r; | 560 | /*! @} */ |
| 450 | float Vt; | 561 | |
| 451 | float n; | 562 | //diode ladder filter |
| 452 | float gamma; | 563 | typedef struct _tDiodeFilter |
| 453 | float zi; | 564 | { |
| 454 | float g0inv; | 565 | tMempool mempool; |
| 455 | float g1inv; | 566 | float f; |
| 456 | float g2inv; | 567 | float r; |
| 457 | float s0, s1, s2, s3; | 568 | float Vt; |
| 458 | } _tDiodeFilter; | 569 | float n; |
| 459 | | 570 | float gamma; |
| 460 | typedef _tDiodeFilter* tDiodeFilter; | 571 | float zi; |
| 461 | | 572 | float g0inv; |
| 462 | void tDiodeFilter_init (tDiodeFilter* const, float freq, float Q); | 573 | float g1inv; |
| 463 | void tDiodeFilter_initToPool (tDiodeFilter* const, float freq, float Q, tMempool* const); | 574 | float g2inv; |
| 464 | void tDiodeFilter_free (tDiodeFilter* const); | 575 | float s0, s1, s2, s3; |
| 465 | | 576 | } _tDiodeFilter; |
| 466 | float tDiodeFilter_tick (tDiodeFilter* const, float input); | 577 | |
| 467 | void tDiodeFilter_setFreq (tDiodeFilter* const vf, float cutoff); | 578 | typedef _tDiodeFilter* tDiodeFilter; |
| 468 | void tDiodeFilter_setQ (tDiodeFilter* const vf, float resonance); | 579 | |
| 469 | | 580 | void tDiodeFilter_init (tDiodeFilter* const, float freq, float Q); |
| 470 | | 581 | void tDiodeFilter_initToPool (tDiodeFilter* const, float freq, float Q, tMempool* const); |
| | 582 | void tDiodeFilter_free (tDiodeFilter* const); |
| | 583 | |
| | 584 | float tDiodeFilter_tick (tDiodeFilter* const, float input); |
| | 585 | void tDiodeFilter_setFreq (tDiodeFilter* const vf, float cutoff); |
| | 586 | void tDiodeFilter_setQ (tDiodeFilter* const vf, float resonance); |
| | 587 | |
| | 588 | |
| 471 | #ifdef __cplusplus | 589 | #ifdef __cplusplus |
| 472 | } | 590 | } |
| 473 | #endif | 591 | #endif |
| @@ -476,3 +594,4 @@ extern "C" { · 2 unmodified lines |
| 476 | | 594 | |
| 477 | //============================================================================== | 595 | //============================================================================== |
| 478 | | 596 | |
| | 597 | |