package slider components into its own widget

This commit is contained in:
2025-12-25 21:39:12 -06:00
parent 65fd963a3f
commit 97de073690
13 changed files with 244 additions and 241 deletions

View File

@@ -29,15 +29,15 @@ private:
// RtAudio binding for passing samples
static int32_t audioCallback(void* outputBuffer, void* inputBuffer, uint32_t nFrames, double streamTime, RtAudioStreamStatus status, void* userData);
// calls the synth.process to generate a buffer audio samples
// calls the synth.process to generate a buffer of audio samples
int32_t process(float* out, uint32_t nFrames);
ParameterStore params_;
NoteQueue noteQueue_;
Synth synth_;
ParameterStore params_; // stores the control parameters
NoteQueue noteQueue_; // stores note events for passing between threads
Synth synth_; // generates audio
RtAudio audio_; // audio device
// TODO: id like a yml config file or something for these
RtAudio audio_;
uint32_t sampleRate_ = 44100;
uint32_t bufferFrames_ = 256; // time per buffer = BF/SR (256/44100 = 5.8ms)
uint32_t channels_ = 2; // stereo

View File

@@ -21,6 +21,7 @@ public:
// setters
void setSampleRate(float sampleRate) { sampleRate_ = sampleRate; }
void set(float a, float d, float s, float r) { setAttack(a); setDecay(a); setSustain(a); setRelease(a); }
void setAttack(float seconds) { attack_ = std::max(seconds, 0.0001f); }
void setDecay(float seconds) { decay_ = std::max(seconds, 0.0001f); }
void setSustain(float level) { sustain_ = level; }

View File

@@ -73,6 +73,8 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
for(auto& p : params_) p.update(); // TODO: profile this
// process all envelopes
//gainEnvelope_.set(0.05f, 0.2f, 0.7f, getParam(ParamId::Osc1VolumeEnvR));
gainEnvelope_.setRelease(getParam(ParamId::Osc1VolumeEnvR));
float gain = gainEnvelope_.process();
// skip if no active notes
@@ -85,10 +87,13 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
float phaseInc = 2.0f * M_PI * frequency_ / static_cast<float>(sampleRate);
// sample generation
// TODO: wavetables
// TODO: wavetables should be scaled by their RMS for equal loudness (prelim standard = 0.707)
float sineSample = std::sin(phase_);
float squareSample = -0.707f;
if(phase_ >= M_PI) squareSample = 0.707f;
sampleOut = squareSample * gain;
float sawSample = phase_ * 4.0f / M_PI * frequency_ / static_cast<float>(sampleRate);
sampleOut = sawSample * gain;
// write to buffer
out[2*i] = sampleOut; // left