UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
radaudio_common.h
Go to the documentation of this file.
1// Copyright Epic Games Tools, LLC. All Rights Reserved.
2#ifndef RADAUDIO_COMMON_H
3#define RADAUDIO_COMMON_H
4
5#define MAX_VALID_VERSION 1
6
7#include "rrCore.h"
8
9#ifdef RADAUDIO_DEVELOPMENT
10#include "rrTime.h"
11#endif
12
13// sets up what SIMD kernels we build.
14#include "radaudio_sse.h"
15
16// determined by the FFT code
17#define FFT_ALIGN(type, name) RAD_ALIGN(type, name, 64)
18
19// rather than fight with whether math.h is included we just name our own.
20#define RADAUDIO_PI 3.1415926535897932384626433832795028
21
22#ifndef __cplusplus
23enum { false, true };
24#endif
25
26#define RADAUDIO_LONG_BLOCK_LEN 1024 // number of mdct coefficients for a long block
27#define RADAUDIO_SHORT_BLOCK_LEN 128 // number of mdct coefficients for a short block
28
29#define MAX_BANDS 24
30#define MAX_COEFFS 1024
31#define MAX_SUBBANDS 72
32#define MAX_SUBBANDS_QUANTIZED 56
33#define MAX_MDCT_SAMPLES 2048
34#define MAX_RADAUD_CHANNELS 2
35#define MAX_COEFF_PER_BAND 512
36#define MAX_COEFF_PER_SUBBAND 32
37
38#define MAX_RUNLEN 240
39#define END_OF_ZERORUN 255 // token indicating end of the zero-runlength data
40#define COARSE_RUNLEN_THRESHOLD 60 // runlengths larger than this have bottom two bits sent by varbits
41#define PREDICT_FIRST_BAND_EXP 0 // exponent to use as prediction for first band of left channel
42
43#define MAX_FINE_ENERGY_BITS 16
44#define COEFFS_PER_SUBBAND 16 // maximum
45
46#define EXPONENT_NEGATIVE_INFINITY -17 // encoding of -inf exponent, i.e. 0 amplitude
47#define EXPONENT_NEGATIVE_16 -16 // encoding of -16 exponent
48#define EXPONENT_ZERO 0
49#define EXPONENT_POSITIVE_14 14
50#define BAND_EXPONENT_NONE -17 // encoding indicating no data in band, i.e. -inf
51
52#define SUBBANDS_SKIP_EMPTY_BANDS true
53
54#define MACRO_BAND_SIZE 3
55#define LARGEST_BIASED_SUBBAND 63
56#define SUBBAND_BIAS_CENTER 12
57
58#define NUM_NZ_MODE 4 // num long block modes
59#define NUM_SELECTOR_MODES (NUM_NZ_MODE+1) // short blocks get separate selectors
60#define NUM_NZ_SELECTOR 4 // num selectors per mode
61#define NUM_NZ_HUFF 6 // number of nonzero huffman tables
62#define MAX_NZ_BLOCKS 12 // maximum number of nonzero 8-byte blocks
63
64#define CLAMPED_INTEGER_EXPONENT_TO_CODED_EXPONENT(is_neg_inf, n) \
65 (is_neg_inf ? EXPONENT_NEGATIVE_INFINITY \
66 : (n))
67
68#define CODED_EXPONENT_TO_INTEGER(n) (n)
69
70#define MAX_ENCODED_BLOCK_BYTES 16383
71
72typedef struct
73{
74 #ifdef __RADX86__
80 U8 padding[3];
81 #else
82 U8 dummy[8];
83 #endif
85
93#define RADAUDIO_NUM_RATES 4
94
95// block sizes
96enum
97{
100};
101
102// certain values are encoded in the block headers as biased numbers,
103// as 1 or 2 bytes depending on if the biased value fits in 1 byte
104typedef struct
105{
106 U16 bytes_bias[2][3]; // bias for blocktype, num_channels
108
109typedef struct
110{
114
116 S8 mantissa_param[2][MAX_BANDS][2];
117 U8 subband_predicted_sum[MAX_BANDS];
118 S8 subband_bias[MAX_BANDS];
120 U8 nzmode_num64[NUM_NZ_MODE]; // num64[3] is always 0 (not transmitted)
121 S8 nzmode_huff[3][12];
122 U8 nzmode_selectors[NUM_NZ_SELECTOR][NUM_SELECTOR_MODES]; // other huffman table selectors
124
125typedef struct
126{
127 // first 3-4 members get initialized by data
129 U8 huffman_table_for_chunk[MAX_NZ_BLOCKS];
130 U8 invert_chunk[MAX_NZ_BLOCKS]; // 0 (don't invert) or 1 (invert)
131
132 // remaining members get initialized by code
133 U8 num_chunks_per_huff[NUM_NZ_HUFF];
134 U8 source_pos[3][MAX_NZ_BLOCKS]; // for each channel, where its source offset is, in blocks, separately for left & right
136
137typedef struct
138{
142 int band_exponent[MAX_BANDS]; // MAX_BANDS
143 U8 band_mantissa_bitcount[MAX_BANDS]; // MAX_BANDS
144 int band_mantissa[MAX_BANDS]; // MAX_BANDS
145 U16 quantized_subbands[MAX_SUBBANDS+7]; // excess_read7
146 S8 quantized_coeff_decode[MAX_COEFFS];
147 union {
148 int quantized_coeff_encode[MAX_COEFFS]; // encoder uses this space for full-size quantized coeffs
149 FFT_ALIGN(F32, dequantized_coeff_decode[MAX_COEFFS]); // decoder uses it for float dequantized coeffs
150 };
152
153typedef struct
154{
155 int rate;
162 int num_coeffs_for_band [MAX_BANDS];
163 int num_subbands_for_band [MAX_BANDS]; // only long blocks
164
165 // computed values:
166 int first_subband_for_band [MAX_BANDS];
167 int first_coeff_for_band [MAX_BANDS];
168 int num_coeffs_for_subband [MAX_SUBBANDS];
169 int first_coeff_for_subband[MAX_SUBBANDS];
170 float band_scale_encode [MAX_BANDS];
171 float band_scale_decode [MAX_BANDS];
173
193
194typedef struct
195{
199
200typedef struct
201{
205
206typedef struct
207{
208 #ifdef HUFFMAN_ENCODE
210 #endif
211 #ifdef HUFFMAN_DECODE
212 radaudio_huff_symbol decode[2048];
213 #endif
214 #if !defined(HUFFMAN_ENCODE) && !defined(HUFFMAN_DECODE)
215 int dummy; // so struct isn't empty (which is not allowed)
216 #endif
218
219// BCPL lcg
220#define LCG_MUL 2147001325
221#define LCG_ADD 715136305
222
223static RADINLINE U32 lcg(U32 value)
224{
225 return value * LCG_MUL + LCG_ADD;
226}
227#endif
RAD_S8 S8
Definition egttypes.h:476
RAD_U32 U32
Definition egttypes.h:501
RAD_U8 U8
Definition egttypes.h:481
S32 rrbool
Definition egttypes.h:536
RAD_F32 F32
Definition egttypes.h:516
#define RADINLINE
Definition egttypes.h:387
RAD_U16 U16
Definition egttypes.h:491
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define MAX_BANDS
Definition radaudio_common.h:29
#define LCG_ADD
Definition radaudio_common.h:221
#define MAX_SUBBANDS
Definition radaudio_common.h:31
#define NUM_NZ_HUFF
Definition radaudio_common.h:61
#define MAX_NZ_BLOCKS
Definition radaudio_common.h:62
#define LCG_MUL
Definition radaudio_common.h:220
#define NUM_NZ_SELECTOR
Definition radaudio_common.h:60
#define NUM_NZ_MODE
Definition radaudio_common.h:58
@ RADAUDIO_LONG
Definition radaudio_common.h:98
@ RADAUDIO_SHORT
Definition radaudio_common.h:99
radaudio_samprate_code
Definition radaudio_common.h:87
@ RADA_48000
Definition radaudio_common.h:88
@ RADA_24000
Definition radaudio_common.h:91
@ RADA_32000
Definition radaudio_common.h:90
@ RADA_44100
Definition radaudio_common.h:89
#define MAX_COEFFS
Definition radaudio_common.h:30
#define FFT_ALIGN(type, name)
Definition radaudio_common.h:17
#define NUM_SELECTOR_MODES
Definition radaudio_common.h:59
Definition radaudio_common.h:138
int num_quantized_coeffs
Definition radaudio_common.h:141
int num_bands
Definition radaudio_common.h:139
int num_quantized_subbands
Definition radaudio_common.h:140
Definition radaudio_common.h:105
Definition radaudio_common.h:175
rrbool predict_stereo_exponent
Definition radaudio_common.h:184
rrbool predict_stereo_subband
Definition radaudio_common.h:183
rrbool next_block_short
Definition radaudio_common.h:179
rrbool mid_side_encoded
Definition radaudio_common.h:180
U32 num_runlength_array
Definition radaudio_common.h:189
rrbool disable_final_subband_predict
Definition radaudio_common.h:182
rrbool final_block
Definition radaudio_common.h:176
U32 block_bytes
Definition radaudio_common.h:188
rrbool this_block_short
Definition radaudio_common.h:178
rrbool mid_side_bands
Definition radaudio_common.h:185
rrbool prev_block_short
Definition radaudio_common.h:177
unsigned int nonzero_bitarray_mode
Definition radaudio_common.h:186
unsigned int num_channels_encoded
Definition radaudio_common.h:181
U32 vbstream0_length
Definition radaudio_common.h:190
U32 final_samples_discard
Definition radaudio_common.h:191
Definition radaudio_common.h:73
Definition radaudio_common.h:201
U8 length
Definition radaudio_common.h:203
U16 code
Definition radaudio_common.h:202
Definition radaudio_common.h:195
U8 length
Definition radaudio_common.h:196
U8 symbol
Definition radaudio_common.h:197
Definition radaudio_common.h:207
int dummy
Definition radaudio_common.h:215
Definition radaudio_common.h:126
U8 num_8byte_chunks
Definition radaudio_common.h:128
Definition radaudio_common.h:154
int num_quantized_coeffs
Definition radaudio_common.h:157
int num_coeffs
Definition radaudio_common.h:158
int num_bands
Definition radaudio_common.h:156
int num_bands_without_subbands
Definition radaudio_common.h:161
int num_subbands
Definition radaudio_common.h:159
int rate
Definition radaudio_common.h:155
int num_quantized_subbands
Definition radaudio_common.h:160
Definition radaudio_common.h:110
int num_channels
Definition radaudio_common.h:112
U16 bytes_bias
Definition radaudio_common.h:119
int sample_rate
Definition radaudio_common.h:115
U32 version
Definition radaudio_common.h:111
int sample_rate_mode
Definition radaudio_common.h:113