polyphony checkpoint
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <numbers>
|
||||
#include <string>
|
||||
|
||||
AudioEngine::AudioEngine(ConfigService* config, LoggerService* logger, NoteQueue* noteQueue) : config_(config), logger_(logger), noteQueue_(noteQueue) {
|
||||
AudioEngine::AudioEngine(ConfigService* config, LoggerService* logger, Synth* synth) : config_(config), logger_(logger), synth_(synth) {
|
||||
|
||||
if(audioDevice_.getDeviceCount() < 1) {
|
||||
std::cout << "No audio devices found" << std::endl;
|
||||
@@ -70,29 +70,23 @@ int32_t AudioEngine::audioCallback(void* outputBuffer, void* inputBuffer, uint32
|
||||
|
||||
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);
|
||||
noteOn_ = (noteEvent.type == NoteEventType::NoteOn) ? true : false;
|
||||
freq_ = 440.0f * pow(2.0f, (static_cast<float>(noteEvent.note) - 69.0f) / 12.0f);
|
||||
}
|
||||
synth_->process(out, nFrames);
|
||||
|
||||
const float twoPi = 2.0f*std::numbers::pi_v<float>;
|
||||
float phaseIncrement = twoPi * freq_ / sampleRate_;
|
||||
// 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
|
||||
phase_ += phaseIncrement;
|
||||
if(phase_ > twoPi) {
|
||||
phase_ -= twoPi;
|
||||
}
|
||||
float outSample = std::sin(phase_) / 4.0f * noteOn_;
|
||||
// // simulate a sine wave
|
||||
// phase_ += phaseIncrement;
|
||||
// if(phase_ > twoPi) {
|
||||
// phase_ -= twoPi;
|
||||
// }
|
||||
// float outSample = std::sin(phase_) / 4.0f * noteOn_;
|
||||
|
||||
out[2*i] = outSample;
|
||||
out[2*i+1] = outSample;
|
||||
}
|
||||
// out[2*i] = outSample;
|
||||
// out[2*i+1] = outSample;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user