2022-11-14 14:44:30 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2023-04-21 20:49:41 -04:00
|
|
|
#include "AudioMixerDevice.h"
|
2023-04-21 14:55:25 -04:00
|
|
|
#include "AudioBusSubsystem.h"
|
|
|
|
|
#include "AudioDevice.h"
|
2022-11-14 14:44:30 -05:00
|
|
|
#include "Internationalization/Text.h"
|
|
|
|
|
#include "MediaPacket.h"
|
|
|
|
|
#include "MetasoundAudioBuffer.h"
|
|
|
|
|
#include "MetasoundAudioBus.h"
|
|
|
|
|
#include "MetasoundEngineNodesNames.h"
|
|
|
|
|
#include "MetasoundExecutableOperator.h"
|
|
|
|
|
#include "MetasoundFacade.h"
|
|
|
|
|
#include "MetasoundNodeRegistrationMacro.h"
|
|
|
|
|
#include "MetasoundParamHelper.h"
|
|
|
|
|
#include "MetasoundStandardNodesCategories.h"
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "MetasoundAudioBusWriterNode"
|
|
|
|
|
|
|
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace AudioBusWriterNode
|
|
|
|
|
{
|
|
|
|
|
METASOUND_PARAM(InParamAudioBusOutput, "Audio Bus", "Audio Bus Asset.");
|
|
|
|
|
METASOUND_PARAM(InParamAudio, "In {0}", "Audio input for channel {0}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<uint32 NumChannels>
|
|
|
|
|
class TAudioBusWriterOperator : public TExecutableOperator<TAudioBusWriterOperator<NumChannels>>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static const FNodeClassMetadata& GetNodeInfo()
|
|
|
|
|
{
|
|
|
|
|
auto InitNodeInfo = []() -> FNodeClassMetadata
|
|
|
|
|
{
|
|
|
|
|
FName OperatorName = *FString::Printf(TEXT("Audio Bus Writer (%d)"), NumChannels);
|
|
|
|
|
FText NodeDisplayName = METASOUND_LOCTEXT_FORMAT("AudioBusWriterDisplayNamePattern", "Audio Bus Writer ({0})", NumChannels);
|
|
|
|
|
|
|
|
|
|
FNodeClassMetadata Info;
|
|
|
|
|
Info.ClassName = { EngineNodes::Namespace, OperatorName, TEXT("") };
|
|
|
|
|
Info.MajorVersion = 1;
|
|
|
|
|
Info.MinorVersion = 0;
|
|
|
|
|
Info.DisplayName = NodeDisplayName;
|
|
|
|
|
Info.Description = METASOUND_LOCTEXT("AudioBusWriter_Description", "Sends audio data to the audio bus asset.");
|
|
|
|
|
Info.Author = PluginAuthor;
|
|
|
|
|
Info.PromptIfMissing = PluginNodeMissingPrompt;
|
|
|
|
|
Info.DefaultInterface = GetVertexInterface();
|
|
|
|
|
Info.CategoryHierarchy.Emplace(NodeCategories::Io);
|
|
|
|
|
return Info;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const FNodeClassMetadata Info = InitNodeInfo();
|
|
|
|
|
|
|
|
|
|
return Info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const FVertexInterface& GetVertexInterface()
|
|
|
|
|
{
|
|
|
|
|
using namespace AudioBusWriterNode;
|
|
|
|
|
|
|
|
|
|
auto CreateVertexInterface = []() -> FVertexInterface
|
|
|
|
|
{
|
|
|
|
|
FInputVertexInterface InputInterface;
|
|
|
|
|
InputInterface.Add(TInputDataVertex<FAudioBusAsset>(METASOUND_GET_PARAM_NAME_AND_METADATA(InParamAudioBusOutput)));
|
|
|
|
|
for (uint32 i = 0; i < NumChannels; ++i)
|
|
|
|
|
{
|
|
|
|
|
InputInterface.Add(TInputDataVertex<FAudioBuffer>(METASOUND_GET_PARAM_NAME_WITH_INDEX_AND_METADATA(InParamAudio, i)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FOutputVertexInterface OutputInterface;
|
|
|
|
|
|
|
|
|
|
return FVertexInterface(InputInterface, OutputInterface);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const FVertexInterface Interface = CreateVertexInterface();
|
|
|
|
|
return Interface;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-13 19:29:51 -04:00
|
|
|
static TUniquePtr<IOperator> CreateOperator(const FBuildOperatorParams& InParams, FBuildResults& OutResults)
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
|
|
|
|
using namespace Frontend;
|
2023-04-27 18:49:33 -04:00
|
|
|
using namespace AudioBusWriterNode;
|
2023-05-09 17:27:12 -04:00
|
|
|
|
2023-10-13 19:29:51 -04:00
|
|
|
const FInputVertexInterfaceData& InputData = InParams.InputData;
|
2022-11-14 14:44:30 -05:00
|
|
|
|
2023-05-09 17:27:12 -04:00
|
|
|
bool bHasEnvironmentVars = InParams.Environment.Contains<Audio::FDeviceId>(SourceInterface::Environment::DeviceID);
|
|
|
|
|
bHasEnvironmentVars &= InParams.Environment.Contains<int32>(SourceInterface::Environment::AudioMixerNumOutputFrames);
|
|
|
|
|
|
2023-01-25 20:41:44 -05:00
|
|
|
if (bHasEnvironmentVars)
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
2023-10-13 19:29:51 -04:00
|
|
|
FAudioBusAssetReadRef AudioBusIn = InputData.GetOrConstructDataReadReference<FAudioBusAsset>(METASOUND_GET_PARAM_NAME(InParamAudioBusOutput));
|
2023-01-25 20:41:44 -05:00
|
|
|
|
|
|
|
|
TArray<FAudioBufferReadRef> AudioInputs;
|
|
|
|
|
for (int32 ChannelIndex = 0; ChannelIndex < NumChannels; ++ChannelIndex)
|
|
|
|
|
{
|
2023-10-13 19:29:51 -04:00
|
|
|
AudioInputs.Add(InputData.GetOrConstructDataReadReference<FAudioBuffer>(METASOUND_GET_PARAM_NAME_WITH_INDEX(InParamAudio, ChannelIndex), InParams.OperatorSettings));
|
2023-01-25 20:41:44 -05:00
|
|
|
}
|
|
|
|
|
|
2023-10-16 14:11:32 -04:00
|
|
|
FString GraphName;
|
|
|
|
|
if (InParams.Environment.Contains<FString>(SourceInterface::Environment::GraphName))
|
|
|
|
|
{
|
|
|
|
|
GraphName = InParams.Environment.GetValue<FString>(SourceInterface::Environment::GraphName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GraphName = TEXT("<Unknown>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MakeUnique<TAudioBusWriterOperator<NumChannels>>(InParams, MoveTemp(AudioBusIn), MoveTemp(AudioInputs), MoveTemp(GraphName));
|
2023-01-25 20:41:44 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-05-09 17:27:12 -04:00
|
|
|
UE_LOG(LogMetaSound, Warning, TEXT("Audio bus writer node requires audio device ID '%s' and audio mixer num output frames '%s' environment variables")
|
|
|
|
|
, *SourceInterface::Environment::DeviceID.ToString(), *SourceInterface::Environment::AudioMixerNumOutputFrames.ToString());
|
2023-01-25 20:41:44 -05:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2023-10-16 14:42:40 -04:00
|
|
|
TAudioBusWriterOperator(const FBuildOperatorParams& InParams, FAudioBusAssetReadRef InAudioBusAsset, TArray<FAudioBufferReadRef> InAudioInputs, FString InGraphName)
|
|
|
|
|
: AudioBusAsset(MoveTemp(InAudioBusAsset))
|
|
|
|
|
, AudioInputs(MoveTemp(InAudioInputs))
|
|
|
|
|
, GraphName(MoveTemp(InGraphName))
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
2023-05-09 17:27:12 -04:00
|
|
|
Reset(InParams);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 12:51:55 -04:00
|
|
|
void CreatePatchInput()
|
|
|
|
|
{
|
|
|
|
|
const FAudioBusProxyPtr& AudioBusProxy = AudioBusAsset->GetAudioBusProxy();
|
|
|
|
|
if (AudioBusProxy.IsValid())
|
|
|
|
|
{
|
|
|
|
|
if (FAudioDeviceManager* ADM = FAudioDeviceManager::Get())
|
|
|
|
|
{
|
|
|
|
|
if (FAudioDevice* AudioDevice = ADM->GetAudioDeviceRaw(AudioDeviceId))
|
|
|
|
|
{
|
|
|
|
|
UAudioBusSubsystem* AudioBusSubsystem = AudioDevice->GetSubsystem<UAudioBusSubsystem>();
|
|
|
|
|
check(AudioBusSubsystem);
|
|
|
|
|
|
|
|
|
|
AudioBusId = AudioBusProxy->AudioBusId;
|
|
|
|
|
const Audio::FAudioBusKey AudioBusKey = Audio::FAudioBusKey(AudioBusId);
|
|
|
|
|
|
|
|
|
|
// Start the audio bus in case it's not already started
|
|
|
|
|
AudioBusChannels = AudioBusProxy->NumChannels;
|
|
|
|
|
AudioBusSubsystem->StartAudioBus(AudioBusKey, AudioBusChannels, false);
|
|
|
|
|
|
|
|
|
|
InterleavedBuffer.Reset();
|
2023-10-16 14:11:32 -04:00
|
|
|
InterleavedBuffer.Reserve(NumBlocksToNumSamples(InitialNumBlocks()));
|
2023-06-07 12:51:55 -04:00
|
|
|
|
|
|
|
|
// Create a bus patch input with enough room for the number of samples we expect and some buffering
|
|
|
|
|
AudioBusPatchInput = AudioBusSubsystem->AddPatchInputForAudioBus(AudioBusKey, BlockSizeFrames, AudioBusChannels);
|
2023-08-31 11:23:00 -04:00
|
|
|
|
|
|
|
|
ConnectionState = EConnectionState::Disconnected;
|
2023-06-07 12:51:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-09 17:27:12 -04:00
|
|
|
void Reset(const IOperator::FResetParams& InParams)
|
|
|
|
|
{
|
|
|
|
|
using namespace Frontend;
|
|
|
|
|
using namespace AudioBusWriterNode;
|
|
|
|
|
|
|
|
|
|
bool bHasEnvironmentVars = InParams.Environment.Contains<Audio::FDeviceId>(SourceInterface::Environment::DeviceID);
|
|
|
|
|
bHasEnvironmentVars &= InParams.Environment.Contains<int32>(SourceInterface::Environment::AudioMixerNumOutputFrames);
|
|
|
|
|
|
|
|
|
|
if (bHasEnvironmentVars)
|
|
|
|
|
{
|
|
|
|
|
SampleRate = InParams.OperatorSettings.GetSampleRate();
|
|
|
|
|
AudioDeviceId = InParams.Environment.GetValue<Audio::FDeviceId>(SourceInterface::Environment::DeviceID);
|
|
|
|
|
AudioMixerOutputFrames = InParams.Environment.GetValue<int32>(SourceInterface::Environment::AudioMixerNumOutputFrames);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogMetaSound, Warning, TEXT("Audio bus writer node requires audio device ID '%s' and audio mixer num output frames '%s' environment variables")
|
|
|
|
|
, *SourceInterface::Environment::DeviceID.ToString(), *SourceInterface::Environment::AudioMixerNumOutputFrames.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-07 12:51:55 -04:00
|
|
|
BlockSizeFrames = InParams.OperatorSettings.GetNumFramesPerBlock();
|
2023-05-09 17:27:12 -04:00
|
|
|
|
2023-10-16 14:11:32 -04:00
|
|
|
bWasUnderrunReported = false;
|
|
|
|
|
|
2023-06-07 12:51:55 -04:00
|
|
|
CreatePatchInput();
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
[Metasound Bind] Fixup for bind issues caught by new automated tests.
#jira UE-187406, UE-187390, UE-187404, UE-187403, UE-187405, UE-187392, UE-187391, UE-187395, UE-187399, UE-187398, UE-187389, UE-187393, UE-187394, UE-187396, UE-187397, UE-187401
#rb phil.popp
[CL 26130674 by maxwell hayes in ue5-main branch]
2023-06-20 15:08:54 -04:00
|
|
|
|
|
|
|
|
virtual void BindInputs(FInputVertexInterfaceData& InOutVertexData) override
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
|
|
|
|
using namespace AudioBusWriterNode;
|
|
|
|
|
|
[Metasound Bind] Fixup for bind issues caught by new automated tests.
#jira UE-187406, UE-187390, UE-187404, UE-187403, UE-187405, UE-187392, UE-187391, UE-187395, UE-187399, UE-187398, UE-187389, UE-187393, UE-187394, UE-187396, UE-187397, UE-187401
#rb phil.popp
[CL 26130674 by maxwell hayes in ue5-main branch]
2023-06-20 15:08:54 -04:00
|
|
|
InOutVertexData.BindReadVertex(METASOUND_GET_PARAM_NAME(InParamAudioBusOutput), AudioBusAsset);
|
2022-11-14 14:44:30 -05:00
|
|
|
|
|
|
|
|
for (int32 ChannelIndex = 0; ChannelIndex < NumChannels; ++ChannelIndex)
|
|
|
|
|
{
|
[Metasound Bind] Fixup for bind issues caught by new automated tests.
#jira UE-187406, UE-187390, UE-187404, UE-187403, UE-187405, UE-187392, UE-187391, UE-187395, UE-187399, UE-187398, UE-187389, UE-187393, UE-187394, UE-187396, UE-187397, UE-187401
#rb phil.popp
[CL 26130674 by maxwell hayes in ue5-main branch]
2023-06-20 15:08:54 -04:00
|
|
|
InOutVertexData.BindReadVertex(METASOUND_GET_PARAM_NAME_WITH_INDEX(InParamAudio, ChannelIndex), AudioInputs[ChannelIndex]);
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
[Metasound Bind] Fixup for bind issues caught by new automated tests.
#jira UE-187406, UE-187390, UE-187404, UE-187403, UE-187405, UE-187392, UE-187391, UE-187395, UE-187399, UE-187398, UE-187389, UE-187393, UE-187394, UE-187396, UE-187397, UE-187401
#rb phil.popp
[CL 26130674 by maxwell hayes in ue5-main branch]
2023-06-20 15:08:54 -04:00
|
|
|
}
|
2022-11-14 14:44:30 -05:00
|
|
|
|
[Metasound Bind] Fixup for bind issues caught by new automated tests.
#jira UE-187406, UE-187390, UE-187404, UE-187403, UE-187405, UE-187392, UE-187391, UE-187395, UE-187399, UE-187398, UE-187389, UE-187393, UE-187394, UE-187396, UE-187397, UE-187401
#rb phil.popp
[CL 26130674 by maxwell hayes in ue5-main branch]
2023-06-20 15:08:54 -04:00
|
|
|
virtual void BindOutputs(FOutputVertexInterfaceData& InOutVertexData) override
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual FDataReferenceCollection GetInputs() const override
|
|
|
|
|
{
|
|
|
|
|
// This should never be called. Bind(...) is called instead. This method
|
|
|
|
|
// exists as a stop-gap until the API can be deprecated and removed.
|
|
|
|
|
checkNoEntry();
|
|
|
|
|
return {};
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual FDataReferenceCollection GetOutputs() const override
|
|
|
|
|
{
|
[Metasound Bind] Fixup for bind issues caught by new automated tests.
#jira UE-187406, UE-187390, UE-187404, UE-187403, UE-187405, UE-187392, UE-187391, UE-187395, UE-187399, UE-187398, UE-187389, UE-187393, UE-187394, UE-187396, UE-187397, UE-187401
#rb phil.popp
[CL 26130674 by maxwell hayes in ue5-main branch]
2023-06-20 15:08:54 -04:00
|
|
|
// This should never be called. Bind(...) is called instead. This method
|
|
|
|
|
// exists as a stop-gap until the API can be deprecated and removed.
|
|
|
|
|
checkNoEntry();
|
|
|
|
|
return {};
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Execute()
|
|
|
|
|
{
|
2023-06-07 12:51:55 -04:00
|
|
|
const FAudioBusProxyPtr& BusProxy = AudioBusAsset->GetAudioBusProxy();
|
|
|
|
|
if (BusProxy.IsValid() && BusProxy->AudioBusId != AudioBusId)
|
|
|
|
|
{
|
|
|
|
|
AudioBusPatchInput.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!AudioBusPatchInput.IsValid())
|
|
|
|
|
{
|
|
|
|
|
// if environment vars & a valid audio bus have been set since starting, try to create the patch now
|
|
|
|
|
if (SampleRate > 0.f && BusProxy.IsValid())
|
|
|
|
|
{
|
|
|
|
|
CreatePatchInput();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 14:44:30 -05:00
|
|
|
if (!AudioBusPatchInput.IsOutputStillActive())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve input and interleaved buffer pointers
|
|
|
|
|
const float* AudioInputBufferPtrs[NumChannels];
|
2022-11-29 12:35:48 -05:00
|
|
|
for (uint32 ChannelIndex = 0; ChannelIndex < NumChannels; ++ChannelIndex)
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
|
|
|
|
AudioInputBufferPtrs[ChannelIndex] = AudioInputs[ChannelIndex]->GetData();
|
|
|
|
|
}
|
2023-10-16 14:11:32 -04:00
|
|
|
int32 InterleavedBufferOffset = InterleavedBuffer.Num();
|
|
|
|
|
InterleavedBuffer.SetNum(InterleavedBufferOffset + BlockSizeFrames * NumChannels);
|
|
|
|
|
float* InterleavedBufferPtr = InterleavedBuffer.GetData() + InterleavedBufferOffset;
|
2022-11-14 14:44:30 -05:00
|
|
|
|
2022-11-29 12:35:48 -05:00
|
|
|
if (AudioBusChannels == 1)
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
2022-11-29 12:35:48 -05:00
|
|
|
FMemory::Memcpy(InterleavedBufferPtr, AudioInputBufferPtrs[0], BlockSizeFrames * sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Interleave the inputs
|
|
|
|
|
// Writing the channels of the interleaved buffer sequentially should improve
|
|
|
|
|
// cache utilization compared to writing each input's frames sequentially.
|
|
|
|
|
// There is more likely to be a cache line for each buffer than for the
|
|
|
|
|
// entirety of the interleaved buffer.
|
|
|
|
|
uint32 MinChannels = FMath::Min(AudioBusChannels, NumChannels);
|
|
|
|
|
for (int32 FrameIndex = 0; FrameIndex < BlockSizeFrames; ++FrameIndex)
|
2022-11-14 14:44:30 -05:00
|
|
|
{
|
2022-11-29 12:35:48 -05:00
|
|
|
for (uint32 ChannelIndex = 0; ChannelIndex < MinChannels; ++ChannelIndex)
|
|
|
|
|
{
|
|
|
|
|
InterleavedBufferPtr[ChannelIndex] = *AudioInputBufferPtrs[ChannelIndex]++;
|
|
|
|
|
}
|
|
|
|
|
InterleavedBufferPtr += AudioBusChannels;
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-16 14:11:32 -04:00
|
|
|
switch (ConnectionState)
|
2023-02-27 13:29:22 -05:00
|
|
|
{
|
2023-10-16 14:11:32 -04:00
|
|
|
case EConnectionState::Disconnected:
|
2023-02-27 13:29:22 -05:00
|
|
|
{
|
2023-10-16 14:11:32 -04:00
|
|
|
// Wait until InterleavedBuffer contains enough samples to satisfy any mix eventualities!
|
|
|
|
|
// A single mix requires enough MetaSound executions to satisfy its buffer size.
|
|
|
|
|
// Mixing can occur concurrently with the first MetaSound execution intended for the next mix,
|
|
|
|
|
// and can steal that execution's patch output.
|
|
|
|
|
if (InterleavedBuffer.Num() < NumBlocksToNumSamples(InitialNumBlocks()))
|
2023-08-31 11:23:00 -04:00
|
|
|
{
|
2023-10-16 14:11:32 -04:00
|
|
|
return;
|
2023-08-31 11:23:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConnectionState = EConnectionState::ConnectionPending;
|
2023-10-16 14:11:32 -04:00
|
|
|
break;
|
2023-08-31 11:23:00 -04:00
|
|
|
}
|
2023-10-16 14:11:32 -04:00
|
|
|
|
|
|
|
|
case EConnectionState::ConnectionPending:
|
2023-08-31 11:23:00 -04:00
|
|
|
{
|
2023-10-16 14:11:32 -04:00
|
|
|
int32 InitialNumSamples = NumBlocksToNumSamples(InitialNumBlocks());
|
|
|
|
|
|
2023-08-31 11:23:00 -04:00
|
|
|
// Determine if the pending connection has been established, by detecting if samples have been consumed.
|
2023-10-16 14:11:32 -04:00
|
|
|
if (AudioBusPatchInput.GetNumSamplesAvailable() == InitialNumSamples)
|
2023-08-31 11:23:00 -04:00
|
|
|
{
|
2023-10-16 14:11:32 -04:00
|
|
|
// If the connection hasn't been established by the time as many executions have occurred again,
|
|
|
|
|
// something has probably gone wrong.
|
|
|
|
|
if (InterleavedBuffer.Num() == InitialNumSamples)
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogMetaSound, Warning, TEXT("Graph %s: Writer node executed before mixer patch connection established, with buffer size %d."), *GraphName, InterleavedBuffer.Num());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-08-31 11:23:00 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConnectionState = EConnectionState::Connected;
|
2023-10-16 14:11:32 -04:00
|
|
|
break;
|
2023-02-27 13:29:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 14:44:30 -05:00
|
|
|
// Pushes the interleaved data to the audio bus
|
2023-09-29 14:26:52 -04:00
|
|
|
const int32 SamplesPushed = AudioBusPatchInput.PushAudio(InterleavedBuffer.GetData(), InterleavedBuffer.Num());
|
|
|
|
|
if (SamplesPushed < InterleavedBuffer.Num() && !bWasUnderrunReported)
|
2022-11-29 12:35:48 -05:00
|
|
|
{
|
|
|
|
|
UE_LOG(LogMetaSound, Warning, TEXT("Underrun detected in audio bus writer node."));
|
2023-09-29 14:26:52 -04:00
|
|
|
bWasUnderrunReported = true;
|
2022-11-29 12:35:48 -05:00
|
|
|
}
|
2023-10-16 14:11:32 -04:00
|
|
|
InterleavedBuffer.Reset();
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2023-10-16 14:11:32 -04:00
|
|
|
int32 InitialNumBlocks() const
|
|
|
|
|
{
|
|
|
|
|
if (AudioMixerOutputFrames == BlockSizeFrames)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We need enough blocks for as many executions as the mixer can consume at once, plus one more,
|
|
|
|
|
// because the last execution can be concurrent with the mixer, and could contribute to either the
|
|
|
|
|
// current mix or the next. That could leave us with one block too few if we didn't have an extra.
|
|
|
|
|
int32 MaxSizeFrames = FMath::Max(AudioMixerOutputFrames, BlockSizeFrames), MinSizeFrames = FMath::Min(AudioMixerOutputFrames, BlockSizeFrames);
|
|
|
|
|
return 1 + FMath::DivideAndRoundUp(MaxSizeFrames, MinSizeFrames);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 11:23:00 -04:00
|
|
|
int32 NumBlocksToNumSamples(int32 NumBlocks) const
|
|
|
|
|
{
|
|
|
|
|
return NumBlocks * BlockSizeFrames * AudioBusChannels;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 14:44:30 -05:00
|
|
|
FAudioBusAssetReadRef AudioBusAsset;
|
|
|
|
|
TArray<FAudioBufferReadRef> AudioInputs;
|
2023-10-16 14:11:32 -04:00
|
|
|
FString GraphName;
|
2022-11-14 14:44:30 -05:00
|
|
|
|
|
|
|
|
TArray<float> InterleavedBuffer;
|
|
|
|
|
int32 AudioMixerOutputFrames = INDEX_NONE;
|
|
|
|
|
Audio::FDeviceId AudioDeviceId = INDEX_NONE;
|
|
|
|
|
float SampleRate = 0.0f;
|
|
|
|
|
Audio::FPatchInput AudioBusPatchInput;
|
|
|
|
|
uint32 AudioBusChannels = INDEX_NONE;
|
2023-06-07 12:51:55 -04:00
|
|
|
uint32 AudioBusId = 0;
|
2023-09-29 14:26:52 -04:00
|
|
|
bool bWasUnderrunReported = false;
|
2022-11-14 14:44:30 -05:00
|
|
|
int32 BlockSizeFrames = 0;
|
2023-08-31 11:23:00 -04:00
|
|
|
enum class EConnectionState : uint8
|
|
|
|
|
{
|
|
|
|
|
Disconnected,
|
|
|
|
|
ConnectionPending,
|
|
|
|
|
Connected
|
|
|
|
|
}
|
|
|
|
|
ConnectionState = EConnectionState::Disconnected;
|
2022-11-14 14:44:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<uint32 NumChannels>
|
|
|
|
|
class TAudioBusWriterNode : public FNodeFacade
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TAudioBusWriterNode(const FNodeInitData& InitData)
|
|
|
|
|
: FNodeFacade(InitData.InstanceName, InitData.InstanceID, TFacadeOperatorClass<TAudioBusWriterOperator<NumChannels>>())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define REGISTER_AUDIO_BUS_WRITER_NODE(ChannelCount) \
|
|
|
|
|
using FAudioBusWriterNode_##ChannelCount = TAudioBusWriterNode<ChannelCount>; \
|
|
|
|
|
METASOUND_REGISTER_NODE(FAudioBusWriterNode_##ChannelCount) \
|
|
|
|
|
|
|
|
|
|
REGISTER_AUDIO_BUS_WRITER_NODE(1);
|
|
|
|
|
REGISTER_AUDIO_BUS_WRITER_NODE(2);
|
2022-11-29 12:35:48 -05:00
|
|
|
REGISTER_AUDIO_BUS_WRITER_NODE(4);
|
|
|
|
|
REGISTER_AUDIO_BUS_WRITER_NODE(6);
|
|
|
|
|
REGISTER_AUDIO_BUS_WRITER_NODE(8);
|
2022-11-14 14:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|