@geastack/host 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/host/audio_worklet.cpp +19 -0
- package/host/timers.cpp +19 -4
- package/package.json +1 -1
package/host/audio_worklet.cpp
CHANGED
|
@@ -20,6 +20,15 @@
|
|
|
20
20
|
#else
|
|
21
21
|
#include <thread>
|
|
22
22
|
#endif
|
|
23
|
+
#if defined(_WIN32) && !defined(ESP_PLATFORM)
|
|
24
|
+
#ifndef NOMINMAX
|
|
25
|
+
#define NOMINMAX
|
|
26
|
+
#endif
|
|
27
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
28
|
+
#define WIN32_LEAN_AND_MEAN
|
|
29
|
+
#endif
|
|
30
|
+
#include <windows.h>
|
|
31
|
+
#endif
|
|
23
32
|
|
|
24
33
|
namespace gea::host::audio_worklet {
|
|
25
34
|
namespace {
|
|
@@ -337,6 +346,16 @@ struct ContextState : std::enable_shared_from_this<ContextState> {
|
|
|
337
346
|
// This entry owns its periodic render loop; runPending services only its
|
|
338
347
|
// bounded messages between process calls, never on the UI or mixer task.
|
|
339
348
|
realm->start([self] {
|
|
349
|
+
#if defined(_WIN32) && !defined(ESP_PLATFORM)
|
|
350
|
+
// The render loop is the graph's audio clock, which ESP runs at its top
|
|
351
|
+
// task priority (above). Windows would leave it at normal priority, and
|
|
352
|
+
// it does not favour a thread waking from its 1 ms sleep over ready
|
|
353
|
+
// threads of equal priority: on a busy host every wake queued behind
|
|
354
|
+
// them, the loop fell seconds behind its quanta and capture overran.
|
|
355
|
+
// Time-critical is the level Windows audio engines give render threads;
|
|
356
|
+
// the bounded batch and the sleep below still yield every iteration.
|
|
357
|
+
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
|
358
|
+
#endif
|
|
340
359
|
active = self.get();
|
|
341
360
|
{ std::lock_guard lock(self->readyMutex); self->ready = true; }
|
|
342
361
|
self->readySignal.notify_all();
|
package/host/timers.cpp
CHANGED
|
@@ -88,9 +88,15 @@ struct ScheduledTimer {
|
|
|
88
88
|
|
|
89
89
|
class TimerScheduler {
|
|
90
90
|
public:
|
|
91
|
+
// Function-local statics are read through an acquire-loaded pointer: on
|
|
92
|
+
// targets without hardware atomics (ESP32-S3) each guarded access takes an
|
|
93
|
+
// RTOS mutex, and these run on every frame.
|
|
91
94
|
static TimerScheduler &instance()
|
|
92
95
|
{
|
|
96
|
+
static std::atomic<TimerScheduler *> ready{nullptr};
|
|
97
|
+
if (auto *scheduler = ready.load(std::memory_order_acquire)) return *scheduler;
|
|
93
98
|
static TimerScheduler scheduler;
|
|
99
|
+
ready.store(&scheduler, std::memory_order_release);
|
|
94
100
|
return scheduler;
|
|
95
101
|
}
|
|
96
102
|
|
|
@@ -197,7 +203,11 @@ class AnimationFrameQueue {
|
|
|
197
203
|
public:
|
|
198
204
|
static AnimationFrameQueue &instance()
|
|
199
205
|
{
|
|
206
|
+
// See TimerScheduler::instance().
|
|
207
|
+
static std::atomic<AnimationFrameQueue *> ready{nullptr};
|
|
208
|
+
if (auto *queue = ready.load(std::memory_order_acquire)) return *queue;
|
|
200
209
|
static AnimationFrameQueue queue;
|
|
210
|
+
ready.store(&queue, std::memory_order_release);
|
|
201
211
|
return queue;
|
|
202
212
|
}
|
|
203
213
|
|
|
@@ -279,11 +289,16 @@ private:
|
|
|
279
289
|
// call sites on this so the strings are only built when logging is actually on.
|
|
280
290
|
static bool debugLoggingEnabled()
|
|
281
291
|
{
|
|
282
|
-
|
|
292
|
+
// Constant-initialized, so no guard: -1 until the first read. Racing
|
|
293
|
+
// first reads compute the same value.
|
|
294
|
+
static std::atomic<signed char> enabled{-1};
|
|
295
|
+
signed char value = enabled.load(std::memory_order_relaxed);
|
|
296
|
+
if (value < 0) {
|
|
283
297
|
const char *p = std::getenv("GEA_RAF_DEBUG_LOG");
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
298
|
+
value = p && p[0] != '\0' ? 1 : 0;
|
|
299
|
+
enabled.store(value, std::memory_order_relaxed);
|
|
300
|
+
}
|
|
301
|
+
return value != 0;
|
|
287
302
|
}
|
|
288
303
|
|
|
289
304
|
void logDebug(const std::string &message)
|