From 6817c0e700290716d34948129d3024709ddaaa03 Mon Sep 17 00:00:00 2001 From: Bliblank Date: Wed, 10 Jun 2026 21:23:55 -0500 Subject: [PATCH] its a monosynth now --- src/synth/AudioEngine.cpp | 14 +++++++++----- src/synth/AudioEngine.hpp | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/synth/AudioEngine.cpp b/src/synth/AudioEngine.cpp index 45bf5bd..c2000a3 100644 --- a/src/synth/AudioEngine.cpp +++ b/src/synth/AudioEngine.cpp @@ -72,19 +72,23 @@ int32_t AudioEngine::process(float* out, size_t nFrames) { NoteEvent noteEvent; while(noteQueue_->pop(noteEvent)) { - std::string msg = "[NoteEvent] Type: " + std::to_string(noteEvent.type) +" Velocity: " + std::to_string(noteEvent.velocity) + " Note:" + std::to_string(noteEvent.note); - logger_->log("Audio", LogFlag::Debug, msg); + //std::string msg = "[NoteEvent] Type: " + std::to_string(noteEvent.type) +" Velocity: " + std::to_string(noteEvent.velocity) + " Note:" + std::to_string(noteEvent.note); + //logger_->log("Audio", LogFlag::Debug, msg); + noteOn_ = (noteEvent.type == NoteEventType::NoteOn) ? true : false; + freq_ = 440.0f * pow(2.0f, (static_cast(noteEvent.note) - 69.0f) / 12.0f); } + const float twoPi = 2.0f*std::numbers::pi_v; + float phaseIncrement = twoPi * freq_ / sampleRate_; + for(size_t i = 0; i < nFrames; i++) { // simulate a sine wave - phase_ += 0.04f; - const float twoPi = 2.0f*std::numbers::pi_v; + phase_ += phaseIncrement; if(phase_ > twoPi) { phase_ -= twoPi; } - float outSample = std::sin(phase_) / 4.0f; + float outSample = std::sin(phase_) / 4.0f * noteOn_; out[2*i] = outSample; out[2*i+1] = outSample; diff --git a/src/synth/AudioEngine.hpp b/src/synth/AudioEngine.hpp index bd5ff17..0d8ce13 100644 --- a/src/synth/AudioEngine.hpp +++ b/src/synth/AudioEngine.hpp @@ -40,6 +40,8 @@ private: uint32_t channels_ = 2; float phase_ = 0.0f; + float freq_ = 0.0f; + bool noteOn_ = false; LoggerService* logger_; ConfigService* config_;