From fa0c5b4539fe135e49fee7f3b4e6f38835b87925 Mon Sep 17 00:00:00 2001 From: kub Date: Sat, 25 Sep 2021 08:27:32 +0200 Subject: [PATCH] sound, fix psg audio (missed commit) --- pico/sound/sn76496.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pico/sound/sn76496.c b/pico/sound/sn76496.c index b4a8847f..c84bd16a 100644 --- a/pico/sound/sn76496.c +++ b/pico/sound/sn76496.c @@ -90,7 +90,6 @@ void SN76496Write(int data) case 4: /* tone 2 : frequency */ R->Period[c] = R->UpdateStep * data; if (R->Period[c] == 0) R->Period[c] = R->UpdateStep; - R->Count[c] = 0; if (r == 4) { /* update noise shift frequency */ @@ -109,8 +108,7 @@ void SN76496Write(int data) R->NoiseFB = (n & 4) ? FB_WNOISE : FB_PNOISE; n &= 3; /* N/512,N/1024,N/2048,Tone #3 output */ - R->Period[3] = (n == 3) ? 2 * R->Period[2] : (R->UpdateStep << (4 + n)); - R->Count[3] = 0; + R->Period[3] = 2 * (n == 3 ? R->Period[2] : R->UpdateStep << (4 + n)); /* reset noise shifter */ R->RNG = FB_PNOISE; @@ -156,7 +154,7 @@ void SN76496Update(short *buffer, int length, int stereo) /* If we exit the loop in the middle, Output[i] has to be inverted */ /* and vol[i] incremented only if the exit status of the square */ /* wave is 1. */ - if (R->Count[i] < -2*R->Period[i]) { + if (R->Count[i] < -2*R->Period[i] || R->Volume[i] == 0) { /* Cut of anything above the Nyquist freqency */ /* It will only create aliasing anyway */ vol[i] += STEP/2; // mean value @@ -200,7 +198,7 @@ void SN76496Update(short *buffer, int length, int stereo) } left -= nextevent; - } while (left > 0); + } while (left > 0 && R->Volume[3]); if (R->Output[3]) vol[3] -= R->Count[3]; out = vol[0] * R->Volume[0] + vol[1] * R->Volume[1] + -- 2.39.5