sound, fix minor clipping in psg audio
authorkub <derkub@gmail.com>
Tue, 28 Sep 2021 19:10:02 +0000 (21:10 +0200)
committerkub <derkub@gmail.com>
Tue, 28 Sep 2021 19:10:02 +0000 (21:10 +0200)
pico/sound/sn76496.c

index c84bd16..27764a9 100644 (file)
@@ -90,6 +90,7 @@ 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
+                       if (R->Count[c] > R->Period[c]) R->Count[c] = R->Period[c];\r
                        if (r == 4)\r
                        {\r
                                /* update noise shift frequency */\r
@@ -155,8 +156,9 @@ void SN76496Update(short *buffer, int length, int stereo)
                        /* 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->Volume[i] == 0) {\r
-                               /* Cut of anything above the Nyquist freqency */\r
-                               /* It will only create aliasing anyway */\r
+                               /* Cut off anything above the Nyquist frequency. */\r
+                               /* It will only create aliasing anyway. This is actually an */\r
+                               /* ideal lowpass filter with Nyquist corner frequency. */\r
                                vol[i] += STEP/2; // mean value\r
                                R->Count[i] = R->Output[i] = 0;\r
                        }\r