UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SoundWaveProxyReader.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "AudioDecompress.h"
7#include "HAL/Platform.h"
10
11// Forward declare
12class FSoundWaveProxy;
13
20{
21
22public:
24
26 static constexpr uint32 DefaultMinDecodeSizeInFrames = 128;
27
32 static constexpr uint32 DecodeSizeQuantizationInFrames = 128;
33
35
37 static constexpr float MinLoopDurationInSeconds = 0.05f;
38
45 static constexpr float MaxLoopDurationInSeconds = 60.f * 60.f * 365.f * 10.f;
46
48 struct FSettings
49 {
51 float StartTimeInSeconds = 0.f;
52 bool bIsLooping = false;
55 bool bMaintainAudioSync = false;
56 };
57
58private:
65
66public:
73
76
78 inline bool IsLooping() const
79 {
80 return Settings.bIsLooping;
81 }
82
85
92
93 inline float GetSampleRate() const
94 {
95 return SampleRate;
96 }
97
98 inline int32 GetNumChannels() const
99 {
100 return NumChannels;
101 }
102
104 inline int32 GetFrameIndex() const
105 {
106 return CurrentFrameIndex;
107 }
108
110 {
111 return NumFramesInWave;
112 }
113
115 {
116 return LoopEndFrameIndex - LoopStartFrameIndex;
117 }
118
120 {
121 return LoopStartFrameIndex;
122 }
123
125 {
126 return LoopEndFrameIndex;
127 }
128
135 ENGINE_API bool SeekToTime(float InSeconds);
136
144
145
150
155 ENGINE_API bool CanProduceMoreAudio() const;
156
161 bool HasFailed() const
162 {
163 return DecodeResult == EDecodeResult::Fail;
164 }
165
166private:
167
168 enum class EDecodeResult
169 {
170 Fail, // Decoder failed somehow.
171 MoreDataRemaining, // Data has produced and there's more remaining
172 Finished // The decoder has reached the end of the wave data
173 };
174
175 EDecodeResult Decode();
176
177 int32 PopAudioFromDecoderOutput(TArrayView<float> OutBufferView);
178 bool InitializeDecoder(float InStartTimeInSeconds);
179 int32 DiscardSamples(int32 InNumSamplesToDiscard);
180 float ClampLoopStartTime(float InStartTimeInSeconds);
181 float ClampLoopDuration(float InDurationInSeconds);
182 void UpdateLoopBoundaries();
183
184 FSoundWaveProxyRef WaveProxy;
185
186 FSettings Settings;
187
188 float SampleRate = 0.f;
189 int32 NumChannels = 0;
190 EDecodeResult DecodeResult = EDecodeResult::MoreDataRemaining;
191 int32 NumFramesInWave = 0;
192 int32 NumDecodeSamplesToDiscard = 0;
193 int32 CurrentFrameIndex = 0;
194 int32 LoopStartFrameIndex = 0;
195 int32 LoopEndFrameIndex = -1;
196 float DurationInSeconds = 0.f;
197 float MaxLoopStartTimeInSeconds = 0.f;
198
199 bool bIsDecoderValid = false;
200 bool bFallbackSeekMethodWarningLogged = false;
201
202private:
203 mutable TUniquePtr<class ICompressedAudioInfo> CompressedAudioInfo;
205
206 TArray<int16> ResidualBuffer;
207 Audio::FAlignedFloatBuffer SampleConversionBuffer;
208
209 static constexpr uint32 MinNumFramesPerDecode = 1;
210
211 bool bIsFirstDecode = true;
212 bool bPreviousIsStreaming = true;
213 uint32 NumFramesPerDecode = MinNumFramesPerDecode;
214};
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
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Dsp.h:834
Definition SoundWaveProxyReader.h:20
static constexpr uint32 DecodeSizeQuantizationInFrames
Definition SoundWaveProxyReader.h:32
static uint32 ConformDecodeSize(uint32 InMaxDesiredDecodeSizeInFrames)
Definition SoundWaveProxyReader.cpp:33
int32 GetFrameIndex() const
Definition SoundWaveProxyReader.h:104
ENGINE_API bool CanProduceMoreAudio() const
Definition SoundWaveProxyReader.cpp:187
ENGINE_API void SetLoopStartTime(float InLoopStartTimeInSeconds)
Definition SoundWaveProxyReader.cpp:129
static constexpr float MaxLoopDurationInSeconds
Definition SoundWaveProxyReader.h:45
ENGINE_API bool SeekToFrame(uint32 InFrameNum)
Definition SoundWaveProxyReader.cpp:194
bool HasFailed() const
Definition SoundWaveProxyReader.h:161
ENGINE_API int32 PopAudio(Audio::FAlignedFloatBuffer &OutBuffer)
Definition SoundWaveProxyReader.cpp:233
int32 GetNumFramesInLoop() const
Definition SoundWaveProxyReader.h:114
static constexpr uint32 DefaultMinDecodeSizeInFrames
Definition SoundWaveProxyReader.h:26
TSharedRef< FSoundWaveProxy, ESPMode::ThreadSafe > FSoundWaveProxyRef
Definition SoundWaveProxyReader.h:23
ENGINE_API bool SeekToTime(float InSeconds)
Definition SoundWaveProxyReader.cpp:151
int32 GetLoopEndFrameIndex() const
Definition SoundWaveProxyReader.h:124
int32 GetNumChannels() const
Definition SoundWaveProxyReader.h:98
ENGINE_API void SetLoopDuration(float InLoopDurationInSeconds)
Definition SoundWaveProxyReader.cpp:141
bool IsLooping() const
Definition SoundWaveProxyReader.h:78
static constexpr float MinLoopDurationInSeconds
Definition SoundWaveProxyReader.h:37
int32 GetNumFramesInWave() const
Definition SoundWaveProxyReader.h:109
float GetSampleRate() const
Definition SoundWaveProxyReader.h:93
int32 GetLoopStartFrameIndex() const
Definition SoundWaveProxyReader.h:119
ENGINE_API void SetIsLooping(bool bInIsLooping)
Definition SoundWaveProxyReader.cpp:119
Definition SoundWave.h:1742
Definition ArrayView.h:139
Definition UniquePtr.h:107
Definition SoundWaveProxyReader.h:49
float LoopStartTimeInSeconds
Definition SoundWaveProxyReader.h:53
float LoopDurationInSeconds
Definition SoundWaveProxyReader.h:54
uint32 MaxDecodeSizeInFrames
Definition SoundWaveProxyReader.h:50
float StartTimeInSeconds
Definition SoundWaveProxyReader.h:51
bool bIsLooping
Definition SoundWaveProxyReader.h:52
bool bMaintainAudioSync
Definition SoundWaveProxyReader.h:55