Files
sonobulus/src/synth/Voice.hpp
2026-06-12 23:13:18 -05:00

42 lines
914 B
C++

#pragma once
#include <stdint.h>
#include "Instrument.hpp"
// a voice is a tone generator that the synth uses for polyphony
// the synth mixes multiple voices together into a polyphonic audio. calculations for samples are handled in the instrument
class Voice {
public:
Voice() = default;
Voice(ConfigService* config, LoggerService* logger);
~Voice() = default;
void noteOn(uint8_t midiNote, float velocity);
void noteOff();
bool isActive();
float process(bool& scopeTrigger);
uint8_t note() { return note_; }
private:
float sampleRate_ = 44100.0f;
inline float noteToFrequency(uint8_t note) {
return 440.0f * pow(2.0f, static_cast<float>(note - 69) / static_cast<float>(12));
}
uint8_t note_ = 0;
float velocity_ = 1.0f;
bool active_ = false;
ConfigService* config_;
LoggerService* logger_;
Instrument instrument_;
};