fix: oscillator

This commit is contained in:
2023-08-08 00:06:23 +04:00
parent 56b68bc963
commit d565817d8f
2 changed files with 15 additions and 14 deletions

View File

@@ -2,11 +2,11 @@
#include<vector>
#include "OscillatorType.h"
typedef float (Oscillator::*OscFunction)(void);
typedef float (Oscillator::*DtFunction)(float);
class Oscillator
{
//typedef float (Oscillator::*OscFunction)(void);
//typedef float (Oscillator::*DtFunction)(float);
private:
OscillatorType m_osc;
@@ -14,8 +14,9 @@ class Oscillator
float m_volume;
float m_phase;
float m_phase_dt;
OscFunction m_osc_function;
DtFunction m_dt_function;
//значение типа "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);

View File

@@ -26,20 +26,20 @@ void Oscillator::SetType(OscillatorType osc)
m_osc = osc;
switch (m_osc) {
case Sine:
m_osc_function = &sineosc;
m_dt_function = &calc_sine_phase_delta;
m_osc_function = &Oscillator::sineosc;
m_dt_function = &Oscillator::calc_sine_phase_delta;
break;
case Triangle:
m_osc_function = &triangleosc;
m_dt_function = &calc_saw_phase_delta;
m_osc_function = &Oscillator::triangleosc;
m_dt_function = &Oscillator::calc_saw_phase_delta;
break;
case Square:
m_osc_function = &squareosc;
m_dt_function = &calc_sine_phase_delta;
m_osc_function = &Oscillator::squareosc;
m_dt_function = &Oscillator::calc_sine_phase_delta;
break;
case Saw:
m_osc_function = &sawosc;
m_dt_function = &calc_saw_phase_delta;
m_osc_function = &Oscillator::sawosc;
m_dt_function = &Oscillator::calc_saw_phase_delta;
break;
}
}
@@ -48,12 +48,12 @@ void Oscillator::SetFreq(float freq)
{
m_freq = freq;
m_phase = 0;
m_phase_dt = m_dt_function(freq);
m_phase_dt = (this->*m_dt_function)(freq);
}
float Oscillator::GenerateSample(float duration)
{
return m_osc_function() * m_volume;
return (this->*m_osc_function)() * m_volume;
}
void Oscillator::sine_osc_phase_incr()