diff options
author | Chris Robinson <[email protected]> | 2014-04-17 09:03:57 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-04-17 09:03:57 -0700 |
commit | d1f1a1d056b654bbe52c0b1ba6752b7a106482e1 (patch) | |
tree | e549f65f02cc97be3f42e9165a3407d9fcbc5abe /Alc/backends/null.c | |
parent | 47f5c436c8f5e55ebafd72dcd155b2a762bb18ca (diff) |
Make and use a C11-like altimespec_get wrapper function
Diffstat (limited to 'Alc/backends/null.c')
-rw-r--r-- | Alc/backends/null.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/Alc/backends/null.c b/Alc/backends/null.c index 26e63b2e..a96ab701 100644 --- a/Alc/backends/null.c +++ b/Alc/backends/null.c @@ -72,38 +72,45 @@ static int ALCnullBackend_mixerProc(void *ptr) { ALCnullBackend *self = (ALCnullBackend*)ptr; ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; - ALuint now, start; + struct timespec now, start; ALuint64 avail, done; + const long restTime = (long)((ALuint64)device->UpdateSize * 1000000000 / + device->Frequency / 2); SetRTPriority(); SetThreadName(MIXER_THREAD_NAME); done = 0; - start = timeGetTime(); + if(altimespec_get(&start, AL_TIME_UTC) != AL_TIME_UTC) + { + ERR("Failed to get starting time\n"); + return 1; + } while(!self->killNow && device->Connected) { - now = timeGetTime(); + if(altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC) + { + ERR("Failed to get current time\n"); + return 1; + } - avail = (ALuint64)(now-start) * device->Frequency / 1000; + avail = (now.tv_sec - start.tv_sec) * device->Frequency; + avail += (ALint64)(now.tv_nsec - start.tv_nsec) * device->Frequency / 1000000000; if(avail < done) { - /* Timer wrapped (50 days???). Add the remainder of the cycle to - * the available count and reset the number of samples done */ - avail += (U64(1)<<32)*device->Frequency/1000 - done; - done = 0; + /* Oops, time skipped backwards. Reset the number of samples done + * with one update available since we (likely) just came back from + * sleeping. */ + done = avail - device->UpdateSize; } + if(avail-done < device->UpdateSize) - { - long restTime = (long)((device->UpdateSize - (avail-done)) * 1000000000 / - device->Frequency); al_nssleep(0, restTime); - continue; - } - - do { + else while(avail-done >= device->UpdateSize) + { aluMixData(device, NULL, device->UpdateSize); done += device->UpdateSize; - } while(avail-done >= device->UpdateSize); + } } return 0; |