Skip to content

Commit

Permalink
Add more node types for audio processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Sep 4, 2024
1 parent 48d96ed commit a15566f
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 23 deletions.
2 changes: 0 additions & 2 deletions packages/math/include/math/MathFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace l::math::functions {
return llabs(val);
}
}
return static_cast<T>(0);
}


Expand Down Expand Up @@ -92,7 +91,6 @@ namespace l::math::functions {
return ::pow(val, exp);
}
}
return static_cast<T>(0);
}

template<class T>
Expand Down
137 changes: 123 additions & 14 deletions packages/nodegraph/include/nodegraph/NodeGraphOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ namespace l::nodegraph {
class GraphSourceSine : public NodeGraphOp {
public:
GraphSourceSine(NodeGraphBase* node) :
NodeGraphOp(node, 5, 3)
NodeGraphOp(node, 5, 2)
{}

std::string defaultInStrings[5] = { "Note", "Vol", "Vib", "Mod", "Reset"};
std::string defaultOutStrings[3] = { "Sine", "Phase", "Ph. Mod"};
std::string defaultInStrings[5] = { "Note", "Volume", "Fmod", "Phase", "Reset"};
std::string defaultOutStrings[2] = { "Sine", "Phase"};

virtual ~GraphSourceSine() = default;

Expand Down Expand Up @@ -344,19 +344,28 @@ namespace l::nodegraph {
/*********************************************************************/
class GraphOutputDebug : public NodeGraphOp {
public:
GraphOutputDebug(NodeGraphBase* node, int32_t numValueDisplays) :
NodeGraphOp(node, numValueDisplays, 0, 0)
std::string defaultInStrings[2] = { "Debug", "Smooth" };
GraphOutputDebug(NodeGraphBase* node) :
NodeGraphOp(node, 1, 0, 2)
{}
virtual ~GraphOutputDebug() = default;

bool IsDataVisible(int8_t) override {
virtual void Reset() override;
virtual void Process(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) override;
virtual bool IsDataVisible(int8_t) override {
return true;
}

virtual ~GraphOutputDebug() = default;

std::string_view GetName() override {
virtual bool IsDataEditable(int8_t channel) override {
return channel == 1;
}
virtual std::string_view GetOutputName(int8_t outputChannel) {
return defaultInStrings[outputChannel];
}
virtual std::string_view GetName() override {
return "Debug";
}
protected:
float mValue = 0.0F;
};

/*********************************************************************/
Expand All @@ -369,14 +378,13 @@ namespace l::nodegraph {
mAudioStream(stream),
mCurrentStereoPosition(0)
{}
virtual ~GraphOutputSpeaker() = default;

void Process(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) override;

bool IsDataVisible(int8_t) override {
return true;
}

virtual ~GraphOutputSpeaker() = default;
void Process(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) override;

std::string_view GetOutputName(int8_t outputChannel) {
return defaultOutStrings[outputChannel];
}
Expand Down Expand Up @@ -519,5 +527,106 @@ namespace l::nodegraph {
float mLP3 = 0.0f;
};

/*********************************************************************/
class GraphEffectLimiter : public NodeGraphOp {
public:
std::string defaultInStrings[6] = { "In 1", "In 2", "Attack", "Release", "Preamp", "Limit" };
std::string defaultOutStrings[3] = { "Out 1", "Out 2", "Envelope"};

GraphEffectLimiter(NodeGraphBase* node) :
NodeGraphOp(node, 6, 3, 0)
{}

virtual ~GraphEffectLimiter() = default;
virtual void Reset() override;
virtual void Process(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) override;

virtual bool IsDataVisible(int8_t num) override {
return num >= 2 ? true : false;
}
virtual bool IsDataEditable(int8_t num) override {
return num >= 2 ? true : false;
}
std::string_view GetInputName(int8_t inputChannel) {
return defaultInStrings[inputChannel];
}
std::string_view GetOutputName(int8_t outputChannel) {
return defaultOutStrings[outputChannel];
}
std::string_view GetName() override {
return "Limiter";
}

protected:
float mEnvelope = 0.0f;
};

/*********************************************************************/
class GraphEffectEnvelopeFollower : public NodeGraphOp {
public:
std::string defaultInStrings[6] = { "In 1", "In 2", "Attack", "Release" };
std::string defaultOutStrings[3] = { "Envelope" };

GraphEffectEnvelopeFollower(NodeGraphBase* node) :
NodeGraphOp(node, 4, 1, 0)
{}

virtual ~GraphEffectEnvelopeFollower() = default;
virtual void Reset() override;
virtual void Process(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) override;

virtual bool IsDataVisible(int8_t num) override {
return num >= 2 ? true : false;
}
virtual bool IsDataEditable(int8_t num) override {
return num >= 2 ? true : false;
}
std::string_view GetInputName(int8_t inputChannel) {
return defaultInStrings[inputChannel];
}
std::string_view GetOutputName(int8_t outputChannel) {
return defaultOutStrings[outputChannel];
}
std::string_view GetName() override {
return "Envelope Follower";
}

protected:
float mEnvelope = 0.0f;
};

/*********************************************************************/
class GraphEffectSaturator : public NodeGraphOp {
public:
std::string defaultInStrings[6] = { "In 1", "In 2", "Wet", "Preamp", "Limit", "Postamp"};
std::string defaultOutStrings[3] = { "Out 1", "Out 2"};

GraphEffectSaturator(NodeGraphBase* node) :
NodeGraphOp(node, 6, 2, 0)
{}

virtual ~GraphEffectSaturator() = default;
virtual void Reset() override;
virtual void Process(std::vector<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& outputs) override;

virtual bool IsDataVisible(int8_t num) override {
return num >= 2 ? true : false;
}
virtual bool IsDataEditable(int8_t num) override {
return num >= 2 ? true : false;
}
std::string_view GetInputName(int8_t inputChannel) {
return defaultInStrings[inputChannel];
}
std::string_view GetOutputName(int8_t outputChannel) {
return defaultOutStrings[outputChannel];
}
std::string_view GetName() override {
return "Saturator";
}

protected:
float mEnvelope = 0.0f;
};
}

9 changes: 7 additions & 2 deletions packages/nodegraph/include/nodegraph/NodeGraphSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,20 @@ namespace l::nodegraph {
RegisterNodeType("Numeric", 52, "Negate");
RegisterNodeType("Numeric", 53, "Multiply");
RegisterNodeType("Numeric", 54, "Integral");
RegisterNodeType("Numeric", 55, "Multiply3");
RegisterNodeType("Numeric", 56, "Multiply & Add");
RegisterNodeType("Logic", 100, "And");
RegisterNodeType("Logic", 101, "Or");
RegisterNodeType("Logic", 102, "Xor");
RegisterNodeType("Filter", 150, "Lowpass Filter");
RegisterNodeType("Output", 200, "Value Debug");
RegisterNodeType("Filter", 150, "Lowpass");
RegisterNodeType("Output", 200, "Debug");
RegisterNodeType("Output", 201, "Speaker");
RegisterNodeType("Effect", 250, "Envelope");
RegisterNodeType("Effect", 251, "Reverb1");
RegisterNodeType("Effect", 252, "Reverb2");
RegisterNodeType("Effect", 253, "Limiter");
RegisterNodeType("Effect", 254, "Envelope Follower");
RegisterNodeType("Effect", 255, "Saturator");
}

~NodeGraphSchema() = default;
Expand Down
Loading

0 comments on commit a15566f

Please sign in to comment.