its a monosynth now
This commit is contained in:
@@ -72,19 +72,23 @@ int32_t AudioEngine::process(float* out, size_t nFrames) {
|
|||||||
|
|
||||||
NoteEvent noteEvent;
|
NoteEvent noteEvent;
|
||||||
while(noteQueue_->pop(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);
|
//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);
|
//logger_->log("Audio", LogFlag::Debug, msg);
|
||||||
|
noteOn_ = (noteEvent.type == NoteEventType::NoteOn) ? true : false;
|
||||||
|
freq_ = 440.0f * pow(2.0f, (static_cast<float>(noteEvent.note) - 69.0f) / 12.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float twoPi = 2.0f*std::numbers::pi_v<float>;
|
||||||
|
float phaseIncrement = twoPi * freq_ / sampleRate_;
|
||||||
|
|
||||||
for(size_t i = 0; i < nFrames; i++) {
|
for(size_t i = 0; i < nFrames; i++) {
|
||||||
|
|
||||||
// simulate a sine wave
|
// simulate a sine wave
|
||||||
phase_ += 0.04f;
|
phase_ += phaseIncrement;
|
||||||
const float twoPi = 2.0f*std::numbers::pi_v<float>;
|
|
||||||
if(phase_ > twoPi) {
|
if(phase_ > twoPi) {
|
||||||
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] = outSample;
|
||||||
out[2*i+1] = outSample;
|
out[2*i+1] = outSample;
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ private:
|
|||||||
uint32_t channels_ = 2;
|
uint32_t channels_ = 2;
|
||||||
|
|
||||||
float phase_ = 0.0f;
|
float phase_ = 0.0f;
|
||||||
|
float freq_ = 0.0f;
|
||||||
|
bool noteOn_ = false;
|
||||||
|
|
||||||
LoggerService* logger_;
|
LoggerService* logger_;
|
||||||
ConfigService* config_;
|
ConfigService* config_;
|
||||||
|
|||||||
Reference in New Issue
Block a user