UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
binka_ue_decode.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2//
3// This decodes _blocks_ of bink audio data, not files. Usage is
4// to create a decoder that will decode a stream of mono or stereo
5// audio data, and sequentially feed it blocks of data.
6//
7#pragma once
8#include <stdint.h>
9
10/*
11 UEBinkAudioDecodeInterface* Interface = UnrealBinkAudioDecodeInterface();
12
13 // Allocate the decoder
14 U32 Bytes = Interface->MemoryFn(48000, 2);
15 void* Decoder = malloc(Bytes);
16
17 // Init the decoder memory. Only fails with bad params.
18 Interface->OpenFn(Decoder, 48000, 2, 1);
19
20 // This assumes the blocks are back-to-back (not true for on-disc bink audio files)
21 char* CompressedData;
22 char* CompressedDataEnd = CompressedData + CompressedDataLen;
23 while (CompressedData < CompressedDataEnd)
24 {
25 char OutputBuffer[BinkAudioDecodeOutputMaxSize()];
26 U32 OutputBufferValidLen = Interface->DecodeFn(Decoder, OutputBuffer, BinkAudioDecodeOutputMaxSize(), &CompressedData, CompressedDataEnd);
27
28 if (OutputBufferValidLen == 0)
29 break; // error condition (or if CompressedData doesn't move)
30
31 // work with OutputBuffer.
32 // CompressedData has been updated by DecodeFn to point at the next
33 // data.
34 }
35
36 // Done.
37 free(Decoder);
38*/
39
40// with invalid data, we can read past the InputBuffer during parsing.
41#define BINK_UE_DECODER_EXTRA_INPUT_SPACE 72
42
43// with _normal_ data, we can read past the InputBuffer by 16 bytes
44// due to vector bit decoding. It's highly unlikely that it reads that far,
45// however _some_ amount of reading is all but certain.
46#define BINK_UE_DECODER_END_INPUT_SPACE 16
47
48// For the given rate and channels, this is the memory required for the decoder
49// structure. Max 2 channels. Rates above 48000 are pretty useless as high freqs
50// are crushed.
52
53// Initialize the decoder, returns 0 on invalid parameters. Unreal should always be encoding bink_audio_2
55
56// Decode a single block. InputBuffer is updated with the amount of compressed data consumed for the block.
57// Output is 16 bit pcm, interleaved if OpenFn() specified interleave_output.
59
60// Call this when seeking/looping, this clears the overlap buffers.
62
70
72
73// what is the maximum data that can be touched of the output for ANY Bink file
74// OutputBufferLen never needs to be larger than this for 1 block.
75#define BinkAudioDecodeOutputMaxSize() ( 2048 * sizeof(int16_t) * 2 ) // 2 is channels
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void DecodeResetStartFrameFnType(void *BinkAudioDecoderMemory)
Definition binka_ue_decode.h:61
uint32_t DecodeOpenFnType(void *BinkAudioDecoderMemory, uint32_t rate, uint32_t chans, bool interleave_output, bool is_bink_audio_2)
Definition binka_ue_decode.h:54
uint32_t DecodeFnType(void *BinkAudioDecoderMemory, uint8_t *OutputBuffer, uint32_t OutputBufferLen, uint8_t const **InputBuffer, uint8_t const *InputBufferEnd)
Definition binka_ue_decode.h:58
uint32_t DecodeMemoryFnType(uint32_t rate, uint32_t chans)
Definition binka_ue_decode.h:51
UEBinkAudioDecodeInterface * UnrealBinkAudioDecodeInterface()
Definition binka_ue_decode.cpp:61
char * InputBufferEnd
Definition binka_ue_decode_test.cpp:31
char const * InputBuffer
Definition binka_ue_decode_test.cpp:29
Definition binka_ue_decode.h:64
DecodeFnType * DecodeFn
Definition binka_ue_decode.h:67
DecodeMemoryFnType * MemoryFn
Definition binka_ue_decode.h:65
DecodeOpenFnType * OpenFn
Definition binka_ue_decode.h:66
DecodeResetStartFrameFnType * ResetStartFn
Definition binka_ue_decode.h:68