UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioMixerClockManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "AudioMixerClock.h"
7
8namespace Audio
9{
10 // forwards
11 class FMixerDevice;
12 class FQuartzClock;
13 class FQuartzClockManager;
14
15 // Class that owns, updates, and provides access to all active clocks
16 // All methods are thread-safe. The method locks if it returns a value, and stages a command if it returns void
18 {
19 public:
20 // ctor
22
23 // dtor
25
26 int32 GetNumClocks() const { return ActiveClocks.Num(); }
27
28 // Called on AudioRenderThread
31
32 // can be called from any thread for low-resolution clock updates
33 // (i.e. used when running without an audio device)
34 // not sample-accurate!
35 AUDIOMIXER_API void LowResoultionUpdate(float DeltaTimeSeconds);
36
37 // add (and take ownership of) a new clock
38 // safe to call from AudioThread (uses critical section)
41
42 // returns true if a clock with the given name already exists.
44
45 // returns true if the name is running
47
48 // Returns the duration in seconds of the given Quantization Type, or -1 if the Clock is invalid or nonexistent
50
51 // Returns the current location of the clock in the transport
53
54 // Returns the amount of time, in seconds, the clock has been running. Caution: due to latency, this will not be perfectly accurate
56
57 // remove existing clock
58 // safe to call from AudioThread (uses Audio Render Thread Command)
59 AUDIOMIXER_API void RemoveClock(const FName& InName, bool bForceSynchronous = false);
60
61 // get Tick rate for clock
62 // safe to call from AudioThread (uses critical section)
63 AUDIOMIXER_API FQuartzClockTickRate GetTickRateForClock(const FName& InName);
64
65 AUDIOMIXER_API void SetTickRateForClock(const FQuartzClockTickRate& InNewTickRate, const FName& InName);
66
67 // start the given clock
68 // safe to call from AudioThread (uses Audio Render Thread command)
70
71 // stop the given clock
72 // safe to call from AudioThread (uses Audio Render Thread command)
73 AUDIOMIXER_API void StopClock(const FName& InName, bool CancelPendingEvents);
74
75 // stop the given clock
76 // safe to call from AudioThread (uses Audio Render Thread command)
77 AUDIOMIXER_API void PauseClock(const FName& InName);
78
79 // shutdown all clocks that don't ignore Flush() (i.e. level change)
80 AUDIOMIXER_API void Flush();
81
82 // stop all clocks and cancel all pending events
84
85 // add a new command to a given clock
86 // safe to call from AudioThread (uses Audio Render Thread command)
88
89 // subscribe to a specific time division on a clock
90 // TODO: update the metronome subscription functions to take an FQuartzGameThreadSubscriber instead of the Command queue ptr
91 // (to support metronome event offset)
93
94 // subscribe to all time divisions on a clock
96
97 // un-subscribe from a specific time division on a clock
99
100 // un-subscribe from all time divisions on a specific clock
102
103 // cancel a queued command on a clock (i.e. cancel a PlayQuantized command if the sound is stopped before it is played)
105
107
108 int32 GetLastUpdateSizeInFrames() const { return LastUpdateSizeInFrames; }
109
110 // get access to the owning FMixerDevice
112
113 private:
114 // updates all active clocks
115 AUDIOMIXER_API void TickClocks(int32 NumFramesToTick);
116
117 // find clock with a given key
118 AUDIOMIXER_API TSharedPtr<FQuartzClock> FindClock(const FName& InName);
119
120 // pointer to owning FMixerDevice
121 FMixerDevice* MixerDevice;
122
123 // Container of active clocks
124 FCriticalSection ActiveClockCritSec;
125
126 // Our array of active clocks (mutation/access acquires clock)
128
129 FThreadSafeCounter LastClockTickedIndex{ 0 };
130 int32 LastUpdateSizeInFrames{ 0 };
131
132 // allow a clock that is queuing a command directly use FindClock() to retrieve the TSharedPtr<FQuartzClock>
134 };
135
136 // data that the UQuartzSubsystem needs to persist on the AudioDevice across UWorld shutdown/startup
138 {
139 // internal clock manager for game-thread-ticked clocks
141
142 // array of active clock handles (update FindProxyByName() if more are added later)
145 };
146} // namespace Audio
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
EQuartzCommandQuantization
Definition QuartzQuantizationUtilities.h:46
@ Multiplier
Definition AudioMixerDevice.h:117
Definition AudioMixerClockManager.h:18
int32 GetLastUpdateSizeInFrames() const
Definition AudioMixerClockManager.h:108
AUDIOMIXER_API float GetDurationOfQuantizationTypeInSeconds(const FName &InClockName, const EQuartzCommandQuantization &QuantizationType, float Multiplier)
Definition AudioMixerClockManager.cpp:116
AUDIOMIXER_API FQuartzClockTickRate GetTickRateForClock(const FName &InName)
Definition AudioMixerClockManager.cpp:190
AUDIOMIXER_API bool DoesClockExist(const FName &InClockName)
Definition AudioMixerClockManager.cpp:94
AUDIOMIXER_API void RemoveClock(const FName &InName, bool bForceSynchronous=false)
Definition AudioMixerClockManager.cpp:164
AUDIOMIXER_API FQuartzClockProxy GetOrCreateClock(const FName &InClockName, const FQuartzClockSettings &InClockSettings, bool bOverrideTickRateIfClockExists=false)
Definition AudioMixerClockManager.cpp:55
AUDIOMIXER_API bool HasClockBeenTickedThisUpdate(FName InClockName)
Definition AudioMixerClockManager.cpp:447
AUDIOMIXER_API void Flush()
Definition AudioMixerClockManager.cpp:289
int32 GetNumClocks() const
Definition AudioMixerClockManager.h:26
AUDIOMIXER_API void SubscribeToAllTimeDivisions(FName InClockName, MetronomeCommandQueuePtr InListenerQueue)
Definition AudioMixerClockManager.cpp:365
AUDIOMIXER_API ~FQuartzClockManager()
Definition AudioMixerClockManager.cpp:15
AUDIOMIXER_API void Shutdown()
Definition AudioMixerClockManager.cpp:304
AUDIOMIXER_API bool CancelCommandOnClock(FName InOwningClockName, TSharedPtr< IQuartzQuantizedCommand > InCommandPtr)
Definition AudioMixerClockManager.cpp:428
AUDIOMIXER_API FMixerDevice * GetMixerDevice() const
Definition AudioMixerClockManager.cpp:473
AUDIOMIXER_API FQuartzClockProxy GetClock(const FName &InClockName)
Definition AudioMixerClockManager.cpp:80
AUDIOMIXER_API void UnsubscribeFromTimeDivision(FName InClockName, MetronomeCommandQueuePtr InListenerQueue, EQuartzCommandQuantization InQuantizationBoundary)
Definition AudioMixerClockManager.cpp:386
AUDIOMIXER_API void StopClock(const FName &InName, bool CancelPendingEvents)
Definition AudioMixerClockManager.cpp:247
AUDIOMIXER_API void SubscribeToTimeDivision(FName InClockName, MetronomeCommandQueuePtr InListenerQueue, EQuartzCommandQuantization InQuantizationBoundary)
Definition AudioMixerClockManager.cpp:344
AUDIOMIXER_API FQuartzQuantizedCommandHandle AddCommandToClock(FQuartzQuantizedCommandInitInfo &InQuantizationCommandInitInfo)
Definition AudioMixerClockManager.cpp:310
AUDIOMIXER_API void ResumeClock(const FName &InName, int32 NumFramesToDelayStart=0)
Definition AudioMixerClockManager.cpp:225
AUDIOMIXER_API void PauseClock(const FName &InName)
Definition AudioMixerClockManager.cpp:268
AUDIOMIXER_API bool IsClockRunning(const FName &InClockName)
Definition AudioMixerClockManager.cpp:100
AUDIOMIXER_API FQuartzTransportTimeStamp GetCurrentTimestamp(const FName &InClockName)
Definition AudioMixerClockManager.cpp:132
AUDIOMIXER_API void LowResoultionUpdate(float DeltaTimeSeconds)
Definition AudioMixerClockManager.cpp:33
AUDIOMIXER_API void UpdateClock(FName InClockToAdvance, int32 NumFramesToAdvance)
Definition AudioMixerClockManager.cpp:44
AUDIOMIXER_API void UnsubscribeFromAllTimeDivisions(FName InClockName, MetronomeCommandQueuePtr InListenerQueue)
Definition AudioMixerClockManager.cpp:407
AUDIOMIXER_API float GetEstimatedRunTime(const FName &InClockName)
Definition AudioMixerClockManager.cpp:148
AUDIOMIXER_API void SetTickRateForClock(const FQuartzClockTickRate &InNewTickRate, const FName &InName)
Definition AudioMixerClockManager.cpp:204
Definition AudioMixerClock.h:50
virtual UE_API void AddQuantizedCommand(FQuartzQuantizedRequestData &InQuantizedRequestData) override
Definition AudioMixerClock.cpp:615
Definition NameTypes.h:617
Definition QuartzQuantizationUtilities.h:245
Definition ThreadSafeCounter.h:14
Definition Array.h:670
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
Definition AudioMixerClockManager.h:138
TArray< Audio::FQuartzClockProxy > ActiveAudioMixerClockProxies
Definition AudioMixerClockManager.h:144
TArray< Audio::FQuartzClockProxy > ActiveExternalClockProxies
Definition AudioMixerClockManager.h:143
FQuartzClockManager SubsystemClockManager
Definition AudioMixerClockManager.h:140
Definition QuartzQuantizationUtilities.h:662
Definition QuartzQuantizationUtilities.h:557
Definition QuartzQuantizationUtilities.h:227
Definition QuartzQuantizationUtilities.h:142