aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/device.cpp3
-rw-r--r--core/device.h18
2 files changed, 19 insertions, 2 deletions
diff --git a/core/device.cpp b/core/device.cpp
index 2766c5e4..a5edf63c 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -9,6 +9,9 @@
#include "mastering.h"
+static_assert(std::atomic<std::chrono::nanoseconds>::is_always_lock_free);
+
+
al::FlexArray<ContextBase*> DeviceBase::sEmptyContextArray{0u};
diff --git a/core/device.h b/core/device.h
index 8abbef21..842f1d82 100644
--- a/core/device.h
+++ b/core/device.h
@@ -218,8 +218,8 @@ struct DeviceBase {
*/
NfcFilter mNFCtrlFilter{};
- uint SamplesDone{0u};
- std::chrono::nanoseconds ClockBase{0};
+ std::atomic<uint> mSamplesDone{0u};
+ std::atomic<std::chrono::nanoseconds> mClockBase{std::chrono::nanoseconds{}};
std::chrono::nanoseconds FixedLatency{0};
AmbiRotateMatrix mAmbiRotateMatrix{};
@@ -307,6 +307,20 @@ struct DeviceBase {
return refcount;
}
+ /**
+ * Helper to get the current clock time from the device's ClockBase, and
+ * SamplesDone converted from the sample rate. Should only be called while
+ * watching the MixCount.
+ */
+ std::chrono::nanoseconds getClockTime() const noexcept
+ {
+ using std::chrono::seconds;
+ using std::chrono::nanoseconds;
+
+ auto ns = nanoseconds{seconds{mSamplesDone.load(std::memory_order_relaxed)}} / Frequency;
+ return mClockBase.load(std::memory_order_relaxed) + ns;
+ }
+
void ProcessHrtf(const size_t SamplesToDo);
void ProcessAmbiDec(const size_t SamplesToDo);
void ProcessAmbiDecStablized(const size_t SamplesToDo);