UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioMixerBus.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Audio.h"
6#include "AudioBusSubsystem.h"
7#include "AudioMixerTrace.h"
10#include "Sound/AudioSettings.h"
11
12#if UE_AUDIO_PROFILERTRACE_ENABLED
14#endif // UE_AUDIO_PROFILERTRACE_ENABLED
15
16namespace Audio
17{
18 class FMixerSourceManager;
19
20 // Struct holding mappings of runtime source ids (bus instances) to bus send level
27
28 // Bus instance data. Holds source id bus instances and bus sends data
30 {
31 public:
32 // Creates an audio bus.
33 // SourceManager The owning source manager object.
34 // bInIsAutomatic Whether or not this audio bus was created automatically via source buses.
35 // InNumChannels The number of channels of the source bus.
36 // InBusKey The unique key used to identify this bus.
38
40
41 // Allow anybody to add a pre-existing patch output object to the audio bus
43
44 // Allow anybody to write audio into this audio bus from any thread.
46
47 // Allow anybody to write audio into this audio bus from any thread.
49
50 private:
51
52 // Sets whether or not this audio bus is automatic.
53 void SetAutomatic(bool bInIsAutomatic) { bIsAutomatic = bInIsAutomatic; }
54
55 // Returns if this is a manual audio bus vs automatic
56 bool IsAutomatic() const { return bIsAutomatic; }
57
58 // Returns the number of channels of the audio bus
59 int32 GetNumChannels() const { return NumChannels; }
60
61 // Update the mixer bus after a render block
62 void Update();
63
64 // Adds a source id for instances of this bus
66
67 // Removes the source id from this bus. Returns true if there are no more instances or sends.
68 bool RemoveInstanceId(const int32 InSourceId, const uint64 InTransmitterID);
69
70 // Adds a bus send to the bus
71 void AddSend(EBusSendType BusSendType, const FAudioBusSend& InBusSend);
72
73 // Removes the source instance from this bus's send list
74 bool RemoveSend(EBusSendType BusSendType, const int32 InSourceId);
75
76 // Gets the current mixed bus buffer
77 const float* GetCurrentBusBuffer() const;
78
79 // Gets the previous mixed bus buffer
80 const float* GetPreviousBusBuffer() const;
81
82 // Compute the mixed buffer
83 void MixBuffer();
84
85 // Copies the current internal buffer to a provided output buffer. Only supports mono or stereo input/output formats.
86 void CopyCurrentBuffer(Audio::FAlignedFloatBuffer& InChannelMap, int32 InNumOutputChannels, FAlignedFloatBuffer& OutBuffer, int32 NumOutputFrames) const;
87 void CopyCurrentBuffer(int32 InNumOutputChannels, FAlignedFloatBuffer& OutBuffer, int32 NumOutputFrames) const;
88
89 // If this bus was constructed before
90 void SetNumOutputChannels(int32 InNumOutputChannels);
91
92 // IAudioMixerRenderStep interface
93 virtual void DoRenderStep() override;
94 virtual const TCHAR* GetRenderStepName() override;
95
96#if UE_AUDIO_PROFILERTRACE_ENABLED
97 void StartEnvelopeFollower(const float InAttackTime, const float InReleaseTime, const float InSampleRate);
99 void ProcessEnvelopeFollower(const float* InBuffer);
100#endif // UE_AUDIO_PROFILERTRACE_ENABLED
101
102 // Array of instance ids. These are sources which are instances of this.
103 // It's possible for this data to have bus sends but no instance ids.
104 // This means a source would send its audio to the bus if the bus had an instance.
105 // Once and instance plays, it will then start sending its audio to the bus instances.
106 TArray<int32> InstanceIds;
107
108 // Bus sends to this instance
110
111 // The mixed source data. This is double-buffered to allow buses to send audio to themselves.
112 // Buses feed audio to each other by storing their previous buffer. Current buses mix in previous other buses (including themselves)
113 FAlignedFloatBuffer MixedSourceData[2];
114
115 // The index of the bus data currently being rendered
116 int32 CurrentBufferIndex;
117
118 // The number of channels of this bus
119 int32 NumChannels;
120
121 // The number of output frames
122 int32 NumFrames;
123
124 // Owning source manager
125 FMixerSourceManager* SourceManager;
126
127 // Multiple places can produce and consume from audio buses
128 Audio::FPatchMixer PatchMixer;
129 Audio::FPatchSplitter PatchSplitter;
130
131 // Unique bus identifier
132 FAudioBusKey BusKey;
133
134 // Was created manually, not via source buses.
135 bool bIsAutomatic;
136
137#if ENABLE_AUDIO_DEBUG
138 FString BusName;
139#endif // if ENABLE_AUDIO_DEBUG
140
141#if UE_AUDIO_PROFILERTRACE_ENABLED
142 Audio::FEnvelopeFollower EnvelopeFollower;
143 float EnvelopeValues[AUDIO_MIXER_MAX_OUTPUT_CHANNELS];
144 int32 EnvelopeNumChannels = 0;
145 bool bIsEnvelopeFollowing = false;
146#endif // UE_AUDIO_PROFILERTRACE_ENABLED
147
148 friend FMixerSourceManager;
149 friend FMixerSubmix;
150 };
151
152}
#define AUDIO_MIXER_MAX_OUTPUT_CHANNELS
Definition AudioMixer.h:69
EBusSendType
Definition Audio.h:169
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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 EnvelopeFollower.h:226
Definition AudioMixerBus.h:30
void RemovePatchInput(const FPatchInput &InPatchInput)
Definition AudioMixerBus.cpp:244
~FMixerAudioBus()
Definition AudioMixerBus.cpp:30
void AddNewPatchInput(const FPatchInput &InPatchInput)
Definition AudioMixerBus.cpp:239
void AddNewPatchOutput(const FPatchOutputStrongPtr &InPatchOutputStrongPtr)
Definition AudioMixerBus.cpp:234
Definition AudioMixerSourceManager.h:192
Definition AudioMixerSubmix.h:110
Definition MultithreadedPatching.h:96
Definition MultithreadedPatching.h:149
Definition MultithreadedPatching.h:204
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
Definition AudioBusSubsystem.h:22
Definition AudioMixerBus.h:22
float SendLevel
Definition AudioMixerBus.h:25
int32 SourceId
Definition AudioMixerBus.h:23
uint64 TransmitterID
Definition AudioMixerBus.h:24
Definition IAudioMixerRenderStep.h:13