UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
radfft.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#ifndef RADFFT_H
3#define RADFFT_H
4
5#include "egttypes.h"
6
7#ifdef __RADCONSOLE__
8#define RADFFT_ALIGN 32
9#define RADFFT_AVX // We know it's always there, might as well use it!
10#else
11#define RADFFT_ALIGN 16
12#endif
13
14#ifdef WRAP_PUBLICS
15#define rfmerge3(name,add) name##add
16#define rfmerge2(name,add) rfmerge3(name,add)
17#define rfmerge(name) rfmerge2(name,WRAP_PUBLICS)
18#define radfft_init rfmerge(radfft_init)
19#define radfft_cfft rfmerge(radfft_cfft)
20#define radfft_cifft rfmerge(radfft_cifft)
21#define radfft_rfft rfmerge(radfft_rfft)
22#define radfft_rifft rfmerge(radfft_rifft)
23#define radfft_dct rfmerge(radfft_dct)
24#define radfft_idct rfmerge(radfft_idct)
25#define radfft_idct_to_S16 rfmerge(radfft_idct_to_S16)
26#define radfft_idct_to_S16_stereo_interleave rfmerge(radfft_idct_to_S16_stereo_interleave)
27#endif
28
29
30// Complex numbers are returned in this form
31typedef struct rfft_complex
32{
33 F32 re; // real part
34 F32 im; // imaginary part
36
37// Initialize. Call this first!
39
40// Complex FFT. Computes
41// out[k] = sum_{j=0}^{N-1} in[k] * exp(-i*2*pi/N * (j*k))
42//
43// This is the typical FFT definition (negative sign in the exponential).
44//
45// N must be a power of 2, "in" and "out" must be aligned to
46// RADFFT_ALIGN.
48
49// Complex IFFT. Computes
50// out[k] = sum_{j=0}^{N-1} in[k] * exp(i*2*pi/N * (j*k))
51//
52// This is the typical IFFT definition (positive sign in the exponential).
53//
54// cifft(fft(x)) = x * N
55//
56// N must be a power of 2, "in" and "out" must be aligned to
57// RADFFT_ALIGN.
59
60// Real FFT of N elements in[0..N-1].
61// This computes (except for out[0] and out[N/2], see below!)
62// out[k] = sum_{j=0}^{N-1} in[j] * exp(i*2*pi/N * (j*k))
63//
64// Engineers often use the opposite sign convention (-i instead of i in the
65// "exp"), and so does the "cfft" in here (sorry). We use this convention
66// here because the code this replaced used it.
67//
68// Returns the first half of the N complex FFT coeffs in out[0..N/2-1].
69// The DC bin out[0] is always real for a real FFT.
70// We use the imaginary part of out[0] to hold the (also always real) Nyquist bin
71// that would otherwise be in out[N/2].
72//
73// N must be a power of 2, "in" and "out" must be aligned to
74// RADFFT_ALIGN.
76
77// Real IFFT matching "radfft_rfft".
78// This computes
79// out[k] = (1/2) * sum_{j=0}^{N-1} in'[j] * exp(-i*2*pi/N * (j*k))
80// where
81// in'[0] = real(in[0])
82// in'[N/2] = imag(in[0])
83// in'[k] = in[k], 1 <= k < N/2
84// in'[N-k] = conj(in[k]), 1 <= k < N/2
85//
86// i.e. "in'" is "in" expanded from N/2 to N values with conjugate (Hermitian)
87// symmetry (whew). Same comment as for "rfft" applies: this is the opposite
88// exponent sign convention from what's typical in engineering, but it matches
89// the code we're replacing.
90//
91// With these rules, we have
92// rifft(rfft(x)) == (N/2) * x
93//
94// N must be a power of 2, "in" and "out" must be aligned to
95// RADFFT_ALIGN.
97
98// DCT-II
99//
100// Computes the type-II discrete cosine transform ("the" DCT) of "in":
101// out[k] = sum_{j=0}^{N-1} in[j] * cos(pi/N * (j+0.5)*k)
102//
103// Input data is in in[0..N-1]; output is written to out[0..N-1].
104// The input data is destroyed.
105//
106// N must be a power of 2, "in" and "out" must be aligned to
107// RADFFT_ALIGN.
108RADDEFFUNC void RADLINK radfft_dct(F32 out[], F32 in[], UINTa N);
109
110// DCT-III
111//
112// Computes the type-III discrete cosine transform ("the" inverse DCT) of "in":
113// out[k] = sum_{j=0}^{N-1} in[j] * cos(pi/N * j*(k+0.5))
114//
115// Input data is in in[0..N-1]; output is written to out[0..N-1].
116// The input data is destroyed.
117//
118// Note that this is using the standard normalization which means it's only
119// *almost* an inverse of "dct"; to be precise, the inverse of
120//
121// dct(data, work, N)
122//
123// is
124//
125// data[0] *= 0.5f;
126// idct(data, work, N);
127// // scale data by 2/N
128//
129// N must be a power of 2, "in" and "out" must be aligned to
130// RADFFT_ALIGN.
131RADDEFFUNC void RADLINK radfft_idct(F32 out[], F32 in[], UINTa N);
134
135#endif
RAD_S16 S16
Definition egttypes.h:486
RAD_UINTa UINTa
Definition egttypes.h:531
#define RADLINK
Definition egttypes.h:289
#define RADDEFFUNC
Definition egttypes.h:66
RAD_F32 F32
Definition egttypes.h:516
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool left(const int *a, const int *b, const int *c)
Definition RecastMesh.cpp:182
RADDEFFUNC void RADLINK radfft_cifft(rfft_complex out[], rfft_complex const in[], UINTa N)
Definition radfft.cpp:2145
RADDEFFUNC void RADLINK radfft_init()
Definition radfft.cpp:2119
RADDEFFUNC void RADLINK radfft_idct_to_S16(S16 outs16[], F32 scale, F32 tmp[], F32 in[], UINTa N)
Definition radfft.cpp:2269
RADDEFFUNC void RADLINK radfft_rifft(F32 out[], rfft_complex in[], UINTa N)
Definition radfft.cpp:2229
RADDEFFUNC void RADLINK radfft_rfft(rfft_complex out[], F32 const in[], UINTa N)
Definition radfft.cpp:2163
RADDEFFUNC void RADLINK radfft_idct_to_S16_stereo_interleave(S16 outs16[], S16 left[], F32 scale, F32 tmp[], F32 in[], UINTa N)
Definition radfft.cpp:2282
RADDEFFUNC void RADLINK radfft_cfft(rfft_complex out[], rfft_complex const in[], UINTa N)
Definition radfft.cpp:2127
RADDEFFUNC void RADLINK radfft_dct(F32 out[], F32 in[], UINTa N)
Definition radfft.cpp:2203
RADDEFFUNC void RADLINK radfft_idct(F32 out[], F32 in[], UINTa N)
Definition radfft.cpp:2256
Definition radfft.h:32
F32 im
Definition radfft.h:34
F32 re
Definition radfft.h:33