73 if (!tables.empty()) {
75 ceilings_.reserve(
first.band_count());
76 for (std::size_t b = 0; b <
first.band_count(); ++b)
77 ceilings_.push_back(
first.band_max_frequency_hz(b));
79 table_count_ = tables.size();
81 bank_.set_sample_rate(sample_rate_);
86 pending_band_snap_ =
true;
93 if (sample_rate > 0.0) sample_rate_ = sample_rate;
94 bank_.set_sample_rate(sample_rate_);
111 pending_band_snap_ =
true;
112 scan_position_ = scan_target_;
113 bank_.set_position(scan_position_);
120 scan_target_ = std::clamp(pos, 0.0, 1.0);
129 scan_time_ms_ = ms > 0.0 ? ms : 0.0;
138 double next(
double increment) {
139 const double frequency = increment * sample_rate_;
140 if (frequency > 0.0) {
147 if (pending_band_snap_) {
148 bank_.set_frequency_immediate(frequency);
149 pending_band_snap_ =
false;
151 bank_.set_frequency(frequency);
158 scan_position_ += (scan_target_ - scan_position_) * scan_coeff_;
159 bank_.set_position(scan_position_);
169 return i < ceilings_.size() ? ceilings_[
i] : 0.0;
178 void update_scan_coeff() {
179 if (scan_time_ms_ <= 0.0 || sample_rate_ <= 0.0) {
183 const double tau_samples = scan_time_ms_ * 0.001 * sample_rate_;
184 scan_coeff_ = 1.0 - std::exp(-1.0 / tau_samples);
188 std::vector<double> ceilings_;
189 std::size_t table_count_ = 0;
191 double sample_rate_ = 48000.0;
192 double scan_target_ = 0.0;
193 double scan_position_ = 0.0;
195 double scan_coeff_ = 1.0;
196 bool pending_band_snap_ =
true;
Modern wavetable oscillator over a set of band-limited WavetableTs.
Definition wt.hpp:59
static constexpr double kDefaultScanTimeMs
Default scan slew time (ms): the one-pole time constant that turns a stepped position control into a ...
Definition wt.hpp:64
double scan_time_ms() const
Definition wt.hpp:132
void set_wavetable_set(std::vector< Wavetable64 > tables)
Install the table set (off the audio thread).
Definition wt.hpp:71
void reset()
Reset phase and crossfade state to the start of the cycle, and snap the scan position to its target (...
Definition wt.hpp:109
std::size_t table_count() const
Number of tables the scan morphs across.
Definition wt.hpp:172
double next(double increment)
Generate one sample and advance by increment cycles (frequency รท sample rate).
Definition wt.hpp:138
void set_scan_time_ms(double ms)
Scan slew time, in ms.
Definition wt.hpp:128
void set_position(double pos)
Target scan position across the table set, 0..1 (0 = first table, 1 = last).
Definition wt.hpp:119
std::size_t band_count() const
Number of bands in the table set's readout (from the first table).
Definition wt.hpp:165
void prepare(double sample_rate)
Set the sample rate.
Definition wt.hpp:92
double band_max_frequency_hz(std::size_t i) const
Upper alias-free playback frequency of band i (its ceiling).
Definition wt.hpp:168
double position() const
The audible (slewed) scan position โ what the bank is actually morphing at.
Definition wt.hpp:123
@ first
Definition dither.hpp:23
WavetableBankT< double > WavetableBank64
Definition wavetable.hpp:309
@ i
Definition formant_filter_bank.hpp:20
WavetableT< double > Wavetable64
Definition wavetable.hpp:307
Wavetable oscillator with band-switching + bank morphing.