Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::WavetableT< SampleType > Class Template Reference

Wavetable oscillator with band-switching. More...

#include <wavetable.hpp>

Public Member Functions

 WavetableT ()=default
 WavetableT (std::vector< WavetableEntryT< SampleType > > bands)
 Construct from a list of bands.
void set_sample_rate (SampleType sr)
void set_frequency (SampleType hz)
void set_frequency_immediate (SampleType hz)
 Select the band for hz with NO crossfade — snap straight to it.
void reset ()
SampleType next ()
 Generate the next sample.
std::size_t band_count () const
int current_band () const
bool is_crossfading () const
SampleType band_max_frequency_hz (std::size_t i) const
 Upper alias-free playback frequency of band i — its max_frequency_hz, the ceiling select_band_for compares against.

Static Public Member Functions

static WavetableT make_sine (std::size_t table_length=2048, SampleType reference_sample_rate=SampleType{48000.0f})
 Compose a stack of harmonic-based bands for one of the four classical shapes (sine, saw, square, triangle).
static WavetableT make_saw (std::size_t bands=10, std::size_t table_length=2048, SampleType reference_sample_rate=SampleType{48000.0f})
static WavetableT make_square (std::size_t bands=10, std::size_t table_length=2048, SampleType reference_sample_rate=SampleType{48000.0f})
static WavetableT make_triangle (std::size_t bands=10, std::size_t table_length=2048, SampleType reference_sample_rate=SampleType{48000.0f})

Static Public Attributes

static constexpr std::size_t kCrossfadeSamples = 128
 Length of the band-switch crossfade in samples.

Detailed Description

template<typename SampleType = float>
class pulp::signal::WavetableT< SampleType >

Wavetable oscillator with band-switching.

RT contract: constructors and factory helpers allocate table storage and must run off the audio thread. set_sample_rate(), set_frequency(), reset(), and next() allocate no memory after construction.

Construction: supply a pre-sorted list of bands (lowest max_frequency_hz first). set_frequency selects the smallest band whose budget covers the new frequency. When the selection changes, next() crossfades between the previous and new band across kCrossfadeSamples samples — short enough to be inaudible, long enough to keep transitions click-free.

Constructor & Destructor Documentation

◆ WavetableT() [1/2]

template<typename SampleType = float>
pulp::signal::WavetableT< SampleType >::WavetableT ( )
default

◆ WavetableT() [2/2]

template<typename SampleType = float>
pulp::signal::WavetableT< SampleType >::WavetableT ( std::vector< WavetableEntryT< SampleType > > bands)
inlineexplicit

Construct from a list of bands.

The list is sorted by max_frequency_hz ascending internally; entries with empty samples are rejected.

Member Function Documentation

◆ band_count()

template<typename SampleType = float>
std::size_t pulp::signal::WavetableT< SampleType >::band_count ( ) const
inline

◆ band_max_frequency_hz()

template<typename SampleType = float>
SampleType pulp::signal::WavetableT< SampleType >::band_max_frequency_hz ( std::size_t i) const
inline

Upper alias-free playback frequency of band i — its max_frequency_hz, the ceiling select_band_for compares against.

Exposed read-only so a caller can place a stress tone just under a band ceiling (where the band's top harmonic sits nearest Nyquist) without duplicating the factory's ceiling formula. Returns 0 for an out-of-range index.

◆ current_band()

template<typename SampleType = float>
int pulp::signal::WavetableT< SampleType >::current_band ( ) const
inline

◆ is_crossfading()

template<typename SampleType = float>
bool pulp::signal::WavetableT< SampleType >::is_crossfading ( ) const
inline

◆ make_saw()

template<typename SampleType>
WavetableT< SampleType > pulp::signal::WavetableT< SampleType >::make_saw ( std::size_t bands = 10,
std::size_t table_length = 2048,
SampleType reference_sample_rate = SampleType{48000.0f} )
inlinestatic

◆ make_sine()

template<typename SampleType>
WavetableT< SampleType > pulp::signal::WavetableT< SampleType >::make_sine ( std::size_t table_length = 2048,
SampleType reference_sample_rate = SampleType{48000.0f} )
inlinestatic

Compose a stack of harmonic-based bands for one of the four classical shapes (sine, saw, square, triangle).

The result is fully bandlimited across the audible range: each band carries only harmonics whose frequency at the band's ceiling stays below half the assumed reference sample rate.

◆ make_square()

template<typename SampleType>
WavetableT< SampleType > pulp::signal::WavetableT< SampleType >::make_square ( std::size_t bands = 10,
std::size_t table_length = 2048,
SampleType reference_sample_rate = SampleType{48000.0f} )
inlinestatic

◆ make_triangle()

template<typename SampleType>
WavetableT< SampleType > pulp::signal::WavetableT< SampleType >::make_triangle ( std::size_t bands = 10,
std::size_t table_length = 2048,
SampleType reference_sample_rate = SampleType{48000.0f} )
inlinestatic

◆ next()

template<typename SampleType = float>
SampleType pulp::signal::WavetableT< SampleType >::next ( )
inline

Generate the next sample.

Returns 0 for an empty wavetable (allocation-safe default rather than UB).

◆ reset()

template<typename SampleType = float>
void pulp::signal::WavetableT< SampleType >::reset ( )
inline

◆ set_frequency()

template<typename SampleType = float>
void pulp::signal::WavetableT< SampleType >::set_frequency ( SampleType hz)
inline

◆ set_frequency_immediate()

template<typename SampleType = float>
void pulp::signal::WavetableT< SampleType >::set_frequency_immediate ( SampleType hz)
inline

Select the band for hz with NO crossfade — snap straight to it.

For the first frequency after construction or reset, there is no previously audible band to fade FROM: a fresh voice must start already settled on the correct band. set_frequency would instead begin a crossfade UP from the default band, playing that band's harmonic content at the new pitch for the fade window (an aliased onset on every note-on). The mid-stream set_frequency still crossfades — that fade is between two real playing bands and must stay smooth.

◆ set_sample_rate()

template<typename SampleType = float>
void pulp::signal::WavetableT< SampleType >::set_sample_rate ( SampleType sr)
inline

Member Data Documentation

◆ kCrossfadeSamples

template<typename SampleType = float>
std::size_t pulp::signal::WavetableT< SampleType >::kCrossfadeSamples = 128
staticconstexpr

Length of the band-switch crossfade in samples.

~2.7 ms at 48 kHz — well below the cycle of even the lowest audible frequency, so it does not smear transients.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/signal/include/pulp/signal/wavetable.hpp