UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AudioFFT.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"
8#include "DSP/Dsp.h"
9#include "DSP/FFTAlgorithm.h"
10
11namespace Audio
12{
13 // Types of spectrums which can be directly derived from FFTFreqDomainData
14
15 enum class ESpectrumType : uint8
16 {
19 };
20
21
22 enum class EWindowType : uint8
23 {
24 None, // No window is applied. Technically a boxcar window.
25 Hamming, // Mainlobe width of -3 dB and sidelove attenuation of ~-40 dB. Good for COLA.
26 Hann, // Mainlobe width of -3 dB and sidelobe attenuation of ~-30dB. Good for COLA.
27 Blackman // Mainlobe width of -3 dB and sidelobe attenuation of ~-60db. Tricky for COLA.
28 };
29
30 // Utility functions for generating different types of windows. Called in FWindow::Generate.
31 SIGNALPROCESSING_API void GenerateRectangularWindow(float* WindowBuffer, int32 NumFrames, int32 NumChannels);
32 SIGNALPROCESSING_API void GenerateHammingWindow(float* WindowBuffer, int32 NumFrames, int32 NumChannels, bool bIsPeriodic);
33 SIGNALPROCESSING_API void GenerateHannWindow(float* WindowBuffer, int32 NumFrames, int32 NumChannels, bool bIsPeriodic);
34 SIGNALPROCESSING_API void GenerateBlackmanWindow(float* WindowBuffer, int32 NumFrames, int32 NumChannels, bool bIsPeriodic);
36
37 // Returns the hop size in samples necessary to maintain constant overlap add.
38 // For more information on COLA, see the following page:
39 // https://ccrma.stanford.edu/~jos/sasp/Overlap_Add_OLA_STFT_Processing.html
41
45 class FWindow
46 {
47 public:
48 FWindow() = delete;
49
60
61 // Apply this window to InBuffer, which is expected to be an interleaved buffer with the same amount of frames
62 // and channels this window was constructed with.
64
66
67 private:
68 EWindowType WindowType;
69 FAlignedFloatBuffer WindowBuffer;
70 int32 NumSamples;
71
72 // Generate the window. Called on constructor.
73 SIGNALPROCESSING_API void Generate(int32 NumFrames, int32 NumChannels, bool bIsPeriodic);
74 };
75
76 // Return the ceiling of the log2 of InNum
78
79 // Return the scaling factor needed to apply to a power spectrum given a current
80 // and target FFT scaling.
82
83 // Scale the power spectrum to remove any scaling introduced by the FFT algorithm
84 // implementation.
86}
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
EWindowType
Definition GenericWindowDefinition.h:17
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AudioFFT.h:46
SIGNALPROCESSING_API EWindowType GetWindowType() const
Definition AudioFFT.cpp:165
SIGNALPROCESSING_API void ApplyToBuffer(float *InBuffer)
Definition AudioFFT.cpp:153
FWindow()=delete
Definition ArrayView.h:139
NO_LOGGING.
Definition AudioMixerPlatformAndroid.cpp:53
void GenerateHannWindow(float *WindowBuffer, int32 NumFrames, int32 NumChannels, bool bIsPeriodic)
Definition AudioFFT.cpp:49
void ScalePowerSpectrumInPlace(int32 FFTSize, EFFTScaling InCurrentScaling, EFFTScaling InTargetScaling, TArrayView< float > InPowerSpectrum)
Definition AudioFFT.cpp:267
float GetPowerSpectrumScaling(int32 FFTSize, EFFTScaling InCurrentScaling, EFFTScaling InTargetScaling)
Definition AudioFFT.cpp:256
void GenerateHammingWindow(float *WindowBuffer, int32 NumFrames, int32 NumChannels, bool bIsPeriodic)
Definition AudioFFT.cpp:31
void GenerateRectangularWindow(float *WindowBuffer, int32 NumFrames, int32 NumChannels)
Definition AudioFFT.cpp:21
ESpectrumType
Definition AudioFFT.h:16
uint32 GetCOLAHopSizeForWindow(EWindowType InType, uint32 WindowLength)
Definition AudioFFT.cpp:126
void GenerateBlackmanWindow(float *WindowBuffer, int32 NumFrames, int32 NumChannels, bool bIsPeriodic)
Definition AudioFFT.cpp:67
int32 CeilLog2(int32 InNum)
Definition AudioFFT.cpp:238
EWindowType
Definition AudioFFT.h:23
void GenerateWindow(float *InOutWindowBuffer, EWindowType InType, int32 InNumFrames, int32 InNumChannels, bool bIsPeriodic)
Definition AudioFFT.cpp:98
EFFTScaling
Definition FFTAlgorithm.h:18