UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
radaudio_decoder.h
Go to the documentation of this file.
1// Copyright Epic Games Tools, LLC. All Rights Reserved.
2#ifndef INCLUDE_RADAUDIO_DECODER_H
3#define INCLUDE_RADAUDIO_DECODER_H
4
5#include "egttypes.h"
6#include <stddef.h>
7
9
18
19#define RADAUDIO_DECODER_AT_EOF -1
20#define RADAUDIO_DECODER_INCOMPLETE_DATA -2
21#define RADAUDIO_DECODER_INVALID_DATA -3
22#define RADAUDIO_DECODER_START_OF_STREAM -4
23#define RADAUDIO_DECODER_INTERNAL_ERROR -5
24#define RADAUDIO_DECODER_MAX_OUTPUT_SAMPLES_PER_CHANNEL_PER_CHUNK 1024
25
27
28// RADAUDIO compatibility version - if these are the same the exports are named the same so we expect
29// that if the linker selects a different copy they all work.
30#define RADAUDIO_DECODER_LIBRARY_VERSION 1
31
32#define RADAUDIO_DECODER_HAS_INTERLEAVING
33
34// The max size of a stream header. It could be smaller but this is a safe size
35// for buffers.
36#define RADAUDIO_STREAM_HEADER_SIZE 128
37
38#ifndef RR_STRING_JOIN3
39#define RR_STRING_JOIN3(arg1, arg2, arg3) RR_STRING_JOIN_DELAY3(arg1, arg2, arg3)
40#define RR_STRING_JOIN_DELAY3(arg1, arg2, arg3) RR_STRING_JOIN_IMMEDIATE3(arg1, arg2, arg3)
41#define RR_STRING_JOIN_IMMEDIATE3(arg1, arg2, arg3) arg1 ## arg2 ## arg3
42#endif
43
44#ifdef RADAUDIO_WRAP
45#define RADAUDIO_DECODER_NAME(name) RR_STRING_JOIN3(RADAUDIO_WRAP, name##_, RADAUDIO_DECODER_LIBRARY_VERSION )
46#else
47#define RADAUDIO_DECODER_NAME(name) RR_STRING_JOIN( name##_, RADAUDIO_DECODER_LIBRARY_VERSION )
48#endif
49
50#define RadAudioDecoderMemoryRequired RADAUDIO_DECODER_NAME(RadAudioDecoderMemoryRequired)
51#define RadAudioDecoderOpen RADAUDIO_DECODER_NAME(RadAudioDecoderOpen)
52#define RadAudioDecoderGetInfo RADAUDIO_DECODER_NAME(RadAudioDecoderGetInfo)
53#define RadAudioDecoderGetInfoHeader RADAUDIO_DECODER_NAME(RadAudioDecoderGetInfoHeader)
54#define RadAudioDecoderDecodeChunk RADAUDIO_DECODER_NAME(RadAudioDecoderDecodeChunk)
55#define RadAudioDecoderGetProfileData RADAUDIO_DECODER_NAME(RadAudioDecoderGetProfileData)
56#define RadAudioDecoderDidSeek RADAUDIO_DECODER_NAME(RadAudioDecoderDidSeek)
57#define RadAudioDecoderGetChunkLength RADAUDIO_DECODER_NAME(RadAudioDecoderGetChunkLength)
58
59#define RadAudioInterleave RADAUDIO_DECODER_NAME(RadAudioInterleave)
60#define RadAudio1ChToS16 RADAUDIO_DECODER_NAME(RadAudio1ChToS16)
61#define RadAudioInterleave2ChToS16 RADAUDIO_DECODER_NAME(RadAudioInterleave2ChToS16)
62#define RadAudioInterleave4ChToS16 RADAUDIO_DECODER_NAME(RadAudioInterleave4ChToS16)
63
64// RadAudioDecoderMemoryRequired()
65//
66// returns the amount of memory that needs to be passed to Open().
67// stereo requires more than mono. Returns 0 if the header is invalid.
68//
69// Pass in NULL to get the maximum size required for any stream.
71
72// RadAudioDecoderOpen()
73//
74// returns a pointer to a decoder structure that is allocated in 'mem'.
75// you don't need to close it, just dispose of the memory yourself when done
76//
77// returns NULL if header is invalid or if memsize is smaller than RadAudioDecoderMemoryRequired()
78// or if stream_header_bytes_valid is too small (needs to be RADAUDIO_STREAM_HEADER_SIZE bytes)
79//
80// if the header is large enough to be read, the size of the header will be written
81// to *header_size
82//
83// there is no RadAudioDecoderClose() function as the structure holds no resources;
84// just free the memory you passed in as necessary
86 size_t memsize, size_t *out_header_size);
87
88// RadAudioDecoderGetInfo*
89//
90// return info about the decoder either from an unopened stream header or an open
91// decoder.
92//
93//
95
96// returns size of the header on success, false if not a valid stream header
98
99
100// RadAudioDecoderChunk()
101//
102// - `radaudio_decoder`: a pointer to a decoder created with `RadAudioDecoderOpen()`
103// - `data` : pointer to the next chunk of compressed data to decode
104// - `data_avail` : the length of the data pointed to by `data`
105// - `data_consumed` : output value, the amount of data consumed decoding this chunk
106// - `output_samples` : a pointer to an array of pointers where to write the output, one pointer per channel
107// - `max_samples` : the maximum number of samples that can be written to each of the `output_samples` pointers
108//
109// For the first call, `data` should either point to the full stream (that is,
110// it points to the stream header), or it can point to the first block output by
111// radaudio_encode_block (e.g. if you store the stream header separately from
112// the sequence of blocks in the stream).
113//
114// returns the number of samples output per channel, and sets `data_consumed`
115// to the number of bytes of input data consumed... you should advance `data`
116// by this much. data_consumed can be 0 if there wasn't enough data.
117//
118// Note that 0 is a valid "number of samples" decoded, it means it decoded a
119// block but there were no samples fully decoded due to the way the codec works. (This
120// should only happen at the start of the stream and after seeks.)
121//
122// returns RADAUDIO_DECODER_AT_EOF if at the "end of stream", i.e. there's no more data in the audio stream
123// returns RADAUDIO_DECODER_INCOMPLETE_DATA if there's not enough data to decode a block
124// returns RADAUDIO_DECODER_INVALID_DATA if the block is invalid
126 size_t *data_consumed, F32 *(output_samples[2]), size_t max_samples);
127
128// Returns the length of the next block, given the block header (needs as much as 6 bytes).
129//
130// returns RADAUDIO_DECODER_AT_START_OF_STREAM if you pass in the stream header instead of the block header
131// returns RADAUDIO_DECODER_AT_EOF if at the "end of stream", i.e. there's no more data expected in the audio stream (regardless of the block you pass in)
132// returns RADAUDIO_DECODER_INCOMPLETE_DATA if there's not enough data to decode the block header
133// returns RADAUDIO_DECODER_INVALID_DATA if the block header is invalid
135
136// inform the decoder that you performed a seek operation on the input stream,
137// such that the next decoder call is not continuous with the previous one.
139
140
141
142// utility function to interleave N buffers of float data into one output buffer of S16 (scales and clamps from -1.0 to 1 into -32768 to 32767)
143RADDEFFUNC void RadAudioInterleave( S16 * output, float const ** inputs, U32 input_count, U32 samples );
144
145// low level direct routines, if these return 0, then they converted NOTHING (the sample count is too small for even one SIMD round).
146// if they return 1, then the ENTIRE buffer was converted.
147RADDEFFUNC int RadAudio1ChToS16( S16 * output, float const * input, U32 samples );
148RADDEFFUNC int RadAudioInterleave2ChToS16( S16 * output, float const * input_left, float const * input_right, U32 samples );
149RADDEFFUNC int RadAudioInterleave4ChToS16( S16 * output, float const * input_left, float const * input_right, float const * input_back_left, float const * input_back_right, U32 samples );
150
152
153#endif
#define RADDEFEND
Definition egttypes.h:68
RAD_S16 S16
Definition egttypes.h:486
RAD_U32 U32
Definition egttypes.h:501
RAD_U8 U8
Definition egttypes.h:481
#define RADDEFSTART
Definition egttypes.h:67
#define RADDEFFUNC
Definition egttypes.h:66
RAD_F32 F32
Definition egttypes.h:516
RAD_U16 U16
Definition egttypes.h:491
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define RadAudio1ChToS16
Definition radaudio_decoder.h:60
#define RadAudioDecoderDidSeek
Definition radaudio_decoder.h:56
#define RadAudioDecoderGetInfo
Definition radaudio_decoder.h:52
#define RadAudioDecoderOpen
Definition radaudio_decoder.h:51
#define RadAudioDecoderDecodeChunk
Definition radaudio_decoder.h:54
#define RadAudioDecoderGetChunkLength
Definition radaudio_decoder.h:57
#define RadAudioDecoderGetInfoHeader
Definition radaudio_decoder.h:53
#define RadAudioDecoderMemoryRequired
Definition radaudio_decoder.h:50
#define RadAudioInterleave
Definition radaudio_decoder.h:59
#define RadAudioInterleave2ChToS16
Definition radaudio_decoder.h:61
#define RadAudioInterleave4ChToS16
Definition radaudio_decoder.h:62
Definition RadAudioInfo.cpp:29
Definition radaudio_decoder.h:11
int sample_rate
Definition radaudio_decoder.h:15
U8 major_version
Definition radaudio_decoder.h:14
U16 sequential_version
Definition radaudio_decoder.h:12
int num_channels
Definition radaudio_decoder.h:16
U8 minor_version
Definition radaudio_decoder.h:13