shithub: choc

Download patch

ref: 080ed4ee4324fa873b4049f5cda8749d9bd801c7
parent: b33ff7e96c5c410f722808314579810f23c86cd8
author: NY00123 <NY00123@users.noreply.github.com>
date: Fri Jan 20 04:41:23 EST 2023

pcsound: Partial fix for #795 #866 (#866)


--- a/pcsound/pcsound_linux.c
+++ b/pcsound/pcsound_linux.c
@@ -89,6 +89,7 @@
 
 static int SoundThread(void *unused)
 {
+    int current_freq = 0;
     int frequency;
     int duration;
     int cycles;
@@ -97,16 +98,20 @@
     {
         callback(&duration, &frequency);
 
-        if (frequency != 0) 
+        if (current_freq != frequency)
         {
-            cycles = PCSOUND_8253_FREQUENCY / frequency;
-        }
-        else
-        {
-            cycles = 0;
-        }
+            current_freq = frequency;
+            if (frequency != 0)
+            {
+                cycles = PCSOUND_8253_FREQUENCY / frequency;
+            }
+            else
+            {
+                cycles = 0;
+            }
 
-        ioctl(console_handle, KIOCSOUND, cycles);
+            ioctl(console_handle, KIOCSOUND, cycles);
+        }
 
         AdjustedSleep(duration);
     }
--- a/pcsound/pcsound_sdl.c
+++ b/pcsound/pcsound_sdl.c
@@ -62,7 +62,7 @@
     Sint16 *leftptr;
     Sint16 *rightptr;
     Sint16 this_value;
-    int oldfreq;
+    int frequency;
     int i;
     int nsamples;
 
@@ -82,19 +82,14 @@
 
         while (current_remaining == 0) 
         {
-            oldfreq = current_freq;
-
             // Get the next frequency to play
 
-            callback(&current_remaining, &current_freq);
+            callback(&current_remaining, &frequency);
 
-            if (current_freq != 0)
+            if (current_freq != frequency)
             {
-                // Adjust phase to match to the new frequency.
-                // This gives us a smooth transition between different tones,
-                // with no impulse changes.
-
-                phase_offset = (phase_offset * oldfreq) / current_freq;
+                current_freq = frequency;
+                phase_offset = 0;
             }
 
             current_remaining = (current_remaining * mixing_freq) / 1000;