From 210286514e11d3ee765a046960abbe0bfa65234a Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Sat, 23 Sep 2017 00:26:06 +0100 Subject: [PATCH] Calculate voice step length adjustments. Signed-off-by: Adrian.Conlon --- LR35902/inc/Audio.h | 8 ++++++++ LR35902/src/Audio.cpp | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/LR35902/inc/Audio.h b/LR35902/inc/Audio.h index e107b2a..04b6067 100644 --- a/LR35902/inc/Audio.h +++ b/LR35902/inc/Audio.h @@ -375,6 +375,14 @@ namespace EightBit { std::array, 4> m_voices; std::array m_channels; bool m_enabled; + + template + static void stepLength(T* voice) { + if (voice->length() > 0) { + auto current = voice->length(); + voice->setLength(--current); + } + } }; } } \ No newline at end of file diff --git a/LR35902/src/Audio.cpp b/LR35902/src/Audio.cpp index 71a3d34..8863726 100644 --- a/LR35902/src/Audio.cpp +++ b/LR35902/src/Audio.cpp @@ -47,7 +47,7 @@ void EightBit::GameBoy::Envelope::step() { auto volume = m_volume + (m_direction == Amplify ? +1 : -1); if (volume >= 0 || volume <= 15) m_volume = volume; - m_position == m_period; + m_position = m_period; } } } @@ -784,6 +784,10 @@ void EightBit::GameBoy::Audio::Sequencer_FrameStep(const int step) { } void EightBit::GameBoy::Audio::Sequencer_LengthStep(const int step) { + stepLength(voice1()); + stepLength(voice2()); + stepLength(voice3()); + stepLength(voice4()); } void EightBit::GameBoy::Audio::Sequencer_VolumeStep(const int step) {