sound, fix psg audio (missed commit)
authorkub <derkub@gmail.com>
Sat, 25 Sep 2021 06:27:32 +0000 (08:27 +0200)
committerkub <derkub@gmail.com>
Sat, 25 Sep 2021 06:38:45 +0000 (08:38 +0200)
pico/sound/sn76496.c

index b4a8847..c84bd16 100644 (file)
@@ -90,7 +90,6 @@ void SN76496Write(int data)
                case 4: /* tone 2 : frequency */\r
                        R->Period[c] = R->UpdateStep * data;\r
                        if (R->Period[c] == 0) R->Period[c] = R->UpdateStep;\r
-                       R->Count[c] = 0;\r
                        if (r == 4)\r
                        {\r
                                /* update noise shift frequency */\r
@@ -109,8 +108,7 @@ void SN76496Write(int data)
                        R->NoiseFB = (n & 4) ? FB_WNOISE : FB_PNOISE;\r
                        n &= 3;\r
                        /* N/512,N/1024,N/2048,Tone #3 output */\r
-                       R->Period[3] = (n == 3) ? 2 * R->Period[2] : (R->UpdateStep << (4 + n));\r
-                       R->Count[3] = 0;\r
+                       R->Period[3] = 2 * (n == 3 ? R->Period[2] : R->UpdateStep << (4 + n));\r
 \r
                        /* reset noise shifter */\r
                        R->RNG = FB_PNOISE;\r
@@ -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 */\r
                        /* and vol[i] incremented only if the exit status of the square */\r
                        /* wave is 1. */\r
-                       if (R->Count[i] < -2*R->Period[i]) {\r
+                       if (R->Count[i] < -2*R->Period[i] || R->Volume[i] == 0) {\r
                                /* Cut of anything above the Nyquist freqency */\r
                                /* It will only create aliasing anyway */\r
                                vol[i] += STEP/2; // mean value\r
@@ -200,7 +198,7 @@ void SN76496Update(short *buffer, int length, int stereo)
                        }\r
 \r
                        left -= nextevent;\r
-               } while (left > 0);\r
+               } while (left > 0 && R->Volume[3]);\r
                if (R->Output[3]) vol[3] -= R->Count[3];\r
 \r
                out = vol[0] * R->Volume[0] + vol[1] * R->Volume[1] +\r