|
Oakfield API Documentation 1.0.0
Numerical core APIs
|
Bandlimited Fourier waveform kernels (BLIT / PolyBLEP / miniBLEP). More...
#include <complex.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include "oakfield/field.h"
Go to the source code of this file.
Classes | |
| struct | SimComplexDouble |
| Explicit in-memory representation for a complex double scalar (re, im) More... | |
Macros | |
| #define | SIM_FOURIER_ASSUME_VALID 0 |
| Skip hot-path argument clamps when inputs are validated by caller. | |
| #define | SIM_FOURIER_MINIBLEP_SPAN 4.0 |
| Two-sided BLIT support window (in units of phase increment): wider -> cleaner stopband. | |
| #define | SIM_FOURIER_MINIBLEP_MAX_WINDOW 0.5 |
| Maximum miniBLEP window in normalized phase (0..1). | |
| #define | SIM_FOURIER_INTEGRATOR_LEAK 1e-9 |
| Small leak to keep BLIT integrators numerically bounded. | |
Typedefs | |
| typedef struct SimComplexDouble | SimComplexDouble |
| Fallback ABI-compatible complex double if not defined in field.h. | |
Functions | |
| double | sim_fourier_dirichlet (double phase_radians, int harmonic_count) |
| Normalized Dirichlet kernel D_M(φ) = sin(Mφ/2)/(M sin(φ/2)). | |
| SimComplexDouble | sim_fourier_dirichlet_complex (SimComplexDouble phase_radians, int harmonic_count) |
| Complex Dirichlet kernel. | |
| double | sim_fourier_blit (double phase_radians, int harmonic_count) |
| DC-corrected BLIT for saw/triangle integration: D_M(φ) − 1/M. | |
| SimComplexDouble | sim_fourier_blit_complex (SimComplexDouble phase_radians, int harmonic_count) |
| Complex BLIT (DC-corrected). | |
| double | sim_fourier_saw_blit (double phase_radians, double phase_increment_radians, int harmonic_count, double *state) |
| Bandlimited saw from BLIT integration. | |
| SimComplexDouble | sim_fourier_saw_blit_complex (SimComplexDouble phase_radians, double phase_increment_radians, int harmonic_count, SimComplexDouble *state) |
| Complex BLIT saw (integrates complex BLIT). | |
| double | sim_fourier_square_blit (double phase_radians, double phase_increment_radians, int harmonic_count, double duty, double *state) |
| Bandlimited square via phase-shifted BLIT difference and integration. | |
| SimComplexDouble | sim_fourier_square_blit_complex (SimComplexDouble phase_radians, double phase_increment_radians, int harmonic_count, double duty, SimComplexDouble *state) |
| Complex BLIT square. | |
| double | sim_fourier_triangle_blit (double phase_radians, double phase_increment_radians, int harmonic_count, double *velocity_state, double *position_state) |
| Triangle from double-integrated BLIT square (velocity + position states). | |
| SimComplexDouble | sim_fourier_triangle_blit_complex (SimComplexDouble phase_radians, double phase_increment_radians, int harmonic_count, SimComplexDouble *velocity_state, SimComplexDouble *position_state) |
| Complex BLIT triangle (double integration). | |
| double | sim_fourier_polyblep (double phase, double dphase) |
| Two-point PolyBLEP step correction (subtract from naive saw/square). | |
| SimComplexDouble | sim_fourier_polyblep_complex (double phase, double dphase) |
| Complex PolyBLEP (imaginary part = 0). | |
| double | sim_fourier_polyblamp (double phase, double dphase) |
| PolyBLAMP (integral of PolyBLEP) for slope/kink smoothing. | |
| SimComplexDouble | sim_fourier_polyblamp_complex (double phase, double dphase) |
| Complex PolyBLAMP. | |
| double | sim_fourier_miniblep (double phase, double dphase) |
| Table-driven miniBLEP (windowed-sinc step) for high stopband rejection. | |
| SimComplexDouble | sim_fourier_miniblep_complex (double phase, double dphase) |
| Complex miniBLEP. | |
| double | sim_fourier_miniblamp (double phase, double dphase) |
| miniBLAMP (integrated miniBLEP) for slope discontinuities (triangle). | |
| SimComplexDouble | sim_fourier_miniblamp_complex (double phase, double dphase) |
| Complex miniBLAMP. | |
Bandlimited Fourier waveform kernels (BLIT / PolyBLEP / miniBLEP).
This header provides reusable kernels for research-grade saw, square, and triangle oscillators:
All routines use double precision. Complex variants use SimComplexDouble for ABI stability and mirror the real APIs.
| #define SIM_FOURIER_ASSUME_VALID 0 |
Skip hot-path argument clamps when inputs are validated by caller.
0 = clamp/guard (default), 1 = assume phase/duty in-range; debug builds assert.
| #define SIM_FOURIER_MINIBLEP_SPAN 4.0 |
Two-sided BLIT support window (in units of phase increment): wider -> cleaner stopband.
The miniBLEP/miniBLAMP kernels are stretched over SIM_FOURIER_MINIBLEP_SPAN phase increments but capped at SIM_FOURIER_MINIBLEP_MAX_WINDOW to avoid consuming an entire period near Nyquist.
| double sim_fourier_dirichlet | ( | double | phase_radians, |
| int | harmonic_count | ||
| ) |
Normalized Dirichlet kernel D_M(φ) = sin(Mφ/2)/(M sin(φ/2)).
| phase_radians | Instantaneous phase in radians (wrap to 2π is optional). |
| harmonic_count | N = number of positive harmonics below Nyquist. |
Implementation detail:
| double sim_fourier_miniblep | ( | double | phase, |
| double | dphase | ||
| ) |
Table-driven miniBLEP (windowed-sinc step) for high stopband rejection.
| phase | Normalized phase in [0,1). |
| dphase | Normalized phase increment (f / fs). |
| double sim_fourier_polyblep | ( | double | phase, |
| double | dphase | ||
| ) |
Two-point PolyBLEP step correction (subtract from naive saw/square).
| phase | Normalized phase in [0,1). |
| dphase | Normalized phase increment per sample (f / fs). |
| double sim_fourier_saw_blit | ( | double | phase_radians, |
| double | phase_increment_radians, | ||
| int | harmonic_count, | ||
| double * | state | ||
| ) |
Bandlimited saw from BLIT integration.
| phase_radians | Phase in radians. | |
| phase_increment_radians | Per-sample phase advance (2π f / fs). | |
| harmonic_count | Number of partials (see sim_fourier_dirichlet). | |
| [in,out] | state | Single-pole integrator state (initialize to 0). |
| double sim_fourier_square_blit | ( | double | phase_radians, |
| double | phase_increment_radians, | ||
| int | harmonic_count, | ||
| double | duty, | ||
| double * | state | ||
| ) |
Bandlimited square via phase-shifted BLIT difference and integration.
| phase_radians | Current oscillator phase. |
| phase_increment_radians | Phase increment per output sample. |
| harmonic_count | Number of harmonics to include. |
| duty | Duty cycle in [0,1]; 0.5 yields a symmetric square. |
| state | Integrator state for the BLIT accumulator. |
| double sim_fourier_triangle_blit | ( | double | phase_radians, |
| double | phase_increment_radians, | ||
| int | harmonic_count, | ||
| double * | velocity_state, | ||
| double * | position_state | ||
| ) |
Triangle from double-integrated BLIT square (velocity + position states).
| phase_radians | Current oscillator phase. |
| phase_increment_radians | Phase increment per output sample. |
| harmonic_count | Number of harmonics to include. |
| velocity_state | First integrator (square accumulator), init to 0. |
| position_state | Second integrator (triangle accumulator), init to 0. |