[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:
39
src/Synth.cpp
Normal file
39
src/Synth.cpp
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user