|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Professional mipmapped wavetable oscillator for bandlimited synthesis. More...
#include <WavetableOscillator.h>
Public Member Functions | |
| WavetableOscillator ()=default | |
| void | prepare (double sampleRate) |
| Prepares the oscillator for a given sample rate. | |
| void | prepare (const AudioSpec &spec) |
| Prepares from AudioSpec (unified API). | |
| void | buildSaw () |
| Builds a bandlimited sawtooth wavetable with mipmaps. | |
| void | buildSquare () |
| Builds a bandlimited square wavetable with mipmaps. | |
| void | buildTriangle () |
| Builds a bandlimited triangle wavetable with mipmaps. | |
| void | buildSine () |
| Builds a pure sine wavetable. | |
| template<typename HarmonicFunc > | |
| void | buildFromHarmonics (HarmonicFunc harmonicFunc) |
| Builds contiguous mipmapped tables from a harmonic amplitude function. | |
| void | loadWavetable (const T *data, int size) |
| Loads and analyzes a custom single-cycle wavetable. | |
| void | setBank (const WavetableBank *bank) noexcept |
| Plays an external bank instead of the oscillator's own table. | |
| void | setPosition (T position) noexcept |
| Morph position across the bank's frames, 0 .. frames - 1 (fractional positions blend adjacent frames; clamped on read). | |
| T | getPosition () const noexcept |
| void | setFrequency (T frequencyHz) noexcept |
| Sets the fundamental oscillation frequency. | |
| T | getFrequency () const noexcept |
| Returns the current internal frequency. | |
| T | getSample () noexcept |
| Generates the next sample. | |
| void | processBlock (T *output, int numSamples) noexcept |
| Generates a block of samples. | |
| void | generateBlock (AudioBufferView< T > buffer) noexcept |
| Fills every channel of the view with the generated waveform. Satisfies the GeneratorProcessor concept (mono source, all channels equal). | |
| void | reset (T phase=T(0)) noexcept |
| Hard resets the oscillator phase. | |
Static Public Attributes | |
| static constexpr int | kTableSize = 2048 |
| Samples of the shortest level table (brighter levels hold more; see WavetableBank). | |
| static constexpr int | kTableMask = kTableSize - 1 |
| static constexpr int | kMaxMipLevels = WavetableBank::kMipLevels |
| Mip levels, half an octave apart. | |
Professional mipmapped wavetable oscillator for bandlimited synthesis.
| T | Sample type (float or double). Must satisfy std::floating_point. |
Definition at line 65 of file WavetableOscillator.h.
|
default |
|
inline |
Builds contiguous mipmapped tables from a harmonic amplitude function.
| HarmonicFunc | Callable signature: T(int harmonic) |
| harmonicFunc | Function returning the sine amplitude for harmonic N (starts at 1, up to WavetableBank::kMaxHarmonics). |
Definition at line 162 of file WavetableOscillator.h.
|
inline |
Builds a bandlimited sawtooth wavetable with mipmaps.
Definition at line 110 of file WavetableOscillator.h.
|
inline |
Builds a pure sine wavetable.
Definition at line 145 of file WavetableOscillator.h.
|
inline |
Builds a bandlimited square wavetable with mipmaps.
Definition at line 121 of file WavetableOscillator.h.
|
inline |
Builds a bandlimited triangle wavetable with mipmaps.
Definition at line 132 of file WavetableOscillator.h.
|
inlinenoexcept |
Fills every channel of the view with the generated waveform. Satisfies the GeneratorProcessor concept (mono source, all channels equal).
Definition at line 265 of file WavetableOscillator.h.
|
inlinenoexcept |
Returns the current internal frequency.
Definition at line 236 of file WavetableOscillator.h.
|
inlinenoexcept |
Definition at line 211 of file WavetableOscillator.h.
|
inlinenoexcept |
Generates the next sample.
Definition at line 243 of file WavetableOscillator.h.
|
inline |
Loads and analyzes a custom single-cycle wavetable.
The cycle is analysed exactly on its own length (no resampling), its DC discarded, and the mip levels rebuilt from its harmonics.
| data | Pointer to wavetable samples. |
| size | Number of samples in the input data (3 or more; smaller sizes and null data are ignored). |
Definition at line 181 of file WavetableOscillator.h.
|
inline |
Prepares from AudioSpec (unified API).
| spec | Framework AudioSpec instance containing sample rate. |
Definition at line 99 of file WavetableOscillator.h.
|
inline |
Prepares the oscillator for a given sample rate.
Re-derives the mip selection for tables that were already built, so a rate change after build*() keeps the anti-aliasing exact.
| sampleRate | Sample rate in Hz. Must be > 0 (invalid values, including NaN, are ignored). |
Definition at line 85 of file WavetableOscillator.h.
|
inlinenoexcept |
Generates a block of samples.
| output | Pointer to output buffer. |
| numSamples | Number of samples to process. |
Definition at line 255 of file WavetableOscillator.h.
|
inlinenoexcept |
Hard resets the oscillator phase.
| phase | Initial phase normalized [0.0, 1.0]. |
Definition at line 281 of file WavetableOscillator.h.
|
inlinenoexcept |
Plays an external bank instead of the oscillator's own table.
The bank is not owned and must outlive its use; it must not be rebuilt while this oscillator generates. nullptr returns to the own table. Setup-time (same contract as the build methods).
Definition at line 195 of file WavetableOscillator.h.
|
inlinenoexcept |
Sets the fundamental oscillation frequency.
| frequencyHz | Frequency in Hz. |
Definition at line 220 of file WavetableOscillator.h.
|
inlinenoexcept |
Morph position across the bank's frames, 0 .. frames - 1 (fractional positions blend adjacent frames; clamped on read).
Definition at line 205 of file WavetableOscillator.h.
|
staticconstexpr |
Mip levels, half an octave apart.
Definition at line 72 of file WavetableOscillator.h.
|
staticconstexpr |
Definition at line 70 of file WavetableOscillator.h.
|
staticconstexpr |
Samples of the shortest level table (brighter levels hold more; see WavetableBank).
Definition at line 69 of file WavetableOscillator.h.