[refactor]: c++ implementation (#13)

implemented in c++ to improve readability and simplify maintenance

Co-authored-by: HiveBeats <e1lama@protonmail.com>
Reviewed-on: #13
This commit is contained in:
2023-08-08 22:08:18 +03:00
parent bcb75a65f9
commit a445fc44b3
31 changed files with 1006 additions and 1054 deletions

39
src/Synth.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include "Synth.h"
#include "Settings.h"
#include "KeyBoard.h"
#include "OscillatorType.h"
Synth::Synth(/* args */)
{
AddOscillator();
}
Synth::~Synth()
{
}
std::vector<float> & Synth::get_note(int semitone, float beats)
{
float hz = KeyBoard::GetHzBySemitone(semitone);
float duration = beats * BEAT_DURATION;
// will change after oscillator starts to be more autonomous
for (Oscillator* osc : m_oscillators)
{
osc->SetFreq(hz);
}
return m_adder.SumOscillators(m_oscillators, duration); //todo: add other pipeline steps (e.g ADSR, Filters, FX);
}
void Synth::ProduceNoteSound(Note input)
{
float length = 1.f / input.length;
int semitone_shift = KeyBoard::GetSemitoneShift(input.name);
m_out_signal = get_note(semitone_shift, length);
}
void Synth::AddOscillator()
{
m_oscillators.push_back(new Oscillator(OscillatorType::Sine, 440.f, VOLUME));
}