UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Adpcm.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "HAL/Platform.h"
6
7namespace ADPCM
8{
9 // Returns true if successful, false if there was an error in decoding
10 bool DecodeBlock(const uint8* EncodedADPCMBlock, const int32 BlockSize, int16* DecodedPCMData, const int32 DecodedPCMSize);
11 bool DecodeBlock(const uint8* EncodedADPCMBlock, const int32 BlockSize, int16* DecodedPCMData);
12} //namespace ADPCM
13
14namespace ADPCMPrivate
15{
17 // Copied from IOS - probably want to split and share
19
20 template <typename T, uint32 B>
21 inline T SignExtend(const T ValueToExtend)
22 {
23 struct { T ExtendedValue : B; } SignExtender;
24 return SignExtender.ExtendedValue = ValueToExtend;
25 }
26
27 template <typename T>
28 inline T ReadFromByteStream(const uint8* ByteStream, int32& ReadIndex, bool bLittleEndian = true)
29 {
30 T ValueRaw = 0;
31
32 if (bLittleEndian)
33 {
34#if PLATFORM_LITTLE_ENDIAN
35 for (int32 ByteIndex = 0; ByteIndex < sizeof(T); ++ByteIndex)
36#else
37 for (int32 ByteIndex = sizeof(T) - 1; ByteIndex >= 0; --ByteIndex)
38#endif // PLATFORM_LITTLE_ENDIAN
39 {
40 ValueRaw |= ByteStream[ReadIndex++] << 8 * ByteIndex;
41 }
42 }
43 else
44 {
45#if PLATFORM_LITTLE_ENDIAN
46 for (int32 ByteIndex = sizeof(T) - 1; ByteIndex >= 0; --ByteIndex)
47#else
48 for (int32 ByteIndex = 0; ByteIndex < sizeof(T); ++ByteIndex)
49#endif // PLATFORM_LITTLE_ENDIAN
50 {
51 ValueRaw |= ByteStream[ReadIndex++] << 8 * ByteIndex;
52 }
53 }
54
55 return ValueRaw;
56 }
57
58 template <typename T>
59 inline void WriteToByteStream(T Value, uint8* ByteStream, int32& WriteIndex, bool bLittleEndian = true)
60 {
61 if (bLittleEndian)
62 {
63#if PLATFORM_LITTLE_ENDIAN
64 for (int32 ByteIndex = 0; ByteIndex < sizeof(T); ++ByteIndex)
65#else
66 for (int32 ByteIndex = sizeof(T) - 1; ByteIndex >= 0; --ByteIndex)
67#endif // PLATFORM_LITTLE_ENDIAN
68 {
69 ByteStream[WriteIndex++] = (Value >> (8 * ByteIndex)) & 0xFF;
70 }
71 }
72 else
73 {
74#if PLATFORM_LITTLE_ENDIAN
75 for (int32 ByteIndex = sizeof(T) - 1; ByteIndex >= 0; --ByteIndex)
76#else
77 for (int32 ByteIndex = 0; ByteIndex < sizeof(T); ++ByteIndex)
78#endif // PLATFORM_LITTLE_ENDIAN
79 {
80 ByteStream[WriteIndex++] = (Value >> (8 * ByteIndex)) & 0xFF;
81 }
82 }
83 }
84
85 template <typename T>
86 inline T ReadFromArray(const T* ElementArray, int32& ReadIndex, int32 NumElements, int32 IndexStride = 1)
87 {
88 T OutputValue = 0;
89
90 if (ReadIndex >= 0 && ReadIndex < NumElements)
91 {
92 OutputValue = ElementArray[ReadIndex];
93 ReadIndex += IndexStride;
94 }
95
96 return OutputValue;
97 }
98
100 // End of copied section
102} // namespace ADPCMPrivate
103
104
105
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
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
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Adpcm.h:15
void WriteToByteStream(T Value, uint8 *ByteStream, int32 &WriteIndex, bool bLittleEndian=true)
Definition Adpcm.h:59
T SignExtend(const T ValueToExtend)
Definition Adpcm.h:21
T ReadFromArray(const T *ElementArray, int32 &ReadIndex, int32 NumElements, int32 IndexStride=1)
Definition Adpcm.h:86
T ReadFromByteStream(const uint8 *ByteStream, int32 &ReadIndex, bool bLittleEndian=true)
Definition Adpcm.h:28
Definition Adpcm.cpp:7
bool DecodeBlock(const uint8 *EncodedADPCMBlock, int32 BlockSize, int16 *DecodedPCMData)
Definition Adpcm.cpp:64