add simple envelope to stop popping

This commit is contained in:
2026-06-13 12:26:57 -05:00
parent 9f79f11a19
commit fcc24c5e3e
5 changed files with 16 additions and 7 deletions

View File

@@ -27,6 +27,11 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/hyperrealm/libconfig.git GIT_REPOSITORY https://github.com/hyperrealm/libconfig.git
GIT_TAG v1.8.2 GIT_TAG v1.8.2
) )
FetchContent_Declare(
eigen
GIT_REPOSITORY git@gitlab.com:libeigen/eigen.git
GIT_TAG 5.0
)
FetchContent_MakeAvailable(rtaudio) FetchContent_MakeAvailable(rtaudio)
FetchContent_MakeAvailable(rtmidi) FetchContent_MakeAvailable(rtmidi)
FetchContent_MakeAvailable(libconfig) FetchContent_MakeAvailable(libconfig)

View File

@@ -29,7 +29,7 @@ to produce somewhat well-sounding instruments and music performance.
to external midi controllers/apps (like musescore) to external midi controllers/apps (like musescore)
- [ ] Create a UI scope to visualize the synthesized composite waveform - [ ] Create a UI scope to visualize the synthesized composite waveform
- [ ] Check cross-platform combatibility for Windows & Linux, especially MIDI interfacing - [ ] Check cross-platform combatibility for Windows & Linux, especially MIDI interfacing
- [ ] Checkpoint at a rudimentary keyboard instrument producing a basic sine output - [x] Checkpoint at a rudimentary keyboard instrument producing a basic sine output
- [ ] Will flesh out future goals when I do the math on how complicated implementing - [ ] Will flesh out future goals when I do the math on how complicated implementing
state-space modelling in c++ is state-space modelling in c++ is

View File

@@ -10,11 +10,10 @@ Instrument::Instrument(ConfigService* config, LoggerService* logger) :
void Instrument::noteOn(float frequency, float velocity) { void Instrument::noteOn(float frequency, float velocity) {
// std::string msg = "NoteOn Frequency = " + std::to_string(frequency);
// if(logger_ != nullptr) logger_->log("Instrument", LogFlag::Debug, msg);
phaseIncrement_ = 2.0f * pi * frequency / sampleRate_; phaseIncrement_ = 2.0f * pi * frequency / sampleRate_;
envelope_ += 0.01f; // so it triggers as active
active_ = true; active_ = true;
} }
@@ -23,14 +22,18 @@ void Instrument::noteOff() {
} }
bool Instrument::isActive() { bool Instrument::isActive() {
return active_; return (envelope_ > 0.0f);
} }
float Instrument::process(bool& scopeTrigger) { float Instrument::process(bool& scopeTrigger) {
if(active_ && envelope_ < 1.0f) envelope_ += 0.01f;
if(!active_ && envelope_ > 0.0f) envelope_ -= 0.01f;
phase_ += phaseIncrement_; phase_ += phaseIncrement_;
if(phase_ > 2.0f * pi) phase_ -= 2.0f * pi; if(phase_ > 2.0f * pi) phase_ -= 2.0f * pi;
return sin(phase_); if(!isActive()) return 0.0f;
return sin(phase_) * envelope_;
} }

View File

@@ -32,5 +32,6 @@ private:
static constexpr float pi = 3.14159265358979323846f; static constexpr float pi = 3.14159265358979323846f;
float phase_ = 0.0f; float phase_ = 0.0f;
float phaseIncrement_ = 0.0f; float phaseIncrement_ = 0.0f;
float envelope_ = 0.0f;
}; };

View File

@@ -45,7 +45,7 @@ void Synth::process(float* out, size_t nFrames) {
float mix = 0.0f; float mix = 0.0f;
for(size_t j = 0; j < voices_.size(); j++) { for(size_t j = 0; j < voices_.size(); j++) {
bool temp = false; bool temp = false;
if(!voices_[j].isActive()) continue; //if(!voices_[j].isActive()) continue;
mix += voices_[j].process(temp); mix += voices_[j].process(temp);
// if(j == lowestVoice) triggered = temp; // if(j == lowestVoice) triggered = temp;
} }