aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/alc.cpp22
-rw-r--r--Alc/alu.cpp2
-rw-r--r--Alc/backends/base.cpp2
-rw-r--r--Alc/backends/base.h11
-rw-r--r--OpenAL32/Include/alMain.h5
5 files changed, 29 insertions, 13 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 42856dbf..a5238aa5 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -1682,8 +1682,13 @@ static struct Compressor *CreateDeviceLimiter(const ALCdevice *device, const ALf
*/
static inline void UpdateClockBase(ALCdevice *device)
{
+ using std::chrono::seconds;
+ using std::chrono::nanoseconds;
+ using std::chrono::duration_cast;
+
IncrementRef(&device->MixCount);
- device->ClockBase += device->SamplesDone * DEVICE_CLOCK_RES / device->Frequency;
+ device->ClockBase += duration_cast<nanoseconds>(seconds{device->SamplesDone}) /
+ device->Frequency;
device->SamplesDone = 0;
IncrementRef(&device->MixCount);
}
@@ -2006,7 +2011,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->MixBuffer.shrink_to_fit();
UpdateClockBase(device);
- device->FixedLatency = 0;
+ device->FixedLatency = std::chrono::nanoseconds::zero();
device->DitherSeed = DITHER_RNG_SEED;
@@ -2222,8 +2227,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
thrshld -= 1.0f / device->DitherDepth;
device->Limiter.reset(CreateDeviceLimiter(device, std::log10(thrshld) * 20.0f));
- device->FixedLatency += (ALuint)(GetCompressorLookAhead(device->Limiter.get()) *
- DEVICE_CLOCK_RES / device->Frequency);
+ /* Convert the lookahead from samples to nanosamples to nanoseconds. */
+ device->FixedLatency += std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::seconds(GetCompressorLookAhead(device->Limiter.get()))
+ ) / device->Frequency;
}
else
device->Limiter = nullptr;
@@ -2231,7 +2238,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
aluSelectPostProcess(device);
- TRACE("Fixed device latency: %uns\n", device->FixedLatency);
+ TRACE("Fixed device latency: %ldns\n", (long)device->FixedLatency.count());
/* Need to delay returning failure until replacement Send arrays have been
* allocated with the appropriate size.
@@ -3420,7 +3427,7 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
case ALC_DEVICE_CLOCK_SOFT:
{ std::lock_guard<almtx_t> _{device->BackendLock};
- ALuint64 basecount;
+ std::chrono::nanoseconds basecount;
ALuint samplecount;
ALuint refcount;
do {
@@ -3429,7 +3436,8 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
basecount = device->ClockBase;
samplecount = device->SamplesDone;
} while(refcount != ReadRef(&device->MixCount));
- *values = basecount + (samplecount*DEVICE_CLOCK_RES/device->Frequency);
+ *values = (basecount + std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::seconds{samplecount}) / device->Frequency).count();
}
break;
diff --git a/Alc/alu.cpp b/Alc/alu.cpp
index fc386908..6587ab39 100644
--- a/Alc/alu.cpp
+++ b/Alc/alu.cpp
@@ -1758,7 +1758,7 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples)
* overflow during conversion. This also guarantees an exact, stable
* conversion. */
device->SamplesDone += SamplesToDo;
- device->ClockBase += (device->SamplesDone/device->Frequency) * DEVICE_CLOCK_RES;
+ device->ClockBase += std::chrono::seconds{device->SamplesDone / device->Frequency};
device->SamplesDone %= device->Frequency;
IncrementRef(&device->MixCount);
diff --git a/Alc/backends/base.cpp b/Alc/backends/base.cpp
index f3a4c60e..1839d353 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;
+ ret.Latency += device->FixedLatency.count();
return ret;
}
diff --git a/Alc/backends/base.h b/Alc/backends/base.h
index 61b71a47..db2127ef 100644
--- a/Alc/backends/base.h
+++ b/Alc/backends/base.h
@@ -7,6 +7,9 @@
#include <mutex>
struct ClockLatency {
+ /* FIXME: These should be nanoseconds. Will require changing backends that
+ * provide this info.
+ */
ALint64 ClockTime;
ALint64 Latency;
};
@@ -16,8 +19,12 @@ struct ClockLatency {
*/
inline ALuint64 GetDeviceClockTime(ALCdevice *device)
{
- return device->ClockBase + (device->SamplesDone * DEVICE_CLOCK_RES /
- device->Frequency);
+ 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();
}
void ALCdevice_Lock(ALCdevice *device);
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 744e3609..036d4ec3 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -19,6 +19,7 @@
#include <array>
#include <vector>
#include <string>
+#include <chrono>
#include "AL/al.h"
#include "AL/alc.h"
@@ -690,9 +691,9 @@ struct ALCdevice_struct {
// Device flags
ALuint Flags{0u};
- ALuint64 ClockBase{0u};
ALuint SamplesDone{0u};
- ALuint FixedLatency{0u};
+ std::chrono::nanoseconds ClockBase{0};
+ std::chrono::nanoseconds FixedLatency{0};
/* Temp storage used for mixer processing. */
alignas(16) ALfloat TempBuffer[4][BUFFERSIZE];