From 0cddc469bca910ad4b3e1fffdb9b798ebde27632 Mon Sep 17 00:00:00 2001 From: Ivo Wetzel Date: Thu, 16 Aug 2018 05:05:50 +0200 Subject: [PATCH] Fix Freeboy noise channel playback (#4538) Writing the enable bit to `FF23` causes the noise oscillator to start outputting samples and writing the other registers (including the one for the SRW value) during the time the oscillator is active has undefined behaviour. In order for `GB_apu` to correctly generate samples when the LSFR width is set to `7`, the trigger write to `0xff23` must happen after all other writes. --- plugins/papu/papu_instrument.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/papu/papu_instrument.cpp b/plugins/papu/papu_instrument.cpp index b555310a0..b9c1b28ae 100644 --- a/plugins/papu/papu_instrument.cpp +++ b/plugins/papu/papu_instrument.cpp @@ -276,9 +276,6 @@ void papuInstrument::playNote( NotePlayHandle * _n, data += m_ch4SweepStepLengthModel.value(); papu->write_register( 0xff21, data ); - //channel 4 init - papu->write_register( 0xff23, 128 ); - _n->m_pluginData = papu; } @@ -380,6 +377,10 @@ void papuInstrument::playNote( NotePlayHandle * _n, data = data << 3; data += ropt; papu->write_register( 0xff22, data ); + + //channel 4 init + papu->write_register( 0xff23, 128 ); + } int const buf_size = 2048;