add simple envelope to stop popping
This commit is contained in:
@@ -10,11 +10,10 @@ Instrument::Instrument(ConfigService* config, LoggerService* logger) :
|
||||
|
||||
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_;
|
||||
|
||||
envelope_ += 0.01f; // so it triggers as active
|
||||
|
||||
active_ = true;
|
||||
}
|
||||
|
||||
@@ -23,14 +22,18 @@ void Instrument::noteOff() {
|
||||
}
|
||||
|
||||
bool Instrument::isActive() {
|
||||
return active_;
|
||||
return (envelope_ > 0.0f);
|
||||
}
|
||||
|
||||
float Instrument::process(bool& scopeTrigger) {
|
||||
|
||||
if(active_ && envelope_ < 1.0f) envelope_ += 0.01f;
|
||||
if(!active_ && envelope_ > 0.0f) envelope_ -= 0.01f;
|
||||
|
||||
phase_ += phaseIncrement_;
|
||||
if(phase_ > 2.0f * pi) phase_ -= 2.0f * pi;
|
||||
|
||||
return sin(phase_);
|
||||
if(!isActive()) return 0.0f;
|
||||
return sin(phase_) * envelope_;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user