UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SynthComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "AudioMixerTypes.h"
6#include "CoreMinimal.h"
12
13#include "SynthComponent.generated.h"
14
15#define SYNTH_GENERATOR_TEST_TONE 0
16
17#if SYNTH_GENERATOR_TEST_TONE
18#include "DSP/SinOsc.h"
19#endif
20
21class UAudioBus;
22class USoundSourceBus;
23
26{
27public:
28 virtual void OnGeneratedBuffer(const float* AudioBuffer, const int32 NumSamples, const int32 NumChannels) = 0;
29};
30
31class USynthComponent;
33
39
42
43
44UCLASS(MinimalAPI)
46{
48
50 AUDIOMIXER_API void StartOnAudioDevice(FAudioDevice* InAudioDevice);
51
53 AUDIOMIXER_API virtual void OnBeginGenerate() override;
54 AUDIOMIXER_API virtual int32 OnGeneratePCMAudio(TArray<uint8>& OutAudio, int32 NumSamples) override;
55 AUDIOMIXER_API virtual void OnEndGenerate() override;
56 AUDIOMIXER_API virtual Audio::EAudioMixerStreamDataFormat::Type GetGeneratedPCMDataFormat() const override;
57 AUDIOMIXER_API virtual ISoundGeneratorPtr CreateSoundGenerator(const FSoundGeneratorInitParams& InParams) override;
60protected:
61 UPROPERTY()
62 TWeakObjectPtr<USynthComponent> OwningSynthComponent = nullptr;
63
64 TArray<float> FloatBuffer;
65
66public:
67 USynthComponent* GetOwningSynthComponent()
68 {
69 return OwningSynthComponent.Get();
70 }
71
73 {
74 return OwningSynthComponent;
75 }
76};
77
78UCLASS(abstract, ClassGroup = Synth, hidecategories = (Object, ActorComponent, Physics, Rendering, Mobility, LOD), MinimalAPI)
79class USynthComponent : public USceneComponent
80{
82
83public:
85
86 //~ Begin USceneComponent Interface
87 AUDIOMIXER_API virtual void Activate(bool bReset = false) override;
88 AUDIOMIXER_API virtual void Deactivate() override;
89 //~ End USceneComponent Interface
90
91 //~ Begin ActorComponent Interface.
92 AUDIOMIXER_API virtual void OnRegister() override;
93 AUDIOMIXER_API virtual void OnUnregister() override;
94 AUDIOMIXER_API virtual bool IsReadyForOwnerToAutoDestroy() const override;
95 AUDIOMIXER_API virtual void EndPlay(const EEndPlayReason::Type Reason) override;
96 //~ End ActorComponent Interface.
97
98 //~ Begin UObject Interface.
99#if WITH_EDITOR
100 AUDIOMIXER_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
101#endif // WITH_EDITOR
102
103#if WITH_EDITORONLY_DATA
104 AUDIOMIXER_API virtual void PostLoad() override;
105#endif //WITH_EDITORONLY_DATA
106
107 AUDIOMIXER_API virtual void Serialize(FArchive& Ar) override;
108 //~ End UObject Interface
109
110 // Starts the synth generating audio.
111 UFUNCTION(BlueprintCallable, Category = "Synth|Components|Audio")
112 AUDIOMIXER_API void Start();
113
114 // Stops the synth generating audio.
115 UFUNCTION(BlueprintCallable, Category = "Synth|Components|Audio")
116 AUDIOMIXER_API void Stop();
117
119 UFUNCTION(BlueprintCallable, Category = "Synth|Components|Audio")
120 AUDIOMIXER_API bool IsPlaying() const;
121
123 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
124 AUDIOMIXER_API void SetVolumeMultiplier(float VolumeMultiplier);
125
127 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
128 AUDIOMIXER_API void SetSubmixSend(USoundSubmixBase* Submix, float SendLevel);
129
131 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
132 AUDIOMIXER_API void SetSourceBusSendPreEffect(USoundSourceBus* SoundSourceBus, float SourceBusSendLevel);
133
135 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
136 AUDIOMIXER_API void SetSourceBusSendPostEffect(USoundSourceBus* SoundSourceBus, float SourceBusSendLevel);
137
139 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
140 AUDIOMIXER_API void SetAudioBusSendPreEffect(UAudioBus* AudioBus, float AudioBusSendLevel);
141
143 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
144 AUDIOMIXER_API void SetAudioBusSendPostEffect(UAudioBus* AudioBus, float AudioBusSendLevel);
145
147 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
148 AUDIOMIXER_API void SetLowPassFilterEnabled(bool InLowPassFilterEnabled);
149
151 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
152 AUDIOMIXER_API virtual void SetLowPassFilterFrequency(float InLowPassFilterFrequency);
153
155 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
156 AUDIOMIXER_API void SetOutputToBusOnly(bool bInOutputToBusOnly);
157
166 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
167 AUDIOMIXER_API void FadeIn(float FadeInDuration, float FadeVolumeLevel = 1.0f, float StartTime = 0.0f, const EAudioFaderCurve FadeCurve = EAudioFaderCurve::Linear) const;
168
177 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
178 AUDIOMIXER_API void FadeOut(float FadeOutDuration, float FadeVolumeLevel, const EAudioFaderCurve FadeCurve = EAudioFaderCurve::Linear) const;
179
185 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio")
186 AUDIOMIXER_API void AdjustVolume(float AdjustVolumeDuration, float AdjustVolumeLevel, const EAudioFaderCurve FadeCurve = EAudioFaderCurve::Linear) const;
187
194 UFUNCTION(BlueprintCallable, Category = "Audio|Components|Audio", DisplayName = "Set Modulation Routing")
195 AUDIOMIXER_API void SetModulationRouting(const TSet<USoundModulatorBase*>& Modulators, const EModulationDestination Destination, const EModulationRouting RoutingMethod = EModulationRouting::Inherit);
196
202 UFUNCTION(BlueprintPure, Category = "Audio|Components|Audio", DisplayName = "Get Modulators")
203 AUDIOMIXER_API UPARAM(DisplayName = "Modulators") TSet<USoundModulatorBase*> GetModulators(const EModulationDestination Destination);
204
206 UPROPERTY()
207 uint8 bAutoDestroy : 1;
208
210 UPROPERTY()
211 uint8 bStopWhenOwnerDestroyed : 1;
212
214 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Attenuation)
215 uint8 bAllowSpatialization : 1;
216
218 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Attenuation)
219 uint8 bOverrideAttenuation : 1;
220
221#if WITH_EDITORONLY_DATA
223 UPROPERTY()
225#endif //WITH_EDITORONLY_DATA
226
228 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Effects)
229 uint32 bEnableBusSends : 1;
230
232 UPROPERTY(EditAnywhere, Category = Effects)
233 uint32 bEnableBaseSubmix : 1;
234
236 UPROPERTY(EditAnywhere, Category = Effects, meta = (DisplayAfter = "SoundSubmixObject"))
237 uint32 bEnableSubmixSends : 1;
238
240 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Attenuation, meta = (EditCondition = "!bOverrideAttenuation"))
241 TObjectPtr<class USoundAttenuation> AttenuationSettings;
242
244 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Attenuation, meta = (EditCondition = "bOverrideAttenuation"))
245 struct FSoundAttenuationSettings AttenuationOverrides;
246
248 UPROPERTY()
249 TObjectPtr<USoundConcurrency> ConcurrencySettings_DEPRECATED;
250
252 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Concurrency)
253 TSet<TObjectPtr<USoundConcurrency>> ConcurrencySet;
254
255 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Modulation)
257
259 UPROPERTY(EditAnywhere, Category = SoundClass)
261
263 UPROPERTY(EditAnywhere, Category = Effects)
265
267 UPROPERTY(EditAnywhere, Category = Effects, meta = (EditCondition = "bEnableBaseSubmix", DisplayName = "Base Submix"))
269
271 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Effects, meta = (EditCondition = "bEnableSubmixSends"))
272 TArray<FSoundSubmixSendInfo> SoundSubmixSends;
273
275 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Effects, meta = (DisplayName = "Post-Effect Bus Sends", EditCondition = "bEnableBusSends"))
277
279 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Effects, meta = (DisplayName = "Pre-Effect Bus Sends", EditCondition = "bEnableBusSends"))
280 TArray<FSoundSourceBusSendInfo> PreEffectBusSends;
281
283 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Sound)
284 uint8 bIsUISound : 1;
285
287 UPROPERTY()
288 uint8 bIsPreviewSound : 1;
289
291 uint8 bAlwaysPlay : 1;
292
297
301 AUDIOMIXER_API void CreateAudioComponent();
302
304 AUDIOMIXER_API UAudioComponent* GetAudioComponent();
305
309 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Sound, meta = (ClampMin = "0", UIMin = "0"))
310 int32 EnvelopeFollowerAttackTime;
311
315 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Sound, meta = (ClampMin = "0", UIMin = "0"))
316 int32 EnvelopeFollowerReleaseTime;
317
318 UPROPERTY(BlueprintAssignable)
319 FOnSynthEnvelopeValue OnAudioEnvelopeValue;
320
322 FOnSynthEnvelopeValueNative OnAudioEnvelopeValueNative;
323
324 AUDIOMIXER_API void OnAudioComponentEnvelopeValue(const UAudioComponent* AudioComponent, const USoundWave* SoundWave, const float EnvelopeValue);
325
326 // Adds and removes audio buffer listener
329
330 AUDIOMIXER_API virtual USoundClass* GetSoundClass();
331
333
335
336 // Method to execute parameter changes on game thread in audio render thread
337 AUDIOMIXER_API void SynthCommand(TFunction<void()> Command);
338
339 // Called when synth is created.
340 virtual bool Init(int32& SampleRate) { return true; }
341
342 UE_DEPRECATED(4.26, "Use OnBeginGenerate to get a callback before audio is generating on the audio render thread")
343 virtual void OnStart() {}
344
345 UE_DEPRECATED(4.26, "Use OnEndGenerate to get a callback when audio stops generating on the audio render thread")
346 virtual void OnStop() {}
347
348 // Called when the synth component begins generating audio in render thread
349 virtual void OnBeginGenerate() {}
350
351 // Called when the synth has finished generating audio on the render thread
352 virtual void OnEndGenerate() {}
353
354 // Called when more audio is needed to be generated
355 // This method of generating audio is soon to be deprecated. For all new synth components, create an FSoundGenerator instance and implement CreateSoundGenerator method to create an instance.
356 virtual int32 OnGenerateAudio(float* OutAudio, int32 NumSamples) { return 0; }
357
358 // Implemented by the synth component to create a generator object instead of generating audio directly on the synth component.
359 // This method prevents UObjects from having to exist in the audio render thread.
361
362 // Called by procedural sound wave
363 // Returns the number of samples actually generated
364 AUDIOMIXER_API int32 OnGeneratePCMAudio(float* GeneratedPCMData, int32 NumSamples);
365
366 // Gets the audio device associated with this synth component
367 AUDIOMIXER_API FAudioDevice* GetAudioDevice() const;
368
369 // Can be set by the derived class, defaults to 2
371
372 // Can be set by the derived class- sets the preferred callback size for the synth component.
374
375private:
376 // Creates the synth component's sound generator, calls into overridden client code to create the instance.
377 AUDIOMIXER_API ISoundGeneratorPtr CreateSoundGeneratorInternal(const FSoundGeneratorInitParams& InParams);
378
381
383 TObjectPtr<UAudioComponent> AudioComponent;
384
385 AUDIOMIXER_API void PumpPendingMessages();
386
387#if SYNTH_GENERATOR_TEST_TONE
390#endif
391
392 // Whether or not synth is playing
393 bool bIsSynthPlaying;
394 bool bIsInitialized;
395
396 TQueue<TFunction<void()>> CommandQueue;
397
398 // Synth component's handle to its sound generator instance.
399 // used to forward BP functions to the instance directly.
400 ISoundGeneratorPtr SoundGenerator;
401
402 friend class USynthSound;
403};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
EAudioFaderCurve
Definition AudioComponent.h:113
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:58
#define DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(DelegateName, Param1Type, Param1Name)
Definition DelegateCombinations.h:53
void Init()
Definition LockFreeList.h:4
#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 GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
@ Stop
Definition PrecomputedVolumetricLightmapStreaming.cpp:26
EModulationDestination
Definition SoundModulationDestination.h:43
EModulationRouting
Definition SoundModulationDestination.h:27
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition SinOsc.h:17
Definition Archive.h:1208
Definition AudioDevice.h:417
Definition UObjectGlobals.h:1292
Definition SynthComponent.h:26
virtual void OnGeneratedBuffer(const float *AudioBuffer, const int32 NumSamples, const int32 NumChannels)=0
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition Queue.h:48
Definition AudioBus.h:76
virtual COREUOBJECT_API void BeginDestroy()
Definition Obj.cpp:1071
Definition SoundAttenuation.h:444
Definition SoundClass.h:209
Definition SoundConcurrency.h:217
FSoundConcurrencySettings Concurrency
Definition SoundConcurrency.h:222
Definition SoundEffectSource.h:49
Definition IAudioModulation.h:223
Definition SoundSubmix.h:174
Definition SoundWaveProcedural.h:28
Definition SoundWave.h:417
Definition SynthComponent.h:80
virtual int32 OnGenerateAudio(float *OutAudio, int32 NumSamples)
Definition SynthComponent.h:356
virtual ISoundGeneratorPtr CreateSoundGenerator(const FSoundGeneratorInitParams &InParams)
Definition SynthComponent.h:360
int32 PreferredBufferLength
Definition SynthComponent.h:373
virtual void OnEndGenerate()
Definition SynthComponent.h:352
virtual void OnBeginGenerate()
Definition SynthComponent.h:349
int32 NumChannels
Definition SynthComponent.h:370
Definition SynthComponent.h:46
TWeakObjectPtr< USynthComponent > & GetOwningSynthComponentPtr()
Definition SynthComponent.h:72
Type
Definition AudioMixerTypes.h:11
Type
Definition EngineTypes.h:3431
Definition UnrealType.h:6865
Definition SoundAttenuation.h:139
Definition SoundGenerator.h:17
Definition SoundModulationDestination.h:134
Definition SoundSourceBusSend.h:27
Definition SoundSubmixSend.h:146
Definition ObjectPtr.h:488
Definition WeakObjectPtrTemplates.h:25