diff --git a/Source/VAPlugin/Private/SignalSources/VAAudioInputSignalSource.cpp b/Source/VAPlugin/Private/SignalSources/VAAudioInputSignalSource.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc2389610aba4ef4954eb10da8a6d08ec1956cbf --- /dev/null +++ b/Source/VAPlugin/Private/SignalSources/VAAudioInputSignalSource.cpp @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "SignalSources/VAAudioInputSignalSource.h" + +#include "VAUtils.h" +#include "VAPlugin.h" + +void UVAAudioInputSignalSource::Initialize() +{ + if (bInitialized) + { + FVAUtils::LogStuff("[UVAAudioInputSignalSource::Initialize()]: Signal source is already initialized, aborting...", true); + return; + } + + + ID = FVAPlugin::GetAudioInputSignalSourceID(Channel); + if (!IsValidID(ID)) + { + FVAUtils::LogStuff("[UVAAudioInputSignalSource::Initialize()]: Error initializing Audio Input Signal Source", true); + return; + } + + bInitialized = true; +} diff --git a/Source/VAPlugin/Private/SoundSource/VAAudioInputSourceComponent.cpp b/Source/VAPlugin/Private/SoundSource/VAAudioInputSourceComponent.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9624a50d2316210816f65ee045e9699b5dcd09ba --- /dev/null +++ b/Source/VAPlugin/Private/SoundSource/VAAudioInputSourceComponent.cpp @@ -0,0 +1,12 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "SoundSource/VAAudioInputSourceComponent.h" + +#include "SignalSources/VAAudioInputSignalSource.h" + + +UVAAudioInputSourceComponent::UVAAudioInputSourceComponent() : Super() +{ + SignalSource = CreateDefaultSubobject<UVAAudioInputSignalSource>("AudioInputSignalSource"); +} diff --git a/Source/VAPlugin/Private/VAPlugin.cpp b/Source/VAPlugin/Private/VAPlugin.cpp index 891399927104953751b22a353cc2ba683b6f0fc7..da11e78999021f0e8db2ec3f0e31cb0aa91419d1 100644 --- a/Source/VAPlugin/Private/VAPlugin.cpp +++ b/Source/VAPlugin/Private/VAPlugin.cpp @@ -557,6 +557,25 @@ bool FVAPlugin::SetSignalSourceBufferLooping(const std::string& SignalSourceID, } } +std::string FVAPlugin::GetAudioInputSignalSourceID(const int Channel) +{ + if (!ShouldInteractWithServer()) + return VA_SLAVE_ID_STRING; + + const std::string SignalSourceID = "audioinput" + std::to_string(Channel); + + //TODO: Check if signal source really exist, otherwise return invalid ID + + //PSC: I was trying to use CVASignalSourceInfo for that. But when the local variable is destroyed, the program crashes. + //std::vector<CVASignalSourceInfo> Infos; + //VAServer->GetSignalSourceInfos(Infos); + //CVASignalSourceInfo Info = VAServer->GetSignalSourceInfo(SignalSourceID); + //if (false) + // return VA_INVALID_ID_STRING; + + return SignalSourceID; +} + std::string FVAPlugin::CreateSignalSourcePrototype(UVAAbstractSignalSource* SignalSource) { if (!ShouldInteractWithServer()) diff --git a/Source/VAPlugin/Private/VAPlugin.h b/Source/VAPlugin/Private/VAPlugin.h index 9fa2bcf31aeff46e6841c4f23cdbecf26fd9adf4..bbd17a7b1c3fd867b3ac28e4a288554e06ab692f 100644 --- a/Source/VAPlugin/Private/VAPlugin.h +++ b/Source/VAPlugin/Private/VAPlugin.h @@ -76,6 +76,9 @@ public: static bool SetSignalSourceBufferPlaybackPosition(const std::string& SignalSourceID, float Time); static bool SetSignalSourceBufferLooping(const std::string& SignalSourceID, bool bLoop); + // Returns the ID of the signal source referring the given audio input channel. Invalid ID, if channel does not exist + static std::string GetAudioInputSignalSourceID(const int Channel); + static std::string CreateSignalSourcePrototype(UVAAbstractSignalSource* SignalSource); // Deletes a signal source with given ID. Use with great care! static bool DeleteSignalSource(const std::string& SignalSourceID); diff --git a/Source/VAPlugin/Public/SignalSources/VAAudioInputSignalSource.h b/Source/VAPlugin/Public/SignalSources/VAAudioInputSignalSource.h new file mode 100644 index 0000000000000000000000000000000000000000..603e4d14d1575d2eb0618d1797d6291d89fa43d2 --- /dev/null +++ b/Source/VAPlugin/Public/SignalSources/VAAudioInputSignalSource.h @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "SignalSources/VAAbstractSignalSource.h" +#include "VAAudioInputSignalSource.generated.h" + +/** + * + */ +UCLASS(ClassGroup = (VA)) +class VAPLUGIN_API UVAAudioInputSignalSource : public UVAAbstractSignalSource +{ + GENERATED_BODY() + +protected: + // Input channel used to stream into signal source + UPROPERTY(EditAnywhere, meta = (DisplayName = "Input Channel ID", Category = "Audio Input", ClampMin = "1")) + int Channel = 1; + +public: + UVAAudioInputSignalSource() = default; + + // Creates the signal source in VA and sets the ID accordingly + void Initialize() override; + +}; diff --git a/Source/VAPlugin/Public/SoundSource/VAAudioInputSourceComponent.h b/Source/VAPlugin/Public/SoundSource/VAAudioInputSourceComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..8c97ff80133f7a947db94ddd46ebe83bbb7d3ede --- /dev/null +++ b/Source/VAPlugin/Public/SoundSource/VAAudioInputSourceComponent.h @@ -0,0 +1,20 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "SoundSource/VAAbstractSourceComponent.h" +#include "VAAudioInputSourceComponent.generated.h" + +/** + * + */ +UCLASS(ClassGroup = (VA), meta = (BlueprintSpawnableComponent)) +class VAPLUGIN_API UVAAudioInputSourceComponent : public UVAAbstractSourceComponent +{ + GENERATED_BODY() +public: + + UVAAudioInputSourceComponent(); + +};