UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SoundConcurrency.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "UObject/Object.h"
8
9#include "SoundConcurrency.generated.h"
10
11class FAudioDevice;
13
14struct FActiveSound;
15
18
21
24
27
29
30UENUM()
32{
58}
59
60UENUM()
62{
63 /* Scales volume of older sounds more than newer sounds (default) */
64 Default = 0,
65
66 /* Scales distant sounds by volume scalar more than closer sounds */
68
69 /* Scales lower priority sounds by volume scalar more than closer sounds */
71};
72
73USTRUCT(BlueprintType)
75{
77
78
83 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Concurrency, meta = (
84 DisplayName = "Max Count (Dynamic)",
85 DisplayAfter = "bEnableMaxCountPlatformScaling",
86 EditCondition = "!bEnableMaxCountPlatformScaling",
87 EditConditionHides,
88 UIMin = "1", ClampMin = "1"))
89 int32 MaxCount;
90
91 /* Whether or not to limit the concurrency to per sound owner (i.e. the actor that plays the sound). If the sound doesn't have an owner, it falls back to global concurrency. */
92 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Concurrency)
93 uint8 bLimitToOwner : 1 = 0;
94
98 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Volume Scaling", meta = (DisplayName = "Can Recover", DisplayAfter = "VolumeScaleMode", EditCondition = "VolumeScaleMode == EConcurrencyVolumeScaleMode::Default", EditConditionHides))
99 uint8 bVolumeScaleCanRelease : 1 = 0;
100
101private:
102 /* If true, MaxCount supports platform scaling, but cannot be dynamically changed at runtime (ex. from Blueprint or Gameplay Code). If false, MaxCount is dynamically assignable at runtime, but is not platform scalable. */
103 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Concurrency, meta = (AllowPrivateAccess))
104 uint8 bEnableMaxCountPlatformScaling : 1 = 0;
105
106public:
108 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Concurrency)
109 TEnumAsByte<EMaxConcurrentResolutionRule::Type> ResolutionRule = EMaxConcurrentResolutionRule::StopFarthestThenOldest;
110
112 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Concurrency, meta = (UIMin = "0.0", ClampMin = "0.0"))
113 float RetriggerTime = 0.0f;
114
115private:
121 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Concurrency, meta = (
122 DisplayName = "Max Count (Platform Scaled)",
123 DisplayAfter = "bEnableMaxCountPlatformScaling",
124 EditCondition = "bEnableMaxCountPlatformScaling",
125 EditConditionHides,
126 AllowPrivateAccess,
127 UIMin = "1", ClampMin = "1"))
129
138 UPROPERTY(EditAnywhere, Category = "Volume Scaling", meta = (UIMin = "0.0", UIMax = "1.0", ClampMin = "0.0", ClampMax = "1.0"))
139 float VolumeScale = 1.0f;
140
141public:
143 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Volume Scaling")
145
149 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Volume Scaling", meta = (DisplayName = "Duck Time", UIMin = "0.0", ClampMin = "0.0", UIMax = "10.0", ClampMax = "1000000.0"))
150 float VolumeScaleAttackTime = 0.01f;
151
155 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Volume Scaling", meta = (
156 DisplayName = "Recover Time",
157 DisplayAfter = "bVolumeScaleCanRelease",
158 EditCondition = "bVolumeScaleCanRelease && VolumeScaleMode == EConcurrencyVolumeScaleMode::Default",
159 EditConditionHides,
160 UIMin = "0.0",
161 ClampMin = "0.0",
162 UIMax = "10.0",
163 ClampMax = "1000000.0"))
164 float VolumeScaleReleaseTime = 0.5f;
165
169 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Voice Stealing", meta = (UIMin = "0.0", ClampMin = "0.0", UIMax = "1.0", ClampMax="1000000.0"))
170 float VoiceStealReleaseTime = 0.0f;
171
173
177 ENGINE_API int32 GetMaxCount() const;
178
183 ENGINE_API bool SetMaxCount(int32 InMaxCount);
184
185#if WITH_EDITOR
190
195
200#endif // WITH_EDITOR
201
205 ENGINE_API float GetVolumeScale() const;
206
211 ENGINE_API bool IsEvictionSupported() const;
212};
213
214
215UCLASS(BlueprintType, hidecategories=Object, editinlinenew, MinimalAPI)
217{
219
220public:
221 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Settings, meta = (ShowOnlyInnerProperties))
223
228 UFUNCTION(BlueprintCallable, Category = Concurrency)
229 UPARAM(DisplayName = "Success") bool SetMaxCount(UPARAM(DisplayName = "MaxCount") int32 InMaxCount);
230};
231
234{
235 Group,
236 Owner,
238 Sound,
239};
240
256
257
260{
262 float LerpTime;
263
264private:
265 float Elapsed;
266 float DbTargetVolume;
267 float DbStartVolume;
268
269public:
271 : Generation(0)
272 , LerpTime(0.0f)
273 , Elapsed(0.0f)
274 , DbTargetVolume(0.0f)
275 , DbStartVolume(0.0f)
276 {
277 }
278
279 void Update(float InElapsed);
280
281 float GetLerpTime() const;
282 float GetVolume(bool bInDecibels = false) const;
283 float GetTargetVolume(bool bInDecibels = false) const;
284
285 void SetTarget(float InTargetVolume, float InLerpTime);
286};
287
288
291{
293 TArray<FActiveSound*> ActiveSounds;
294
295 FConcurrencyGroupID GroupID;
296 FConcurrencyObjectID ObjectID;
298
300 float LastTimePlayed = 0.0f;
301
302public:
305
307
310
313
315 const int32 GetNextGeneration() const;
316
319
322
324 bool IsEmpty() const;
325
327 bool IsFull() const;
328
330 void AddActiveSound(FActiveSound& ActiveSound);
331
333 void RemoveActiveSound(FActiveSound& ActiveSound);
334
337
340
342 void SetLastTimePlayed(float InLastTimePlayed) { LastTimePlayed = InLastTimePlayed; }
343
345 bool CanPlaySoundNow(float InCurrentTime) const;
346
347};
348
350
360
363
373
376
379
382
383
385{
386public:
389
392
394 void RemoveActiveSound(FActiveSound& ActiveSound);
395
397 void StopDueToVoiceStealing(FActiveSound& ActiveSound);
398
401
403 void UpdateSoundsToCull();
404
405private: // Methods
406
410
412 FConcurrencyGroup& CreateNewConcurrencyGroup(const FConcurrencyHandle& ConcurrencyHandle);
413
415 void CreateNewGroupsFromHandles(
419 );
420
423
426
428 FActiveSound* GetEvictableSoundStopFarthest(const FActiveSound& NewActiveSound, const FConcurrencyGroup& ConcurrencyGroup, bool bIsRetriggering) const;
429 FActiveSound* GetEvictableSoundStopOldest(const FActiveSound& NewActiveSound, const FConcurrencyGroup& ConcurrencyGroup, bool bIsRetriggering) const;
430
433
434private: // Data
436 FAudioDevice* AudioDevice;
437
439 FConcurrencyMap ConcurrencyMap;
440
441 FOwnerConcurrencyMap OwnerConcurrencyMap;
442
444 FOwnerPerSoundConcurrencyMap OwnerPerSoundConcurrencyMap;
445
447 FPerSoundToActiveSoundsMap SoundObjectToConcurrencyGroup;
448
450 FConcurrencyGroups ConcurrencyGroups;
451};
int Volume
Definition AndroidPlatformMisc.cpp:380
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
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UPARAM(...)
Definition ObjectMacros.h:748
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define UMETA(...)
Definition ObjectMacros.h:747
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
TMap< FConcurrencyGroupID, FConcurrencyGroup * > FConcurrencyGroups
Definition SoundConcurrency.h:349
TMap< FSoundOwnerObjectID, FOwnerConcurrencyMapEntry > FOwnerConcurrencyMap
Definition SoundConcurrency.h:375
TMap< FSoundObjectID, FConcurrencyGroupID > FPerSoundToActiveSoundsMap
Definition SoundConcurrency.h:381
uint32 FConcurrencyObjectID
Definition SoundConcurrency.h:20
EConcurrencyVolumeScaleMode
Definition SoundConcurrency.h:62
uint32 FSoundObjectID
Definition SoundConcurrency.h:26
uint32 FSoundOwnerObjectID
Definition SoundConcurrency.h:23
uint32 FConcurrencyGroupID
Definition SoundConcurrency.h:17
TMap< FSoundOwnerObjectID, FSoundInstanceEntry > FOwnerPerSoundConcurrencyMap
Definition SoundConcurrency.h:378
TMap< FConcurrencyObjectID, FConcurrencyGroupID > FConcurrencyMap
Definition SoundConcurrency.h:362
EConcurrencyMode
Definition SoundConcurrency.h:234
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AudioDevice.h:417
Definition SoundConcurrency.h:291
static FConcurrencyGroupID GenerateNewID()
Definition SoundConcurrency.cpp:250
bool CanPlaySoundNow(float InCurrentTime) const
Definition SoundConcurrency.cpp:511
FConcurrencyGroupID GetGroupID() const
Definition SoundConcurrency.cpp:261
void RemoveActiveSound(FActiveSound &ActiveSound)
Definition SoundConcurrency.cpp:315
void CullSoundsDueToMaxConcurrency()
Definition SoundConcurrency.cpp:428
const FSoundConcurrencySettings & GetSettings() const
Definition SoundConcurrency.cpp:271
FConcurrencyObjectID GetObjectID() const
Definition SoundConcurrency.cpp:276
void AddActiveSound(FActiveSound &ActiveSound)
Definition SoundConcurrency.cpp:291
void SetLastTimePlayed(float InLastTimePlayed)
Definition SoundConcurrency.h:342
const TArray< FActiveSound * > & GetActiveSounds() const
Definition SoundConcurrency.cpp:256
bool IsFull() const
Definition SoundConcurrency.cpp:286
const int32 GetNextGeneration() const
Definition SoundConcurrency.cpp:266
void UpdateGeneration(FActiveSound *NewActiveSound=nullptr)
Definition SoundConcurrency.cpp:348
bool IsEmpty() const
Definition SoundConcurrency.cpp:281
Definition SoundConcurrency.h:385
void RemoveActiveSound(FActiveSound &ActiveSound)
Definition SoundConcurrency.cpp:991
void StopDueToVoiceStealing(FActiveSound &ActiveSound)
Definition SoundConcurrency.cpp:1066
void UpdateVolumeScaleGenerations()
Definition SoundConcurrency.cpp:1106
ENGINE_API ~FSoundConcurrencyManager()
Definition SoundConcurrency.cpp:530
FActiveSound * CreateNewActiveSound(const FActiveSound &NewActiveSound, bool bIsRetriggering)
Definition SoundConcurrency.cpp:617
void UpdateSoundsToCull()
Definition SoundConcurrency.cpp:1116
Definition Array.h:670
Definition EnumAsByte.h:22
Definition UnrealString.h.inl:34
Definition Object.h:95
Definition SoundConcurrency.h:217
Definition Voice.Build.cs:7
Definition SoundBase.h:40
Type
Definition SoundConcurrency.h:34
@ StopLowestPriority
Definition SoundConcurrency.h:48
@ StopFarthestThenOldest
Definition SoundConcurrency.h:45
@ StopQuietest
Definition SoundConcurrency.h:51
@ PreventNew
Definition SoundConcurrency.h:36
@ StopLowestPriorityThenPreventNew
Definition SoundConcurrency.h:54
@ StopOldest
Definition SoundConcurrency.h:39
@ StopFarthestThenPreventNew
Definition SoundConcurrency.h:42
Definition ActiveSound.h:283
Definition SoundConcurrency.h:243
const FSoundConcurrencySettings & Settings
Definition SoundConcurrency.h:244
EConcurrencyMode GetMode(const FActiveSound &ActiveSound) const
Definition SoundConcurrency.cpp:178
const bool bIsOverride
Definition SoundConcurrency.h:246
const FConcurrencyObjectID ObjectID
Definition SoundConcurrency.h:245
Definition SoundConcurrency.h:260
void SetTarget(float InTargetVolume, float InLerpTime)
Definition SoundConcurrency.cpp:234
int32 Generation
Definition SoundConcurrency.h:261
float GetTargetVolume(bool bInDecibels=false) const
Definition SoundConcurrency.cpp:218
FConcurrencySoundData()
Definition SoundConcurrency.h:270
float GetLerpTime() const
Definition SoundConcurrency.cpp:195
float GetVolume(bool bInDecibels=false) const
Definition SoundConcurrency.cpp:200
float LerpTime
Definition SoundConcurrency.h:262
Definition SoundConcurrency.h:365
FConcurrencyMap ConcurrencyObjectToConcurrencyGroup
Definition SoundConcurrency.h:366
FOwnerConcurrencyMapEntry(FConcurrencyObjectID ConcurrencyObjectID, FConcurrencyGroupID GroupID)
Definition SoundConcurrency.h:368
Definition PerPlatformProperties.h:211
Definition SoundConcurrency.h:75
Definition SoundConcurrency.h:352
FSoundInstanceEntry(FSoundObjectID SoundObjectID, FConcurrencyGroupID GroupID)
Definition SoundConcurrency.h:355
TMap< FSoundObjectID, FConcurrencyGroupID > SoundInstanceToConcurrencyGroup
Definition SoundConcurrency.h:353