-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from matthewscharles/StereoTools
Stereo tools
- Loading branch information
Showing
10 changed files
with
1,467 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
Source/MetasoundBranches/Private/MetasoundStereoBalanceNode.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
#include "MetasoundBranches/Public/MetasoundStereoBalanceNode.h" | ||
#include "MetasoundExecutableOperator.h" // TExecutableOperator class | ||
#include "MetasoundPrimitives.h" // ReadRef and WriteRef descriptions for bool, int32, float, and string | ||
#include "MetasoundNodeRegistrationMacro.h" // METASOUND_LOCTEXT and METASOUND_REGISTER_NODE macros | ||
#include "MetasoundStandardNodesNames.h" // StandardNodes namespace | ||
#include "MetasoundFacade.h" // FNodeFacade class, eliminates the need for a fair amount of boilerplate code | ||
#include "MetasoundParamHelper.h" // METASOUND_PARAM and METASOUND_GET_PARAM family of macros | ||
#include "Math/UnrealMathUtility.h" // For FMath functions | ||
|
||
#define LOCTEXT_NAMESPACE "MetasoundStandardNodes_BalanceNode" | ||
|
||
namespace Metasound | ||
{ | ||
namespace BalanceNodeNames | ||
{ | ||
METASOUND_PARAM(InputLeftSignal, "In L", "Left channel of the stereo input signal."); | ||
METASOUND_PARAM(InputRightSignal, "In R", "Right channel of the stereo input signal."); | ||
METASOUND_PARAM(InputBalance, "Balance", "Balance control ranging from -1.0 (full left) to 1.0 (full right)."); | ||
|
||
METASOUND_PARAM(OutputLeftSignal, "Out L", "Left channel of the adjusted stereo output signal."); | ||
METASOUND_PARAM(OutputRightSignal, "Out R", "Right channel of the adjusted stereo output signal."); | ||
} | ||
|
||
class FBalanceOperator : public TExecutableOperator<FBalanceOperator> | ||
{ | ||
public: | ||
FBalanceOperator( | ||
const FOperatorSettings& InSettings, | ||
const FAudioBufferReadRef& InLeftSignal, | ||
const FAudioBufferReadRef& InRightSignal, | ||
const FFloatReadRef& InBalance) | ||
: InputLeftSignal(InLeftSignal) | ||
, InputRightSignal(InRightSignal) | ||
, InputBalance(InBalance) | ||
, OutputLeftSignal(FAudioBufferWriteRef::CreateNew(InSettings)) | ||
, OutputRightSignal(FAudioBufferWriteRef::CreateNew(InSettings)) | ||
{ | ||
} | ||
|
||
static const FVertexInterface& DeclareVertexInterface() | ||
{ | ||
using namespace BalanceNodeNames; | ||
|
||
static const FVertexInterface Interface( | ||
FInputVertexInterface( | ||
TInputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(InputLeftSignal)), | ||
TInputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(InputRightSignal)), | ||
TInputDataVertexModel<float>(METASOUND_GET_PARAM_NAME_AND_METADATA(InputBalance), 0.0f) // Default balance is centered | ||
), | ||
FOutputVertexInterface( | ||
TOutputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(OutputLeftSignal)), | ||
TOutputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(OutputRightSignal)) | ||
) | ||
); | ||
|
||
return Interface; | ||
} | ||
|
||
static const FNodeClassMetadata& GetNodeInfo() | ||
{ | ||
auto CreateNodeClassMetadata = []() -> FNodeClassMetadata | ||
{ | ||
FVertexInterface NodeInterface = DeclareVertexInterface(); | ||
|
||
FNodeClassMetadata Metadata; | ||
|
||
Metadata.ClassName = { StandardNodes::Namespace, TEXT("Stereo Balance"), StandardNodes::AudioVariant }; | ||
Metadata.MajorVersion = 1; | ||
Metadata.MinorVersion = 0; | ||
Metadata.DisplayName = METASOUND_LOCTEXT("StereoGainNodeDisplayName", "Stereo Balance"); | ||
Metadata.Description = METASOUND_LOCTEXT("StereoGainNodeDesc", "Adjusts the balance of a stereo signal."); | ||
Metadata.Author = "Charles Matthews"; | ||
Metadata.PromptIfMissing = PluginNodeMissingPrompt; | ||
Metadata.DefaultInterface = NodeInterface; | ||
Metadata.CategoryHierarchy = { METASOUND_LOCTEXT("Custom", "Branches") }; | ||
Metadata.Keywords = TArray<FText>(); | ||
|
||
return Metadata; | ||
}; | ||
|
||
static const FNodeClassMetadata Metadata = CreateNodeClassMetadata(); | ||
return Metadata; | ||
} | ||
|
||
virtual FDataReferenceCollection GetInputs() const override | ||
{ | ||
using namespace BalanceNodeNames; | ||
|
||
FDataReferenceCollection InputDataReferences; | ||
|
||
InputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(InputLeftSignal), InputLeftSignal); | ||
InputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(InputRightSignal), InputRightSignal); | ||
InputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(InputBalance), InputBalance); | ||
|
||
return InputDataReferences; | ||
} | ||
|
||
virtual FDataReferenceCollection GetOutputs() const override | ||
{ | ||
using namespace BalanceNodeNames; | ||
|
||
FDataReferenceCollection OutputDataReferences; | ||
|
||
OutputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(OutputLeftSignal), OutputLeftSignal); | ||
OutputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(OutputRightSignal), OutputRightSignal); | ||
|
||
return OutputDataReferences; | ||
} | ||
|
||
static TUniquePtr<IOperator> CreateOperator(const FCreateOperatorParams& InParams, FBuildErrorArray& OutErrors) | ||
{ | ||
using namespace BalanceNodeNames; | ||
|
||
const Metasound::FDataReferenceCollection& InputCollection = InParams.InputDataReferences; | ||
const Metasound::FInputVertexInterface& InputInterface = DeclareVertexInterface().GetInputInterface(); | ||
|
||
TDataReadReference<FAudioBuffer> InputLeftSignal = InputCollection.GetDataReadReferenceOrConstructWithVertexDefault<FAudioBuffer>(InputInterface, METASOUND_GET_PARAM_NAME(InputLeftSignal), InParams.OperatorSettings); | ||
TDataReadReference<FAudioBuffer> InputRightSignal = InputCollection.GetDataReadReferenceOrConstructWithVertexDefault<FAudioBuffer>(InputInterface, METASOUND_GET_PARAM_NAME(InputRightSignal), InParams.OperatorSettings); | ||
TDataReadReference<float> InputBalance = InputCollection.GetDataReadReferenceOrConstructWithVertexDefault<float>(InputInterface, METASOUND_GET_PARAM_NAME(InputBalance), InParams.OperatorSettings); | ||
|
||
return MakeUnique<FBalanceOperator>(InParams.OperatorSettings, InputLeftSignal, InputRightSignal, InputBalance); | ||
} | ||
|
||
void Execute() | ||
{ | ||
int32 NumFrames = InputLeftSignal->Num(); | ||
|
||
const float* LeftData = InputLeftSignal->GetData(); | ||
const float* RightData = InputRightSignal->GetData(); | ||
float* OutputLeftData = OutputLeftSignal->GetData(); | ||
float* OutputRightData = OutputRightSignal->GetData(); | ||
|
||
float Balance = FMath::Clamp(*InputBalance, -1.0f, 1.0f); | ||
|
||
float Angle = (Balance + 1.0f) * (PI / 4.0f); | ||
|
||
float LeftGain = FMath::Cos(Angle); | ||
float RightGain = FMath::Sin(Angle); | ||
|
||
for (int32 i = 0; i < NumFrames; ++i) | ||
{ | ||
OutputLeftData[i] = LeftData[i] * LeftGain; | ||
OutputRightData[i] = RightData[i] * RightGain; | ||
} | ||
} | ||
|
||
private: | ||
|
||
// Inputs | ||
FAudioBufferReadRef InputLeftSignal; | ||
FAudioBufferReadRef InputRightSignal; | ||
FFloatReadRef InputBalance; | ||
|
||
// Outputs | ||
FAudioBufferWriteRef OutputLeftSignal; | ||
FAudioBufferWriteRef OutputRightSignal; | ||
}; | ||
|
||
class FBalanceNode : public FNodeFacade | ||
{ | ||
public: | ||
FBalanceNode(const FNodeInitData& InitData) | ||
: FNodeFacade(InitData.InstanceName, InitData.InstanceID, TFacadeOperatorClass<FBalanceOperator>()) | ||
{ | ||
} | ||
}; | ||
|
||
METASOUND_REGISTER_NODE(FBalanceNode); | ||
} | ||
|
||
#undef LOCTEXT_NAMESPACE |
160 changes: 160 additions & 0 deletions
160
Source/MetasoundBranches/Private/MetasoundStereoGainNode.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#include "MetasoundBranches/Public/MetasoundStereoGainNode.h" | ||
#include "MetasoundExecutableOperator.h" // TExecutableOperator class | ||
#include "MetasoundPrimitives.h" // ReadRef and WriteRef descriptions for bool, int32, float, and string | ||
#include "MetasoundNodeRegistrationMacro.h" // METASOUND_LOCTEXT and METASOUND_REGISTER_NODE macros | ||
#include "MetasoundStandardNodesNames.h" // StandardNodes namespace | ||
#include "MetasoundFacade.h" // FNodeFacade class | ||
#include "MetasoundParamHelper.h" // METASOUND_PARAM and METASOUND_GET_PARAM family of macros | ||
|
||
#define LOCTEXT_NAMESPACE "MetasoundStandardNodes_StereoGain" | ||
|
||
namespace Metasound | ||
{ | ||
namespace StereoGainNodeNames | ||
{ | ||
METASOUND_PARAM(InputLeftSignal, "In L", "Left channel audio input."); | ||
METASOUND_PARAM(InputRightSignal, "In R", "Right channel audio input."); | ||
METASOUND_PARAM(InputGain, "Gain (Lin)", "Gain control (0.0 to 1.0)."); | ||
|
||
METASOUND_PARAM(OutputLeftSignal, "Out L", "Left output channel."); | ||
METASOUND_PARAM(OutputRightSignal, "Out R", "Right output channel."); | ||
} | ||
|
||
class FStereoGainOperator : public TExecutableOperator<FStereoGainOperator> | ||
{ | ||
public: | ||
FStereoGainOperator( | ||
const FOperatorSettings& InSettings, | ||
const FAudioBufferReadRef& InLeftSignal, | ||
const FAudioBufferReadRef& InRightSignal, | ||
const FFloatReadRef& InGain) | ||
: InputLeftSignal(InLeftSignal) | ||
, InputRightSignal(InRightSignal) | ||
, InputGain(InGain) | ||
, OutputLeftSignal(FAudioBufferWriteRef::CreateNew(InSettings)) | ||
, OutputRightSignal(FAudioBufferWriteRef::CreateNew(InSettings)) | ||
{ | ||
} | ||
|
||
static const FVertexInterface& DeclareVertexInterface() | ||
{ | ||
using namespace StereoGainNodeNames; | ||
|
||
static const FVertexInterface Interface( | ||
FInputVertexInterface( | ||
TInputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(InputLeftSignal)), | ||
TInputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(InputRightSignal)), | ||
TInputDataVertexModel<float>(METASOUND_GET_PARAM_NAME_AND_METADATA(InputGain), 1.0f) | ||
), | ||
FOutputVertexInterface( | ||
TOutputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(OutputLeftSignal)), | ||
TOutputDataVertexModel<FAudioBuffer>(METASOUND_GET_PARAM_NAME_AND_METADATA(OutputRightSignal)) | ||
) | ||
); | ||
|
||
return Interface; | ||
} | ||
|
||
static const FNodeClassMetadata& GetNodeInfo() | ||
{ | ||
auto CreateNodeClassMetadata = []() -> FNodeClassMetadata | ||
{ | ||
FVertexInterface NodeInterface = DeclareVertexInterface(); | ||
|
||
FNodeClassMetadata Metadata; | ||
Metadata.ClassName = { StandardNodes::Namespace, TEXT("Stereo Gain"), StandardNodes::AudioVariant }; | ||
Metadata.MajorVersion = 1; | ||
Metadata.MinorVersion = 0; | ||
Metadata.DisplayName = METASOUND_LOCTEXT("StereoGainNodeDisplayName", "Stereo Gain"); | ||
Metadata.Description = METASOUND_LOCTEXT("StereoGainNodeDesc", "Scale a stereo input to a gain value."); | ||
Metadata.Author = "Charles Matthews"; | ||
Metadata.PromptIfMissing = PluginNodeMissingPrompt; | ||
Metadata.DefaultInterface = NodeInterface; | ||
Metadata.CategoryHierarchy = { METASOUND_LOCTEXT("Custom", "Branches") }; | ||
Metadata.Keywords = TArray<FText>(); | ||
|
||
return Metadata; | ||
}; | ||
|
||
static const FNodeClassMetadata Metadata = CreateNodeClassMetadata(); | ||
return Metadata; | ||
} | ||
|
||
virtual FDataReferenceCollection GetInputs() const override | ||
{ | ||
using namespace StereoGainNodeNames; | ||
|
||
FDataReferenceCollection InputDataReferences; | ||
InputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(InputLeftSignal), InputLeftSignal); | ||
InputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(InputRightSignal), InputRightSignal); | ||
InputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(InputGain), InputGain); | ||
|
||
return InputDataReferences; | ||
} | ||
|
||
virtual FDataReferenceCollection GetOutputs() const override | ||
{ | ||
using namespace StereoGainNodeNames; | ||
|
||
FDataReferenceCollection OutputDataReferences; | ||
OutputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(OutputLeftSignal), OutputLeftSignal); | ||
OutputDataReferences.AddDataReadReference(METASOUND_GET_PARAM_NAME(OutputRightSignal), OutputRightSignal); | ||
return OutputDataReferences; | ||
} | ||
|
||
static TUniquePtr<IOperator> CreateOperator(const FCreateOperatorParams& InParams, FBuildErrorArray& OutErrors) | ||
{ | ||
using namespace StereoGainNodeNames; | ||
|
||
const Metasound::FDataReferenceCollection& InputCollection = InParams.InputDataReferences; | ||
const Metasound::FInputVertexInterface& InputInterface = DeclareVertexInterface().GetInputInterface(); | ||
|
||
TDataReadReference<FAudioBuffer> InputLeftSignal = InputCollection.GetDataReadReferenceOrConstructWithVertexDefault<FAudioBuffer>(InputInterface, METASOUND_GET_PARAM_NAME(InputLeftSignal), InParams.OperatorSettings); | ||
TDataReadReference<FAudioBuffer> InputRightSignal = InputCollection.GetDataReadReferenceOrConstructWithVertexDefault<FAudioBuffer>(InputInterface, METASOUND_GET_PARAM_NAME(InputRightSignal), InParams.OperatorSettings); | ||
TDataReadReference<float> Gain = InputCollection.GetDataReadReferenceOrConstructWithVertexDefault<float>(InputInterface, METASOUND_GET_PARAM_NAME(InputGain), InParams.OperatorSettings); | ||
|
||
return MakeUnique<FStereoGainOperator>(InParams.OperatorSettings, InputLeftSignal, InputRightSignal, Gain); | ||
} | ||
|
||
void Execute() | ||
{ | ||
const int32 NumFrames = InputLeftSignal->Num(); | ||
|
||
const float* LeftData = InputLeftSignal->GetData(); | ||
const float* RightData = InputRightSignal->GetData(); | ||
float* OutputLeftData = OutputLeftSignal->GetData(); | ||
float* OutputRightData = OutputRightSignal->GetData(); | ||
|
||
const float GainVal = *InputGain; | ||
|
||
for (int32 i = 0; i < NumFrames; ++i) | ||
{ | ||
OutputLeftData[i] = LeftData[i] * GainVal; | ||
OutputRightData[i] = RightData[i] * GainVal; | ||
} | ||
} | ||
|
||
private: | ||
// Inputs | ||
FAudioBufferReadRef InputLeftSignal; | ||
FAudioBufferReadRef InputRightSignal; | ||
FFloatReadRef InputGain; | ||
|
||
// Outputs | ||
FAudioBufferWriteRef OutputLeftSignal; | ||
FAudioBufferWriteRef OutputRightSignal; | ||
}; | ||
|
||
class FStereoGainNode : public FNodeFacade | ||
{ | ||
public: | ||
FStereoGainNode(const FNodeInitData& InitData) | ||
: FNodeFacade(InitData.InstanceName, InitData.InstanceID, TFacadeOperatorClass<FStereoGainOperator>()) | ||
{ | ||
} | ||
}; | ||
|
||
METASOUND_REGISTER_NODE(FStereoGainNode); | ||
} | ||
|
||
#undef LOCTEXT_NAMESPACE |
13 changes: 13 additions & 0 deletions
13
Source/MetasoundBranches/Public/MetasoundStereoBalanceNode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "Metasound.h" | ||
#include "MetasoundNode.h" | ||
|
||
namespace MetasoundBranches | ||
{ | ||
class FMetasoundStereoBalanceNode : public Metasound::FNode | ||
{ | ||
public: | ||
FMetasoundStereoBalanceNode(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "Metasound.h" | ||
#include "MetasoundNode.h" | ||
|
||
namespace MetasoundBranches | ||
{ | ||
class FMetasoundStereoGainNode : public Metasound::FNode | ||
{ | ||
public: | ||
FMetasoundStereoGainNode(); | ||
}; | ||
} |
Oops, something went wrong.