From 1cd4a952462f27fe26fb970561702ec26e4f5f8a Mon Sep 17 00:00:00 2001 From: paulfd Date: Wed, 28 Aug 2019 17:23:36 +0200 Subject: [PATCH] Tracking the phase of the sine directly instead of recomputing it --- sources/Voice.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/Voice.h b/sources/Voice.h index c2dce465..07e8d885 100644 --- a/sources/Voice.h +++ b/sources/Voice.h @@ -165,9 +165,10 @@ public: return; float step = baseFrequency * twoPi / sampleRate; - ::linearRamp(tempSpan1.first(buffer.size()), sourcePosition * step, step); - ::sin(tempSpan1, buffer.left()); + phase = ::linearRamp(tempSpan1, phase, step); + ::sin(tempSpan1.first(buffer.size()), buffer.left()); absl::c_copy(buffer.left(), buffer.right().begin()); + sourcePosition += buffer.size(); } @@ -238,6 +239,7 @@ private: float pitchRatio { 1.0 }; float baseGain { 1.0 }; float baseFrequency { 440.0 }; + float phase { 0.0f }; uint32_t sourcePosition { 0 }; uint32_t initialDelay { 0 };