UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
QuartzSubsystem.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
9
10#include "QuartzSubsystem.generated.h"
11
12
13// forwards
14namespace Audio
15{
16 class FMixerDevice;
17 class FQuartzClockManager;
19
20}
21
25
26
27
29{
30public:
31 AUDIOMIXER_API void Tick(float DeltaTime);
32 AUDIOMIXER_API bool IsTickable() const;
35
36private:
37 // list of objects needing to be ticked by Quartz
38 TArray<FQuartzTickableObject *> QuartzTickSubscribers;
39
40 // index to track the next subscriber to tick (if updates are being amortized across multiple UObject Ticks)
41 int32 UpdateIndex{ 0 };
42};
43
44
45UCLASS(DisplayName = "Quartz", MinimalAPI)
47{
49
50public:
51 // ctor/dtor
52 UQuartzSubsystem() = default;
53 virtual ~UQuartzSubsystem() override = default;
54
55 //~ Begin UWorldSubsystem Interface
57 AUDIOMIXER_API virtual void Deinitialize() override;
58 AUDIOMIXER_API virtual bool DoesSupportWorldType(EWorldType::Type WorldType) const override;
59 AUDIOMIXER_API void virtual BeginDestroy() override;
60 //~ End UWorldSubsystem Interface
61
62 //~ Begin FTickableGameObject Interface
63 AUDIOMIXER_API virtual void Tick(float DeltaTime) override;
64 AUDIOMIXER_API virtual bool IsTickableWhenPaused() const override;
65 AUDIOMIXER_API virtual bool IsTickable() const override;
66 AUDIOMIXER_API virtual TStatId GetStatId() const override;
67 //~ End FTickableGameObject Interface
68
69 // these calls are forwarded to the internal FQuartzTickableObjectsManager
70 AUDIOMIXER_API void SubscribeToQuartzTick(FQuartzTickableObject* InObjectToTick);
71 AUDIOMIXER_API void UnsubscribeFromQuartzTick(FQuartzTickableObject* InObjectToTick);
72
73 // get C++ handle (proxy) to a clock if it exists
74 AUDIOMIXER_API Audio::FQuartzClockProxy GetProxyForClock(FName ClockName) const;
75
76 // allow an external clock (not ticked by the Audio Mixer or QuartzSubsystem) to be accessible via this subsystem
77 AUDIOMIXER_API void AddProxyForExternalClock(const Audio::FQuartzClockProxy& InProxy);
78
79 // static methods
80 static AUDIOMIXER_API UQuartzSubsystem* Get(const UWorld* const World);
81
82 // Helper functions for initializing quantized command initialization struct (to consolidate eyesore)
88
89 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle")
90 AUDIOMIXER_API bool IsQuartzEnabled();
91
92 // Clock Creation
93 // create a new clock (or return handle if clock already exists)
94 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject", AdvancedDisplay = "bUseAudioEngineClockManager"))
96
97 // delete an existing clock given its name
98 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
99 AUDIOMIXER_API void DeleteClockByName(const UObject* WorldContextObject, FName ClockName);
100
101 // delete an existing clock given its clock handle
102 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
103 AUDIOMIXER_API void DeleteClockByHandle(const UObject* WorldContextObject, UPARAM(ref) UQuartzClockHandle*& InClockHandle);
104
105 // get handle for existing clock
106 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
107 AUDIOMIXER_API UQuartzClockHandle* GetHandleForClock(const UObject* WorldContextObject, FName ClockName);
108
109 // returns true if the clock exists
110 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
111 AUDIOMIXER_API bool DoesClockExist(const UObject* WorldContextObject, FName ClockName);
112
113 // returns true if the clock is running
114 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
115 AUDIOMIXER_API bool IsClockRunning(const UObject* WorldContextObject, FName ClockName);
116
117 // Returns the duration in seconds of the given Quantization Type
118 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
119 AUDIOMIXER_API float GetDurationOfQuantizationTypeInSeconds(const UObject* WorldContextObject, FName ClockName, const EQuartzCommandQuantization& QuantizationType, float Multiplier = 1.0f);
120
121 // Retrieves a timestamp for the clock
122 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
123 AUDIOMIXER_API FQuartzTransportTimeStamp GetCurrentClockTimestamp(const UObject* WorldContextObject, const FName& InClockName);
124
125 // Returns the amount of time, in seconds, the clock has been running. Caution: due to latency, this will not be perfectly accurate
126 UFUNCTION(BlueprintCallable, Category = "Quartz Clock Handle", meta = (WorldContext = "WorldContextObject"))
127 AUDIOMIXER_API float GetEstimatedClockRunTime(const UObject* WorldContextObject, const FName& InClockName);
128
129 // latency data (Game thread -> Audio Render Thread)
130 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem", meta = (WorldContext = "WorldContextObject"))
131 AUDIOMIXER_API float GetGameThreadToAudioRenderThreadAverageLatency(const UObject* WorldContextObject);
132
133 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem", meta = (WorldContext = "WorldContextObject"))
134 AUDIOMIXER_API float GetGameThreadToAudioRenderThreadMinLatency(const UObject* WorldContextObject);
135
136 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem", meta = (WorldContext = "WorldContextObject"))
137 AUDIOMIXER_API float GetGameThreadToAudioRenderThreadMaxLatency(const UObject* WorldContextObject);
138
139 // latency data (Audio Render Thread -> Game thread)
140 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem")
141 AUDIOMIXER_API float GetAudioRenderThreadToGameThreadAverageLatency();
142
143 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem")
144 AUDIOMIXER_API float GetAudioRenderThreadToGameThreadMinLatency();
145
146 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem")
147 AUDIOMIXER_API float GetAudioRenderThreadToGameThreadMaxLatency();
148
149 // latency data (Round trip)
150 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem", meta = (WorldContext = "WorldContextObject"))
151 AUDIOMIXER_API float GetRoundTripAverageLatency(const UObject* WorldContextObject);
152
153 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem", meta = (WorldContext = "WorldContextObject"))
154 AUDIOMIXER_API float GetRoundTripMinLatency(const UObject* WorldContextObject);
155
156 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem", meta = (WorldContext = "WorldContextObject"))
157 AUDIOMIXER_API float GetRoundTripMaxLatency(const UObject* WorldContextObject);
158
159 UFUNCTION(BlueprintCallable, Category = "Quartz Subsystem")
160 AUDIOMIXER_API void SetQuartzSubsystemTickableWhenPaused(const bool bInTickableWhenPaused);
161
162 // sharable to allow non-UObjects to un-subscribe if the Subsystem is going to outlive them
163 AUDIOMIXER_API TWeakPtr<FQuartzTickableObjectsManager> GetTickableObjectManager() const;
164
165private:
166 // deletes proxies to clocks that no longer exists
167 AUDIOMIXER_API void PruneStaleProxies();
168 static AUDIOMIXER_API void PruneStaleProxiesInternal(TArray<Audio::FQuartzClockProxy>& ContainerToPrune);
169
170 // sharable tickable object manager to allow for non-UObject subscription / un-subscription
172
173 // Clock manager/proxy-related data that lives on the AudioDevice for persistence.
174 TSharedPtr<Audio::FPersistentQuartzSubsystemData> ClockManagerDataPtr { nullptr };
175
176 bool bTickEvenWhenPaused = false;
177
178 // helpers
179 AUDIOMIXER_API Audio::FQuartzClockProxy* FindProxyByName(const FName& ClockName);
180 AUDIOMIXER_API Audio::FQuartzClockProxy const* FindProxyByName(const FName& ClockName) const;
181 AUDIOMIXER_API Audio::FQuartzClockManager* GetClockManager(const UObject* WorldContextObject, bool bUseAudioEngineClockManager = true);
182
183}; // class UQuartzGameSubsystem
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
return true
Definition ExternalRpcRegistry.cpp:601
#define UPARAM(...)
Definition ObjectMacros.h:748
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define UCLASS(...)
Definition ObjectMacros.h:776
EQuartzCommandQuantization
Definition QuartzQuantizationUtilities.h:46
@ Multiplier
Definition AudioMixerClockManager.h:18
Definition AudioMixerClock.h:50
Definition NameTypes.h:617
Definition QuartzQuantizationUtilities.h:245
Definition QuartzSubscription.h:49
Definition SubsystemCollection.h:15
Definition Array.h:670
Definition SharedPointer.h:692
Definition SharedPointer.h:1295
Definition Object.h:95
Definition AudioMixerClockHandle.h:28
Definition QuartzSubsystem.h:47
UQuartzSubsystem()=default
virtual ~UQuartzSubsystem() override=default
Definition WorldSubsystem.h:76
Definition World.h:918
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
Type
Definition EngineTypes.h:1264
@ false
Definition radaudio_common.h:23
Definition QuartzQuantizationUtilities.h:543
Definition QuartzQuantizationUtilities.h:227
Definition QuartzQuantizationUtilities.h:489
Definition QuartzSubsystem.h:29
AUDIOMIXER_API void SubscribeToQuartzTick(FQuartzTickableObject *InObjectToTick)
Definition QuartzSubsystem.cpp:169
AUDIOMIXER_API void UnsubscribeFromQuartzTick(FQuartzTickableObject *InObjectToTick)
Definition QuartzSubsystem.cpp:179
AUDIOMIXER_API bool IsTickable() const
Definition QuartzSubsystem.cpp:145
Definition QuartzQuantizationUtilities.h:142
Definition LightweightStats.h:416