summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2007-05-19 16:42:56 +0000
committerSimon Howard2007-05-19 16:42:56 +0000
commit64c188aa8ea658f3ea623990a50f68af4e6e618d (patch)
tree37e9e0587267ea3f9ab4cb79c8560a9538abbeba
parent2a026e12779b77b2aeabb78bdca3ea00e10d478a (diff)
downloadchocolate-doom-64c188aa8ea658f3ea623990a50f68af4e6e618d.tar.gz
chocolate-doom-64c188aa8ea658f3ea623990a50f68af4e6e618d.tar.bz2
chocolate-doom-64c188aa8ea658f3ea623990a50f68af4e6e618d.zip
Fix tempo problems in pcsound linux driver.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 878
-rw-r--r--pcsound/pcsound_linux.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/pcsound/pcsound_linux.c b/pcsound/pcsound_linux.c
index df2015d5..7c1abc7b 100644
--- a/pcsound/pcsound_linux.c
+++ b/pcsound/pcsound_linux.c
@@ -47,6 +47,52 @@ static int console_handle;
static pcsound_callback_func callback;
static int sound_thread_running = 0;
static SDL_Thread *sound_thread_handle;
+static int sleep_adjust = 0;
+
+static void AdjustedSleep(unsigned int ms)
+{
+ unsigned int start_time;
+ unsigned int end_time;
+ unsigned int actual_time;
+
+ // Adjust based on previous error to keep the tempo right
+
+ if (sleep_adjust > ms)
+ {
+ sleep_adjust -= ms;
+ return;
+ }
+ else
+ {
+ ms -= sleep_adjust;
+ }
+
+ // Do the sleep and record how long it takes
+
+ start_time = SDL_GetTicks();
+
+ SDL_Delay(ms);
+
+ end_time = SDL_GetTicks();
+
+ if (end_time > start_time)
+ {
+ actual_time = end_time - start_time;
+ }
+ else
+ {
+ actual_time = ms;
+ }
+
+ if (actual_time < ms)
+ {
+ actual_time = ms;
+ }
+
+ // Save sleep_adjust for next time
+
+ sleep_adjust = actual_time - ms;
+}
static int SoundThread(void *unused)
{
@@ -69,7 +115,7 @@ static int SoundThread(void *unused)
ioctl(console_handle, KIOCSOUND, cycles);
- usleep(duration * 1000);
+ AdjustedSleep(duration);
}
return 0;