diff options
author | Chris Robinson <[email protected]> | 2018-11-22 14:32:48 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-22 14:32:48 -0800 |
commit | d26b5d94677a7091d95972cbfd4337fb36a5e622 (patch) | |
tree | ea4a4a6133be65473914082ed314e4ea98dc20ef /Alc/backends | |
parent | 84f0f74d0794b38d1b1bb0021090d50f2648e0ce (diff) |
Use proper time types for the device clock time and latency
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/alsa.cpp | 6 | ||||
-rw-r--r-- | Alc/backends/base.cpp | 6 | ||||
-rw-r--r-- | Alc/backends/base.h | 12 | ||||
-rw-r--r-- | Alc/backends/jack.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/opensl.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/pulseaudio.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/wasapi.cpp | 4 |
7 files changed, 20 insertions, 20 deletions
diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp index e1e861db..35c1f834 100644 --- a/Alc/backends/alsa.cpp +++ b/Alc/backends/alsa.cpp @@ -915,7 +915,8 @@ ClockLatency ALCplaybackAlsa_getClockLatency(ALCplaybackAlsa *self) ERR("Failed to get pcm delay: %s\n", snd_strerror(err)); delay = 0; } - ret.Latency = std::max<snd_pcm_sframes_t>(0, delay) * DEVICE_CLOCK_RES / device->Frequency; + ret.Latency = std::chrono::seconds{std::max<snd_pcm_sframes_t>(0, delay)}; + ret.Latency /= device->Frequency; ALCplaybackAlsa_unlock(self); return ret; @@ -1286,7 +1287,8 @@ ClockLatency ALCcaptureAlsa_getClockLatency(ALCcaptureAlsa *self) ERR("Failed to get pcm delay: %s\n", snd_strerror(err)); delay = 0; } - ret.Latency = std::max<snd_pcm_sframes_t>(0, delay) * DEVICE_CLOCK_RES / device->Frequency; + ret.Latency = std::chrono::seconds{std::max<snd_pcm_sframes_t>(0, delay)}; + ret.Latency /= device->Frequency; ALCcaptureAlsa_unlock(self); return ret; diff --git a/Alc/backends/base.cpp b/Alc/backends/base.cpp index 1839d353..e4c7588c 100644 --- a/Alc/backends/base.cpp +++ b/Alc/backends/base.cpp @@ -18,7 +18,7 @@ void ALCdevice_Unlock(ALCdevice *device) ClockLatency GetClockLatency(ALCdevice *device) { ClockLatency ret = V0(device->Backend,getClockLatency)(); - ret.Latency += device->FixedLatency.count(); + ret.Latency += device->FixedLatency; return ret; } @@ -65,8 +65,8 @@ ClockLatency ALCbackend_getClockLatency(ALCbackend *self) * any given time during playback. Without a more accurate measurement from * the output, this is an okay approximation. */ - ret.Latency = device->UpdateSize * DEVICE_CLOCK_RES / device->Frequency * - maxu(device->NumUpdates-1, 1); + ret.Latency = std::chrono::seconds{device->UpdateSize*maxi(device->NumUpdates-1, 0)}; + ret.Latency /= device->Frequency; return ret; } diff --git a/Alc/backends/base.h b/Alc/backends/base.h index db2127ef..f4de5176 100644 --- a/Alc/backends/base.h +++ b/Alc/backends/base.h @@ -3,28 +3,26 @@ #include "alMain.h" +#include <chrono> #include <string> #include <mutex> struct ClockLatency { - /* FIXME: These should be nanoseconds. Will require changing backends that - * provide this info. - */ - ALint64 ClockTime; - ALint64 Latency; + std::chrono::nanoseconds ClockTime; + std::chrono::nanoseconds Latency; }; /* Helper to get the current clock time from the device's ClockBase, and * SamplesDone converted from the sample rate. */ -inline ALuint64 GetDeviceClockTime(ALCdevice *device) +inline std::chrono::nanoseconds GetDeviceClockTime(ALCdevice *device) { using std::chrono::seconds; using std::chrono::nanoseconds; using std::chrono::duration_cast; auto ns = duration_cast<nanoseconds>(seconds{device->SamplesDone}) / device->Frequency; - return (device->ClockBase + ns).count(); + return device->ClockBase + ns; } void ALCdevice_Lock(ALCdevice *device); diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp index 93dbaf13..cd02388d 100644 --- a/Alc/backends/jack.cpp +++ b/Alc/backends/jack.cpp @@ -503,8 +503,8 @@ static ClockLatency ALCjackPlayback_getClockLatency(ALCjackPlayback *self) ALCjackPlayback_lock(self); ret.ClockTime = GetDeviceClockTime(device); - ret.Latency = ll_ringbuffer_read_space(self->Ring) * DEVICE_CLOCK_RES / - device->Frequency; + ret.Latency = std::chrono::seconds{ll_ringbuffer_read_space(self->Ring)}; + ret.Latency /= device->Frequency; ALCjackPlayback_unlock(self); return ret; diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp index 2c516021..f7ad1595 100644 --- a/Alc/backends/opensl.cpp +++ b/Alc/backends/opensl.cpp @@ -654,8 +654,8 @@ static ClockLatency ALCopenslPlayback_getClockLatency(ALCopenslPlayback *self) ALCopenslPlayback_lock(self); ret.ClockTime = GetDeviceClockTime(device); - ret.Latency = ll_ringbuffer_read_space(self->mRing)*device->UpdateSize * - DEVICE_CLOCK_RES / device->Frequency; + ret.Latency = std::chrono::seconds{ll_ringbuffer_read_space(self->mRing)*device->UpdateSize}; + ret.Latency /= device->Frequency; ALCopenslPlayback_unlock(self); return ret; diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp index d0c1c229..9563cdd4 100644 --- a/Alc/backends/pulseaudio.cpp +++ b/Alc/backends/pulseaudio.cpp @@ -1213,7 +1213,7 @@ ClockLatency PulsePlayback_getClockLatency(PulsePlayback *self) } else if(UNLIKELY(neg)) latency = 0; - ret.Latency = (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000; + ret.Latency = std::chrono::microseconds{latency}; return ret; } @@ -1714,7 +1714,7 @@ ClockLatency PulseCapture_getClockLatency(PulseCapture *self) } else if(UNLIKELY(neg)) latency = 0; - ret.Latency = (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000; + ret.Latency = std::chrono::microseconds{latency}; return ret; } diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp index e531a9ae..52f324f7 100644 --- a/Alc/backends/wasapi.cpp +++ b/Alc/backends/wasapi.cpp @@ -1145,8 +1145,8 @@ ClockLatency ALCwasapiPlayback_getClockLatency(ALCwasapiPlayback *self) ALCwasapiPlayback_lock(self); ALCdevice *device{STATIC_CAST(ALCbackend, self)->mDevice}; ret.ClockTime = GetDeviceClockTime(device); - ret.Latency = self->mPadding.load(std::memory_order_relaxed) * DEVICE_CLOCK_RES / - device->Frequency; + ret.Latency = std::chrono::seconds{self->mPadding.load(std::memory_order_relaxed)}; + ret.Latency /= device->Frequency; ALCwasapiPlayback_unlock(self); return ret; |