aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/null.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-08-02 20:04:52 -0700
committerChris Robinson <[email protected]>2010-08-02 20:04:52 -0700
commitae41ad5d1ed2c9b41cf5bbb7aa78848a043ee1f8 (patch)
treedbbcb4e8df821f6d9b738c7b9f1bde2c48fda078 /Alc/null.c
parentee61f7a55caabec6f9c1394ce84e343d940cab92 (diff)
Use a better method to time the Null and Wave Writer backends
This better compensates for precision loss when converting milliseconds to the sample rate
Diffstat (limited to 'Alc/null.c')
-rw-r--r--Alc/null.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/Alc/null.c b/Alc/null.c
index 43a10624..c110b3ae 100644
--- a/Alc/null.c
+++ b/Alc/null.c
@@ -30,6 +30,8 @@ typedef struct {
ALvoid *buffer;
ALuint size;
+ ALuint startTime;
+
volatile int killNow;
ALvoid *thread;
} null_data;
@@ -41,30 +43,34 @@ static ALuint NullProc(ALvoid *ptr)
{
ALCdevice *Device = (ALCdevice*)ptr;
null_data *data = (null_data*)Device->ExtraData;
- ALuint frameSize;
- ALuint now, last;
- ALuint avail;
-
- frameSize = aluFrameSizeFromFormat(Device->Format);
+ ALuint now, start;
+ ALuint64 avail, done;
+ const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 /
+ Device->Frequency / 2;
- last = timeGetTime()<<8;
+ done = 0;
+ start = data->startTime;
while(!data->killNow && Device->Connected)
{
- now = timeGetTime()<<8;
+ now = timeGetTime();
- avail = (ALuint64)(now-last) * Device->Frequency / (1000<<8);
- if(avail < Device->UpdateSize)
+ avail = (ALuint64)(now-start) * Device->Frequency / 1000;
+ if(avail < done)
{
- Sleep(1);
+ AL_PRINT("Timer wrapped\n");
+ aluHandleDisconnect(Device);
+ break;
+ }
+ if(avail-done < Device->UpdateSize)
+ {
+ Sleep(restTime);
continue;
}
- while(avail >= Device->UpdateSize)
+ while(avail-done >= Device->UpdateSize)
{
aluMixData(Device, data->buffer, Device->UpdateSize);
-
- avail -= Device->UpdateSize;
- last += (ALuint64)Device->UpdateSize * (1000<<8) / Device->Frequency;
+ done += Device->UpdateSize;
}
}
@@ -111,6 +117,7 @@ static ALCboolean null_reset_playback(ALCdevice *device)
device->TimeRes = (ALuint64)device->UpdateSize * 1000000000 /
device->Frequency;
+ data->startTime = timeGetTime();
data->thread = StartThread(NullProc, device);
if(data->thread == NULL)
{