UnrealVoxta 0.1.1
 
Loading...
Searching...
No Matches
VoxtaAudioPlayback.h
Go to the documentation of this file.
1// Copyright(c) 2024 grrimgrriefer & DZnnah, see LICENSE for details.
2
3#pragma once
4#include "CoreMinimal.h"
5#include "Components/AudioComponent.h"
7#include "LipSyncType.h"
8#include "VoxtaAudioPlayback.generated.h"
9
11class UActorComponent;
13class UVoxtaClient;
14class USoundWaveProcedural;
15struct FBaseCharData;
16struct FChatMessage;
17
26UCLASS(HideCategories = (Mobility, Rendering, LOD), ClassGroup = Voxta, meta = (BlueprintSpawnableComponent))
27class UNREALVOXTA_API UVoxtaAudioPlayback : public UAudioComponent, public IA2FWeightProvider
28{
29 GENERATED_BODY()
30
31#pragma region delegate declarations
32public:
34 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVoxtaMessageAudioPlaybackCompleted, const FGuid&, messageId);
36 DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FVoxtaMessageAudioChunkReadyForCustomPlayback, const TArray<uint8>&, rawBytes, const USoundWaveProcedural*, processedSoundWave, FGuid, audioChunkGuid);
37
39 DECLARE_MULTICAST_DELEGATE_OneParam(FVoxtaMessageAudioPlaybackCompletedNative, const FGuid&);
40 DECLARE_MULTICAST_DELEGATE_ThreeParams(FVoxtaMessageAudioChunkReadyForCustomPlaybackNative, const TArray<uint8>&, const USoundWaveProcedural*, FGuid);
41#pragma endregion
42
43#pragma region events
44public:
46 UPROPERTY(BlueprintAssignable, Category = "Voxta", meta = (IsBindableEvent = "True"))
47 FVoxtaMessageAudioPlaybackCompleted VoxtaMessageAudioPlaybackFinishedEvent;
49 FVoxtaMessageAudioPlaybackCompletedNative VoxtaMessageAudioPlaybackFinishedEventNative;
50
60 UPROPERTY(BlueprintAssignable, Category = "Voxta", meta = (IsBindableEvent = "True"))
61 FVoxtaMessageAudioChunkReadyForCustomPlayback VoxtaMessageAudioChunkReadyForCustomPlaybackEvent;
62
64 FVoxtaMessageAudioChunkReadyForCustomPlaybackNative VoxtaMessageAudioChunkReadyForCustomPlaybackEventNative;
65#pragma endregion
66
67#pragma region public API
68public:
74 UFUNCTION(BlueprintCallable, Category = "Voxta")
75 void Initialize(const FGuid& characterId);
76
84 void Initialize(const FGuid& characterId, LipSyncType lipSyncType);
85
92 UFUNCTION(BlueprintCallable, Category = "Voxta")
93 void MarkAudioChunkCustomPlaybackComplete(const FGuid& guid);
94
101 virtual void PlaybackMessage(const FBaseCharData& sender, const FChatMessage& message);
102
104 LipSyncType GetLipSyncType() const;
105#pragma endregion
106
107#pragma region IA2FWeightProvider overrides
108public:
114 virtual void GetA2FCurveWeightsPreUpdate(TArray<float>& targetArrayRef) override;
115#pragma endregion
116
117#pragma region UActorComponent overrides
118protected:
126 virtual void BeginPlay() override;
127
132 virtual void EndPlay(const EEndPlayReason::Type endPlayReason) override;
133#pragma endregion
134
135#pragma region private helper classes
136private:
138 enum class AudioPlaybackInternalState : uint8
139 {
140 Idle,
141 Playing,
142 Done
143 };
144#pragma endregion
145
146#pragma region data
147protected:
148 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Lipsync Type"))
149 LipSyncType m_lipSyncType = LipSyncType::None;
150 FGuid m_characterId;
151 UVoxtaClient* m_clientReference;
152
153private:
154 // TODO: use interface so we don't have to cast to cast to UAudio2FacePlaybackHandler or
155 // UOVRLipSyncPlaybackActorComponent everytime
156 UPROPERTY()
157 UObject* m_lipSyncHandler;
158
159 FGuid m_currentlyPlayingMessageId;
160 TArray<TSharedPtr<MessageChunkAudioContainer>> m_orderedAudio;
161
162 FDelegateHandle m_playbackFinishedHandle;
163
164 FString m_hostAddress;
165 int m_hostPort;
166 AudioPlaybackInternalState m_internalState;
167 int m_currentAudioClipIndex = 0;
168#pragma endregion
169
170#pragma region private API
171protected:
172 void InitializeInternal(bool autoRegisterHandler = true);
173
174private:
176 void PlayCurrentAudioChunkIfAvailable();
177
186 UFUNCTION()
187 void OnAudioPlaybackFinished(UAudioComponent* component);
188
193 void MarkAudioChunkPlaybackCompleteInternal();
194
200 void OnChunkStateChange(const MessageChunkAudioContainer* finishedChunk);
201
203 void Cleanup();
204#pragma endregion
205};
LipSyncType
LipSyncType All the possible LipSync types that are currently supported by the UnrealVoxta client.
Definition LipSyncType.h:21
@ Idle
Definition MessageChunkState.h:17
IA2FWeightProvider The interface implemented by whoever can provide the A2F curves for any given upda...
Definition AbstractA2FWeightProvider.h:25
virtual void GetA2FCurveWeightsPreUpdate(TArray< float > &targetArrayRef)
Retrieve the A2F curveWeights for the upcoming update tick.
Definition AbstractA2FWeightProvider.h:34
MessageChunkAudioContainer Internal utility class that encapsulates the download, decoding,...
Definition MessageChunkAudioContainer.h:23
UAudio2FacePlaybackHandler Handles synchronization and playback of Audio2Face lipsync data with audio...
Definition Audio2FacePlaybackHandler.h:20
UVoxtaClient Main public-facing subsystem for Voxta integration.
Definition VoxtaClient.h:50
FBaseCharData Read-only data struct containing all the universal information fields for a character.
Definition BaseCharData.h:17
FChatMessage Represents a single message in a chat conversation, containing both text and audio data.
Definition ChatMessage.h:16