[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

40
inc/Oscillator.h Normal file
View File

@@ -0,0 +1,40 @@
#pragma once
#include<vector>
#include "OscillatorType.h"
class Oscillator
{
//typedef float (Oscillator::*OscFunction)(void);
//typedef float (Oscillator::*DtFunction)(float);
private:
OscillatorType m_osc;
float m_freq;
float m_volume;
float m_phase;
float m_phase_dt;
//значение типа "float (Oscillator::*)()" нельзя присвоить сущности типа "float (*)()"
float (Oscillator::*m_osc_function)(void);
float (Oscillator::*m_dt_function)(float freq);
void sine_osc_phase_incr();
void saw_osc_phase_incr();
float calc_saw_phase_delta(float freq);
float calc_sine_phase_delta(float freq);
float sawosc();
float triangleosc();
float squareosc();
float sign(float v);
float sineosc();
public:
Oscillator(OscillatorType osc, float freq, float volume);
~Oscillator();
OscillatorType GetType() { return m_osc; }
void SetType(OscillatorType osc);
float GetVolume() { return m_volume; }
void SetVolume(float volume) { m_volume = volume; }
float GetFreq() { return m_freq; }
void SetFreq(float freq);
void Reset();
float GenerateSample(float duration);
};