Tabula Sonora 0.1.0
A native C++20 implementation of the Roland Sound Canvas VA synth voice
Loading...
Searching...
No Matches
ts::Sampler Class Reference

Wave playback: decode, then resample at a moving rate while honouring the loop. More...

#include <tabulasonora/sampler.hpp>

Public Member Functions

 Sampler (const WaveRom &rom, const Interpolator &interpolator)
 Creates the sampler over a ROM and resampler, both of which must outlive it.
const DecodedWavedecode (const WaveDescriptor &descriptor)
 Decodes a wave, caching the result.
std::vector< float > play (const DecodedWave &wave, int sample_count, double ratio) const
 Plays a wave at a constant rate.
std::vector< float > play_variable (const DecodedWave &wave, int sample_count, std::span< const double > ratios) const
 Plays a wave at a rate that changes per sample; a shorter input holds its last value.

Detailed Description

Wave playback: decode, then resample at a moving rate while honouring the loop.

Looping happens in the delta domain — the index rewinds while the predictor carries on — so loops, ping-pong and reverse are all seamless by construction with no crossfade anywhere.

Decoded waves are cached and never evicted. The working set is bounded by how many distinct waves a song touches, and every voice playing a wave shares one copy, so the cache is also what keeps a dense passage from decoding the same megabyte repeatedly.

Not thread-safe: decode mutates the cache. Both renderers drive it from one thread.

Constructor & Destructor Documentation

◆ Sampler()

ts::Sampler::Sampler ( const WaveRom & rom,
const Interpolator & interpolator )
inline

Creates the sampler over a ROM and resampler, both of which must outlive it.

Member Function Documentation

◆ decode()

const DecodedWave * ts::Sampler::decode ( const WaveDescriptor & descriptor)
nodiscard

Decodes a wave, caching the result.

Returns nullptr when the descriptor has no usable data. The returned pointer stays valid for the sampler's lifetime.

◆ play()

std::vector< float > ts::Sampler::play ( const DecodedWave & wave,
int sample_count,
double ratio ) const
nodiscard

Plays a wave at a constant rate.

◆ play_variable()

std::vector< float > ts::Sampler::play_variable ( const DecodedWave & wave,
int sample_count,
std::span< const double > ratios ) const
nodiscard

Plays a wave at a rate that changes per sample; a shorter input holds its last value.

Vibrato and pitch envelopes are applied by integrating the instantaneous rate into the read position, so the first sample always reads position zero.


The documentation for this class was generated from the following file: