| 1 | // these BLEP routines are based on code by aciddose (written for this project) |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | /* aciddose: |
| 8 | ** information on blep variables |
| 9 | ** |
| 10 | ** ZC = zero crossings, the number of ripples in the impulse |
| 11 | ** OS = oversampling, how many samples per zero crossing are taken |
| 12 | ** SP = step size per output sample, used to lower the cutoff (play the impulse slower) |
| 13 | ** NS = number of samples of impulse to insert |
| 14 | ** RNS = the lowest power of two greater than NS, minus one (used to wrap output buffer) |
| 15 | ** |
| 16 | ** ZC and OS are here only for reference, they depend upon the data in the table and can't be changed. |
| 17 | ** SP, the step size can be any number lower or equal to OS, as long as the result NS remains an integer. |
| 18 | ** for example, if ZC=8,OS=5, you can set SP=1, the result is NS=40, and RNS must then be 63. |
| 19 | ** the result of that is the filter cutoff is set at nyquist * (SP/OS), in this case nyquist/5. |
| 20 | */ |
| 21 | |
| 22 | #define BLEP_ZC 16 |
| 23 | #define BLEP_OS 16 |
| 24 | #define BLEP_SP 16 |
| 25 | #define BLEP_NS (BLEP_ZC * BLEP_OS / BLEP_SP) |
| 26 | #define BLEP_RNS 31 // RNS = (2^ > NS) - 1 |
| 27 | |
| 28 | typedef struct blep_t |
| 29 | { |
| 30 | int32_t index, samplesLeft; |
| 31 | float fBuffer[BLEP_RNS+1], fLastValue; |
| 32 | } blep_t; |
| 33 | |
| 34 | void blepAdd(blep_t *b, const float fOffset, const float fAmplitude); |
| 35 | float blepRun(blep_t *b, const float fInput); |