From 4e802e90caa14d95ea56a68faabcd95d2c7702f1 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 20 Jan 2021 12:32:36 +1000 Subject: [PATCH] SPU: Move voice key off/on outside sample loop Should be a very tiny performance boost with no difference in behaviour. --- src/core/spu.cpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/core/spu.cpp b/src/core/spu.cpp index 48174f247..4aad31f6b 100644 --- a/src/core/spu.cpp +++ b/src/core/spu.cpp @@ -1745,10 +1745,6 @@ void SPU::Execute(TickCount ticks) s32 reverb_in_left = 0; s32 reverb_in_right = 0; - u32 key_on_register = m_key_on_register; - m_key_on_register = 0; - u32 key_off_register = m_key_off_register; - m_key_off_register = 0; u32 reverb_on_register = m_reverb_on_register; for (u32 voice = 0; voice < NUM_VOICES; voice++) @@ -1763,17 +1759,6 @@ void SPU::Execute(TickCount ticks) reverb_in_right += right; } reverb_on_register >>= 1; - - if (key_off_register & 1u) - m_voices[voice].KeyOff(); - key_off_register >>= 1; - - if (key_on_register & 1u) - { - m_endx_register &= ~(1u << voice); - m_voices[voice].KeyOn(); - } - key_on_register >>= 1; } if (!m_SPUCNT.mute_n) @@ -1823,6 +1808,30 @@ void SPU::Execute(TickCount ticks) WriteToCaptureBuffer(2, static_cast(Clamp16(m_voices[1].last_volume))); WriteToCaptureBuffer(3, static_cast(Clamp16(m_voices[3].last_volume))); IncrementCaptureBufferPosition(); + + // Key off/on voices after the first frame. + if (i == 0 && (m_key_off_register != 0 || m_key_on_register != 0)) + { + u32 key_off_register = m_key_off_register; + m_key_off_register = 0; + + u32 key_on_register = m_key_on_register; + m_key_on_register = 0; + + for (u32 voice = 0; voice < NUM_VOICES; voice++) + { + if (key_off_register & 1u) + m_voices[voice].KeyOff(); + key_off_register >>= 1; + + if (key_on_register & 1u) + { + m_endx_register &= ~(1u << voice); + m_voices[voice].KeyOn(); + } + key_on_register >>= 1; + } + } } if (m_dump_writer)