UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Delay.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 "DSP/AlignedBuffer.h"
7#include "DSP/Dsp.h"
8
9namespace Audio
10{
11 // Circular Buffer Delay Line
12 class FDelay
13 {
14 public:
15 // Constructor
17
18 // Virtual Destructor
20
21 // Initialization of the delay with given sample rate and max buffer size in samples.
22 // (calls Reset())
23 SIGNALPROCESSING_API void Init(const float InSampleRate, const float InBufferLengthSec = 2.0f);
24
25 // Resets the delay line state, flushes buffer and resets read/write pointers.
26 // (called by Init())
29
30
31 // Sets the delay line length. Will clamp to within range of the max initialized delay line length (won't resize).
33
34 // Same as SetDelayMsec, except in samples.
36
37 // Sets the delay line length but using the internal easing function for smooth delay line interpolation.
38 SIGNALPROCESSING_API void SetEasedDelayMsec(const float InDelayMsec, const bool bIsInit = false);
39
40 // Sets the easing factor for the delay line's internal exponential interpolator.
42
43 // Sets the output attenuation in DB
45
46 // Returns the current delay line length (in samples).
47 float GetDelayLengthSamples() const { return DelayInSamples; }
48
49 // Reads the delay line at current read index without writing or incrementing read/write pointers.
50 SIGNALPROCESSING_API float Read() const;
51
52 // Reads the delay line at an arbitrary time in Msec without writing or incrementing read/write pointers.
53 SIGNALPROCESSING_API float ReadDelayAt(const float InReadMsec) const;
54
55 // Write the input and increment read/write pointers
57
58 // Process audio in the delay line, return the delayed value
59 SIGNALPROCESSING_API virtual float ProcessAudioSample(const float InAudio);
60
62
63 protected:
64 // Updates delay line based on any recent changes to settings
65 SIGNALPROCESSING_API void Update(bool bForce = false);
66
67 // Updates delay line based on any recent changes to settings
69
70 // Pointer to the circular buffer of audio.
72
73 // Max length of buffer (in samples)
75
76 // Read index for circular buffer.
78
79 // Write index for circular buffer.
81
82 // Sample rate
84
85 // Delay in samples; float supports fractional delay
87
88 // Upper limit of where we will resize the array
90
91 // Eased delay in msec
93
94 // Output attenuation value.
96
97
98 // Attenuation in decibel
100
101 private:
102
103 // Used to do a quick fade-in of input after a call to "ResetWithFade()"
104 float InputAttenuation = 1.f;
105 float InputFadeGainStep = 0.f;
106 };
107
108}
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
void Init()
Definition LockFreeList.h:4
Definition Delay.h:13
int32 WriteIndex
Definition Delay.h:80
SIGNALPROCESSING_API void WriteDelayAndInc(const float InDelayInput)
Definition Delay.cpp:270
virtual SIGNALPROCESSING_API float ProcessAudioSample(const float InAudio)
Definition Delay.cpp:293
SIGNALPROCESSING_API void ResetWithFade()
Definition Delay.cpp:74
FAlignedFloatBuffer AudioBuffer
Definition Delay.h:71
SIGNALPROCESSING_API void SetDelaySamples(const float InDelaySamples)
Definition Delay.cpp:176
float DelayInSamples
Definition Delay.h:86
SIGNALPROCESSING_API void SetDelayMsec(const float InDelayMsec)
Definition Delay.cpp:167
int32 ReadIndex
Definition Delay.h:77
SIGNALPROCESSING_API void ResizeIfNeeded(const int32 InNewNumSamples)
Definition Delay.cpp:341
SIGNALPROCESSING_API float Read() const
Definition Delay.cpp:218
float GetDelayLengthSamples() const
Definition Delay.h:47
SIGNALPROCESSING_API void Reset()
Definition Delay.cpp:63
SIGNALPROCESSING_API float ReadDelayAt(const float InReadMsec) const
Definition Delay.cpp:239
virtual SIGNALPROCESSING_API ~FDelay()
FExponentialEase EaseDelayMsec
Definition Delay.h:92
virtual SIGNALPROCESSING_API void ProcessAudioBuffer(const float *InAudio, int32 InNumSamples, float *OutAudio)
Definition Delay.cpp:302
float OutputAttenuation
Definition Delay.h:95
SIGNALPROCESSING_API void SetOutputAttenuationDB(const float InDelayAttenDB)
Definition Delay.cpp:210
int32 MaxBufferLengthSamples
Definition Delay.h:89
SIGNALPROCESSING_API FDelay()
Definition Delay.cpp:27
int32 AudioBufferSize
Definition Delay.h:74
SIGNALPROCESSING_API void SetEaseFactor(const float InEaseFactor)
Definition Delay.cpp:205
float OutputAttenuationDB
Definition Delay.h:99
float SampleRate
Definition Delay.h:83
SIGNALPROCESSING_API void SetEasedDelayMsec(const float InDelayMsec, const bool bIsInit=false)
Definition Delay.cpp:183
Definition Dsp.h:505
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53