UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OnePole.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/Dsp.h"
7
8namespace Audio
9{
10 // Simple 1-pole lowpass filter
12 {
13 public:
14
15 // Constructor
17 : CutoffFrequency(0.0f)
18 , B1(0.0f)
19 , A0(1.0f)
20 , Z1(0.0f)
21 {}
22
23 // Set the LPF gain coefficient
24 inline void SetG(float InG)
25 {
26 B1 = InG;
27 A0 = 1.0f - B1;
28 }
29
30 // Resets the sample delay to 0
31 void Reset()
32 {
33 B1 = 0.0f;
34 A0 = 1.0f;
35 Z1 = 0.0f;
36 }
37
39 inline void SetFrequency(const float InFrequency)
40 {
42 {
44 B1 = FMath::Exp(-PI * CutoffFrequency);
45 A0 = 1.0f - B1;
46 }
47 }
48
49 inline float ProcessAudioSample(const float InputSample)
50 {
51 const float Yn = InputSample*A0 + B1*Z1;
52 Z1 = Yn;
53 return Yn;
54 }
55
56 protected:
58
59 // Filter coefficients
60 float B1;
61 float A0;
62
63 // 1-sample delay
64 float Z1;
65 };
66
67 // one pole LPF filter for multiple channels
69 {
70 public:
72 : DelayPtr(nullptr)
73 , NumChannels(1)
74 , CutoffFrequency(-1.0f)
75 , B1(0.0f)
76 , A0(1.0f)
77 {
78 Z1.Init(0.0f, NumChannels);
80 }
81
91
92 // Set the LPF gain coefficient
93 inline void SetG(float InG)
94 {
95 B1 = InG;
96 A0 = 1.0f - B1;
97 }
98
99 // Clears memory without reevaluating coefficients. This function is useful when there is a break between ProcessAudio calls.
101 {
103 }
104
105 // Resets the sample delay to 0
106 void Reset()
107 {
108 B1 = 0.0f;
109 A0 = 1.0f;
110 ClearMemory();
111 }
112
114 void SetFrequency(const float InFrequency)
115 {
117 {
119 float NormalizedFreq = FMath::Clamp(2.0f * InFrequency / SampleRate, 0.0f, 1.0f);
120 B1 = FMath::Exp(-PI * NormalizedFreq);
121 A0 = 1.0f - B1;
122 }
123 }
124
125 inline void ProcessAudio(float* InputFrame, float* OutputFrame)
126 {
127 for (int32 i = 0; i < NumChannels; ++i)
128 {
129 const float Yn = InputFrame[i] * A0 + B1*DelayPtr[i];
130 DelayPtr[i] = Yn;
131 OutputFrame[i] = Yn;
132 }
133 }
134
135 protected:
136
138 float* DelayPtr;
142 float B1;
143 float A0;
144 };
145
146}
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 PI
Definition UnrealMathUtility.h:65
Definition OnePole.h:69
float A0
Definition OnePole.h:143
void ClearMemory()
Definition OnePole.h:100
FOnePoleLPFBank()
Definition OnePole.h:71
void SetG(float InG)
Definition OnePole.h:93
int32 NumChannels
Definition OnePole.h:139
void Reset()
Definition OnePole.h:106
void SetFrequency(const float InFrequency)
Definition OnePole.h:114
int32 SampleRate
Definition OnePole.h:141
void Init(int32 InSampleRate, int32 InNumChannels)
Definition OnePole.h:82
float * DelayPtr
Definition OnePole.h:138
float CutoffFrequency
Definition OnePole.h:140
float B1
Definition OnePole.h:142
TArray< float > Z1
Definition OnePole.h:137
void ProcessAudio(float *InputFrame, float *OutputFrame)
Definition OnePole.h:125
Definition OnePole.h:12
float B1
Definition OnePole.h:60
void SetG(float InG)
Definition OnePole.h:24
float ProcessAudioSample(const float InputSample)
Definition OnePole.h:49
void SetFrequency(const float InFrequency)
Definition OnePole.h:39
float A0
Definition OnePole.h:61
void Reset()
Definition OnePole.h:31
float CutoffFrequency
Definition OnePole.h:57
float Z1
Definition OnePole.h:64
FOnePoleLPF()
Definition OnePole.h:16
Definition Array.h:670
void SetNumZeroed(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2340
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
static UE_FORCEINLINE_HINT bool IsNearlyEqual(float A, float B, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:388
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592