UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioMixerSourceOutputBuffer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5
6#include "CoreMinimal.h"
7#include "ISoundfieldFormat.h"
9#include "AudioMixerDevice.h"
10#include "AudioMixerSubmix.h"
11
12namespace Audio
13{
14 class FMixerSubmix;
15
25
30 {
31 public:
33
35
36 // Resets the source submix output to prepare for new source data
38
39 // Sets the number of output channels
41
42 // Returns the number of source channels of this source
43 uint32 GetNumSourceChannels() const { return NumSourceChannels; }
44
45 // Sets the channel map
47
48 // Sets the pre and post attenuation source buffers. This is the source buffer data derived from source manager source processing.
52 const float* GetReverbPluginOutputData() const;
53
54 // Retrieves the current sound field packet for the given key
57
58 // Computes the output buffer given the spat params. This buffer can then be mixed to submixes
60
61 // Called by submixes to mix this output buffer to their buffer
63
64 // Return the listener rotation
65 // TODO: consolidate the code that is using this to be private to this class.
67
68 private: // private classes
69
70 // Private struct used for channel mapping
71 struct FSourceChannelMap
72 {
73 alignas(16) float ChannelStartGains[AUDIO_MIXER_MAX_OUTPUT_CHANNELS * AUDIO_MIXER_MAX_OUTPUT_CHANNELS];
74 alignas(16) float ChannelDestinationGains[AUDIO_MIXER_MAX_OUTPUT_CHANNELS * AUDIO_MIXER_MAX_OUTPUT_CHANNELS];
75
76 // This is the number of bytes the gain array is using:
77 // (Number of input channels * number of output channels) * sizeof float.
78 int32 CopySize = 0;
79 bool bIsInit = false;
80
83 {
86 FMemory::Memzero(ChannelStartGains, CopySize);
87 }
88
90 {
93
94 CopySize = InNumInChannels * InNumOutChannels * sizeof(float);
95 FMemory::Memzero(ChannelStartGains, CopySize);
96 FMemory::Memzero(ChannelDestinationGains, CopySize);
97 bIsInit = false;
98 }
99
100 FORCEINLINE void CopyDestinationToStart()
101 {
102 FMemory::Memcpy(ChannelStartGains, ChannelDestinationGains, CopySize);
103 }
104
105 FORCEINLINE void SetChannelMap(const float* RESTRICT InChannelGains)
106 {
107 FMemory::Memcpy(ChannelDestinationGains, InChannelGains, CopySize);
108 if (!bIsInit)
109 {
110 FMemory::Memcpy(ChannelStartGains, InChannelGains, CopySize);
111 bIsInit = true;
112 }
113 }
114
115 private:
116 FSourceChannelMap()
117 : CopySize(0)
118 , bIsInit(false)
119 {
120 }
121 };
122
123 struct FSoundfieldData
124 {
125 // If the sound source is not a soundfield source and we're sending to a soundfield submix, it gets encoded
126 TUniquePtr<ISoundfieldEncoderStream> SoundfieldEncoder;
127
128 // If the sound source is soundfield, and we're sending to a soundfield submix, it gets transcoded
129 TUniquePtr<ISoundfieldTranscodeStream> SoundfieldTranscoder;
130
131 // The optional soundfield encoder settings
133
134 // The encoded soundfield packet
136
137 // If this is a unreal ambisonics soundfield buffer, we hand it the submixed buffer directly.
138 bool bIsUnrealAmbisonicsSubmix;
139 };
140
141 private: // private methods
142
144 void ComputeOutput3D();
146 void ComputeOutput2D();
147
148 void EncodeSoundfield(FSoundfieldData& InSoundfieldData, Audio::FAlignedFloatBuffer& InSourceBuffer);
149 void EncodeToSoundfieldFormats(const FSpatializationParams& InSpatParams);
150
151 private: // private data
152
153 // Buffer for reverb plugins to write into
154 FAlignedFloatBuffer ReverbPluginOutputBuffer;
155
156 // The source buffer created before distance attenuation is applied
157 FAlignedFloatBuffer* PreAttenuationSourceBuffer;
158
159 // The source buffer created after distance attenuation is applied
160 FAlignedFloatBuffer* PostAttenuationSourceBuffer;
161
162 // Data used to map the source channel data to the output channel configuration
163 FSourceChannelMap SourceChannelMap;
164
165 // The result of the source output with source data derived pre distance attenuation
166 FAlignedFloatBuffer PreAttenuationOutputBuffer;
167
168 // The result of the source output with source data derived post distance attenuation
169 FAlignedFloatBuffer PostAttenuationOutputBuffer;
170
171 // The number of source channels (sound input)
172 uint32 NumSourceChannels;
173
174 // The number of interleaved frames in the source
175 const uint32 NumFrames;
176
177 // The number of device output channels
178 uint32 NumOutputChannels;
179
180 // The owning mixer device
181 FMixerDevice* MixerDevice;
182
183 // Whether this is the initial downmix
184 bool bIsInitialDownmix;
185
186 // If this is a 3D sound source
187 bool bIs3D;
188
189 // Whether this source is vorbis encoded (used for 2D speakermapping)
190 bool bIsVorbis;
191
192 // Cached parameters for encoding to a soundfield format
193 FSoundfieldSpeakerPositionalData SoundfieldPositionalData;
194
195 // The current sound source rotation
196 FQuat SoundSourceRotation;
197
198 // Map of sound field encoding to encoding data
199 TMap<FSoundfieldEncodingKey, FSoundfieldData> EncodedSoundfieldDownmixes;
200
201 // Channel positions of the sound field
202 TArray<Audio::FChannelPositionInfo> InputChannelPositions;
203
204 // If this source is an ambisonics source, we use this to down mix the source to output channel mix.
205 TUniquePtr<ISoundfieldDecoderStream> SoundfieldDecoder;
206
207 };
208
209
210}
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define AUDIO_MIXER_MAX_OUTPUT_CHANNELS
Definition AudioMixer.h:69
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define RESTRICT
Definition Platform.h:706
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AudioMixerDevice.h:117
Definition AudioMixerSourceOutputBuffer.h:30
void SetPreAttenuationSourceBuffer(FAlignedFloatBuffer *InPreAttenuationBuffer)
Definition AudioMixerSourceOutputBuffer.cpp:172
void ComputeOutput(const FSpatializationParams &InSpatParams)
Definition AudioMixerSourceOutputBuffer.cpp:182
void SetNumOutputChannels(uint32 InNumOutputChannels)
Definition AudioMixerSourceOutputBuffer.cpp:127
void SetPostAttenuationSourceBuffer(FAlignedFloatBuffer *InPostAttenuationBuffer)
Definition AudioMixerSourceOutputBuffer.cpp:177
void MixOutput(float SendLevel, EMixerSourceSubmixSendStage InSubmixSendStage, FAlignedFloatBuffer &OutMixedBuffer) const
Definition AudioMixerSourceOutputBuffer.cpp:491
FQuat GetListenerRotation() const
Definition AudioMixerSourceOutputBuffer.cpp:503
const float * GetReverbPluginOutputData() const
Definition AudioMixerSourceOutputBuffer.cpp:514
~FMixerSourceSubmixOutputBuffer()
Definition AudioMixerSourceOutputBuffer.cpp:45
void CopyReverbPluginOutputData(FAlignedFloatBuffer &InAudioBuffer)
Definition AudioMixerSourceOutputBuffer.cpp:508
const ISoundfieldAudioPacket * GetSoundfieldPacket(const FSoundfieldEncodingKey &InKey) const
Definition AudioMixerSourceOutputBuffer.cpp:519
uint32 GetNumSourceChannels() const
Definition AudioMixerSourceOutputBuffer.h:43
bool SetChannelMap(const FAlignedFloatBuffer &InChannelMap, bool bInIsCenterChannelOnly)
Definition AudioMixerSourceOutputBuffer.cpp:140
ISoundfieldAudioPacket * GetSoundFieldPacket(const FSoundfieldEncodingKey &InKey)
Definition AudioMixerSourceOutputBuffer.cpp:530
Definition ISoundfieldFormat.h:137
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
EMixerSourceSubmixSendStage
Definition AudioMixerSubmix.h:65
TArray< float, FAudioBufferAlignedAllocator > FAlignedFloatBuffer
Definition AlignedBuffer.h:22
@ false
Definition radaudio_common.h:23
Definition AudioMixerSourceOutputBuffer.h:17
bool bIsVorbis
Definition AudioMixerSourceOutputBuffer.h:22
uint32 NumOutputChannels
Definition AudioMixerSourceOutputBuffer.h:19
TArray< FMixerSubmixPtr > SoundfieldSubmixSends
Definition AudioMixerSourceOutputBuffer.h:20
bool bIsSoundfield
Definition AudioMixerSourceOutputBuffer.h:23
bool bIs3D
Definition AudioMixerSourceOutputBuffer.h:21
uint32 NumSourceChannels
Definition AudioMixerSourceOutputBuffer.h:18
static UE_FORCEINLINE_HINT void * Memzero(void *Dest, SIZE_T Count)
Definition UnrealMemory.h:131
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition ISoundfieldFormat.h:429
Definition ISoundfieldFormat.h:161
Definition IAudioExtensionPlugin.h:69