UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioMixerSourceDecode.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"
6#include "Containers/Queue.h"
9#include "AudioDecompress.h"
10#include "AudioMixerBuffer.h"
11
12class USoundWave;
13
14namespace Audio
15{
16 class FMixerBuffer;
17 class FMixerSourceBuffer;
18
19 // Data needed for a procedural audio task
21 {
22 // The source which owns this decoding task
24
25 // The sound generator to use to generate audio
27
28 // The audio buffer to fill from the results of the generation
29 float* AudioData;
30
31 // The size of the audio buffer
33
34 // Force decodes to execute synchronously
36
38 : SourceBuffer(nullptr)
39 , AudioData(nullptr)
40 , NumSamples(0)
42 {}
43 };
44
45 // Data needed for a decode audio task
47 {
48 // A pointer to a buffer of audio which will be decoded to
49 float* AudioData;
50
51 // Decompression state for decoder
53
54 // The buffer type for the decoder
56
57 // Number of channels of the decoder
59
60 // The number of frames which are precached
62
63 // The number of frames to decode
65
66 // Whether or not this sound is intending to be looped
68
69 // Whether or not to skip the first buffer
71
72 // Force this decoding operation to occur synchronously,
73 // regardless of the value of au.ForceSyncAudioDecodes. (used by time synth)
75
87 };
88
89 // Data needed for a header parse audio task
91 {
92 // The mixer buffer object which results will be written to
94
95 // The sound wave object which contains the encoded file
97
99 : MixerBuffer(nullptr)
100 , SoundWave(nullptr)
101 {}
102 };
103
104 // Results from procedural audio task
106 {
110
111#if ENABLE_AUDIO_DEBUG
112 double CPUDuration = 0.0;
113#endif // if ENABLE_AUDIO_DEBUG
114
119 };
120
121 // Results from decode audio task
123 {
124
125 // Whether or not the audio buffer looped
128
129#if ENABLE_AUDIO_DEBUG
130 double CPUDuration = 0;
131#endif // if ENABLE_AUDIO_DEBUG
132
136 };
137
138 // The types of audio tasks
139 enum class EAudioTaskType
140 {
141 // The job is a procedural sound wave job to generate more audio
143
144 // The job is a header decode job
145 Header,
146
147 // The job is a decode job
148 Decode,
149
150 // The job is invalid (or unknown)
151 Invalid,
152 };
153
154 // Handle to an in-flight decode job. Can be queried and used on any thread.
156 {
157 public:
158 virtual ~IAudioTask() {}
159
160 // Queries if the decode job has finished.
161 virtual bool IsDone() const = 0;
162
163 // Returns the job type of the handle.
164 virtual EAudioTaskType GetType() const = 0;
165
166 // Ensures the completion of the decode operation.
167 virtual void EnsureCompletion() = 0;
168
169 // Cancel the decode operation
170 virtual void CancelTask() = 0;
171
172 // Returns the result of a procedural sound generate job
174
175 // Returns the result of a decode job
177 };
178
179 // Creates a task to decode a decoded file header
180 IAudioTask* CreateAudioTask(Audio::FDeviceId InDeviceId, const FHeaderParseAudioTaskData& InJobData);
181
182 // Creates a task for a procedural sound wave generation
183 IAudioTask* CreateAudioTask(Audio::FDeviceId InDeviceId, const FProceduralAudioTaskData& InJobData);
184
185 // Creates a task to decode a chunk of audio
186 IAudioTask* CreateAudioTask(Audio::FDeviceId InDeviceId, const FDecodeAudioTaskData& InJobData);
187
188#if ENABLE_AUDIO_DEBUG
189 struct FScopeDecodeTimer
190 {
192 : Result(OutResultSeconds)
193 {
194 StartCycle = FPlatformTime::Cycles64();
195 }
197 {
199 if (Result)
200 {
201 *Result = static_cast<double>(EndCycle - StartCycle) * FPlatformTime::GetSecondsPerCycle64();
202 }
203 }
204
205 double* Result = nullptr;
206 uint64 StartCycle = 0;
207 };
208#endif // if ENABLE_AUDIO_DEBUG
209
210 // Creates a queue for audio decode requests with a specific Id. Tasks
211 // created with this Id will not be started immediately upon creation,
212 // but will instead be queued up to await a start "kick" later. NOTE:
213 // "kicking" the queue is the responsibility of the system that creates
214 // the queue, typically someplace like in a FOnAudioDevicePostRender delegate!
216
217 // Destroys an audio decode task queue. Tasks currently queued up are
218 // optionally started.
220
221 // "Kicks" all of the audio decode tasks currentlyt in the specified queue.
223
224}
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition AudioMixerBuffer.h:28
Definition AudioMixerSourceBuffer.h:69
Definition AudioMixerSourceDecode.h:156
virtual bool IsDone() const =0
virtual void GetResult(FDecodeAudioTaskResults &OutResult)
Definition AudioMixerSourceDecode.h:176
virtual void GetResult(FProceduralAudioTaskResults &OutResult)
Definition AudioMixerSourceDecode.h:173
virtual ~IAudioTask()
Definition AudioMixerSourceDecode.h:158
virtual void CancelTask()=0
virtual EAudioTaskType GetType() const =0
virtual void EnsureCompletion()=0
Definition AudioDecompress.h:31
Definition SoundWave.h:417
Type
Definition AudioMixerBuffer.h:14
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
int KickQueuedTasks(AudioTaskQueueId QueueId)
Definition AudioMixerSourceDecode.cpp:488
EAudioTaskType
Definition AudioMixerSourceDecode.h:140
void CreateSynchronizedAudioTaskQueue(AudioTaskQueueId QueueId)
Definition AudioMixerSourceDecode.cpp:478
uint32 FDeviceId
Definition AudioDefines.h:66
uint32 AudioTaskQueueId
Definition SoundGenerator.h:12
IAudioTask * CreateAudioTask(Audio::FDeviceId InDeviceId, const FProceduralAudioTaskData &InJobData)
Definition AudioMixerSourceDecode.cpp:450
void DestroySynchronizedAudioTaskQueue(AudioTaskQueueId QueueId, bool RunCurrentQueue)
Definition AudioMixerSourceDecode.cpp:483
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
@ false
Definition radaudio_common.h:23
Definition AudioMixerSourceDecode.h:47
int32 NumFramesToDecode
Definition AudioMixerSourceDecode.h:64
int32 NumChannels
Definition AudioMixerSourceDecode.h:58
float * AudioData
Definition AudioMixerSourceDecode.h:49
int32 NumPrecacheFrames
Definition AudioMixerSourceDecode.h:61
ICompressedAudioInfo * DecompressionState
Definition AudioMixerSourceDecode.h:52
Audio::EBufferType::Type BufferType
Definition AudioMixerSourceDecode.h:55
bool bForceSyncDecode
Definition AudioMixerSourceDecode.h:74
bool bSkipFirstBuffer
Definition AudioMixerSourceDecode.h:70
bool bLoopingMode
Definition AudioMixerSourceDecode.h:67
FDecodeAudioTaskData()
Definition AudioMixerSourceDecode.h:76
Definition AudioMixerSourceDecode.h:123
FDecodeAudioTaskResults()
Definition AudioMixerSourceDecode.h:133
bool bIsFinishedOrLooped
Definition AudioMixerSourceDecode.h:126
int32 NumSamplesWritten
Definition AudioMixerSourceDecode.h:127
Definition AudioMixerSourceDecode.h:91
USoundWave * SoundWave
Definition AudioMixerSourceDecode.h:96
FHeaderParseAudioTaskData()
Definition AudioMixerSourceDecode.h:98
FMixerBuffer * MixerBuffer
Definition AudioMixerSourceDecode.h:93
Definition AudioMixerSourceDecode.h:21
bool bForceSyncDecode
Definition AudioMixerSourceDecode.h:35
FMixerSourceBuffer * SourceBuffer
Definition AudioMixerSourceDecode.h:23
ISoundGeneratorPtr SoundGenerator
Definition AudioMixerSourceDecode.h:26
int32 NumSamples
Definition AudioMixerSourceDecode.h:32
FProceduralAudioTaskData()
Definition AudioMixerSourceDecode.h:37
float * AudioData
Definition AudioMixerSourceDecode.h:29
Definition AudioMixerSourceDecode.h:106
FProceduralAudioTaskResults()
Definition AudioMixerSourceDecode.h:115
bool bIsFinished
Definition AudioMixerSourceDecode.h:108
float RelativeRenderCost
Definition AudioMixerSourceDecode.h:109
int32 NumSamplesWritten
Definition AudioMixerSourceDecode.h:107
static uint64 Cycles64()
Definition AndroidPlatformTime.h:34
static double GetSecondsPerCycle64()
Definition GenericPlatformTime.h:196