UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VoiceCaptureWindows.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "VoicePackage.h"
8#include "VoiceDelayBuffer.h"
10#include "Containers/Ticker.h"
12#include "SampleBuffer.h"
13
15
16class IVoiceCapture;
19
24{
25private:
26
28 static FVoiceCaptureDeviceWindows* Singleton;
30 TArray<IVoiceCapture*> ActiveVoiceCaptures;
32 bool bInitialized;
33
35 bool Init();
37 void Shutdown();
38
40
50 static void Destroy();
56 void FreeVoiceCaptureObject(IVoiceCapture* VoiceCaptureObj);
57
58public:
59
61 {
63 FString DeviceName;
68 };
69
72
77
80
84
94 FVoiceCaptureWindows* CreateVoiceCaptureObject(const FString& DeviceName, int32 SampleRate, int32 NumChannels);
95
102};
103
108{
109public:
110
113
114 // IVoiceCapture
115 virtual bool Init(const FString& DeviceName, int32 SampleRate, int32 NumChannels) override;
116 virtual void Shutdown() override;
117 virtual bool Start() override;
118 virtual void Stop() override;
119 virtual bool ChangeDevice(const FString& DeviceName, int32 SampleRate, int32 NumChannels) override;
120 virtual bool IsCapturing() override;
124 virtual int32 GetBufferSize() const override;
125 virtual void DumpState() const override;
126 virtual float GetCurrentAmplitude() const override;
127
128 // FTSTickerObjectBase
129 virtual bool Tick(float DeltaTime) override;
130
131private:
132
136 double LastCaptureTime;
138 EVoiceCaptureState::Type VoiceCaptureState;
140 TArray<uint8> UncompressedAudioBuffer;
142 uint64 SampleCounter;
144 uint64 CachedSampleStart;
146 uint64 CurrentSampleStart;
147
149 bool bSampleStartCached;
150
152 int32 NumInputChannels;
153
155 Audio::TSampleBuffer<float> ConversionBuffer;
156
161 FVoiceDelayBuffer<int16> LookaheadBuffer;
162 /*
163 * This buffer is used in case someone starts speaking again in the middle of a buffer
164 * they were otherwise silent in.
165 */
166 FVoiceDelayBuffer<int16> ReleaseBuffer;
167
168 /*
169 * Envelope following DSP object.
170 * Configured using the MicSilenceDetectionConfig namespace in VoiceConfig.h and the CVars defined in VoiceConfig.cpp.
171 */
172 Audio::FInlineEnvelopeFollower MicLevelDetector;
173 /*
174 * Whether the microphone level is above the threshold set
175 */
176 bool bIsMicActive;
177
181 Audio::FLinearEase NoiseGateAttenuator;
182
186 bool bWasMicAboveNoiseGateThreshold;
187
197 bool CreateCaptureBuffer(const FString& DeviceName, int32 SampleRate, int32 NumChannels);
198
200 void FreeCaptureBuffer();
201
206 void ProcessData();
212 bool CreateNotifications(uint32 BufferSize);
213};
#define PACKAGE_SCOPE
Definition CoreOnlinePackage.h:9
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
struct IDirectSound8 * LPDIRECTSOUND8
Definition VoiceCaptureWindows.h:14
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition EnvelopeFollower.h:323
Definition Dsp.h:619
Definition SampleBuffer.h:24
Definition Ticker.h:137
Definition VoiceCaptureWindows.h:24
FString HMDAudioInputDevice
Definition VoiceCaptureWindows.h:74
static FVoiceCaptureDeviceWindows * Get()
FCaptureDeviceInfo DefaultVoiceCaptureDevice
Definition VoiceCaptureWindows.h:76
LPDIRECTSOUND8 DirectSound
Definition VoiceCaptureWindows.h:71
TMap< FString, FCaptureDeviceInfo > Devices
Definition VoiceCaptureWindows.h:79
FVoiceCaptureWindows * CreateVoiceCaptureObject(const FString &DeviceName, int32 SampleRate, int32 NumChannels)
Definition VoiceCaptureWindows.h:108
virtual float GetCurrentAmplitude() const override
virtual bool Start() override
virtual int32 GetBufferSize() const override
virtual void DumpState() const override
virtual bool Tick(float DeltaTime) override
virtual EVoiceCaptureState::Type GetVoiceData(uint8 *OutVoiceBuffer, uint32 InVoiceBufferSize, uint32 &OutAvailableVoiceData) override
virtual bool IsCapturing() override
virtual EVoiceCaptureState::Type GetCaptureState(uint32 &OutAvailableVoiceData) const override
virtual EVoiceCaptureState::Type GetVoiceData(uint8 *OutVoiceBuffer, uint32 InVoiceBufferSize, uint32 &OutAvailableVoiceData, uint64 &OutSampleCounter) override
virtual bool Init(const FString &DeviceName, int32 SampleRate, int32 NumChannels) override
virtual void Shutdown() override
virtual bool ChangeDevice(const FString &DeviceName, int32 SampleRate, int32 NumChannels) override
virtual void Stop() override
Definition VoiceDelayBuffer.h:13
Definition VoiceCapture.h:69
Definition Array.h:670
Definition UnrealString.h.inl:34
Type
Definition VoiceCapture.h:17
Definition VoiceCaptureWindows.h:61
GUID DeviceId
Definition VoiceCaptureWindows.h:65
bool bIsDefault
Definition VoiceCaptureWindows.h:67
FString DeviceName
Definition VoiceCaptureWindows.h:63