From d565817d8f52e998a93c1194cfe7bb005ddf0290 Mon Sep 17 00:00:00 2001 From: HiveBeats Date: Tue, 8 Aug 2023 00:06:23 +0400 Subject: [PATCH] fix: oscillator --- inc/Oscillator.h | 9 +++++---- src/Oscillator.cpp | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/inc/Oscillator.h b/inc/Oscillator.h index 24d54f5..93111fe 100644 --- a/inc/Oscillator.h +++ b/inc/Oscillator.h @@ -2,11 +2,11 @@ #include #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); diff --git a/src/Oscillator.cpp b/src/Oscillator.cpp index f3d63e9..ebdc0be 100644 --- a/src/Oscillator.cpp +++ b/src/Oscillator.cpp @@ -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()