Skip to content

Commit

Permalink
Fixed output connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ffAudio committed May 11, 2024
1 parent 812a754 commit 91b63e5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions modules/foleys_dsp_magic/DSP/foleys_DspProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ void DspProgram::processBlock (juce::AudioProcessor& processor, juce::AudioBuffe
audioInputs[i]->setAudioBuffer (busBuffer.getArrayOfWritePointers(), busBuffer.getNumChannels(), busBuffer.getNumSamples());
}

for (size_t i = 0; i < audioOutputs.size(); ++i)
{
auto busBuffer = processor.getBusBuffer (buffer, false, static_cast<int> (i));
audioOutputs[i]->setAudioBuffer (busBuffer.getArrayOfWritePointers(), busBuffer.getNumChannels(), busBuffer.getNumSamples());
}

for (auto* node: order)
node->process (buffer.getNumSamples());
}
Expand Down
24 changes: 24 additions & 0 deletions modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ AudioOutput::AudioOutput (DspProgram& program, const juce::ValueTree& node) : Ds
addAudioInput (TRANS ("Audio In"));
}

void AudioOutput::setAudioBuffer (float* const* data, int numChannels, int numSamples)
{
buffer.setDataToReferTo (data, numChannels, numSamples);
}

void AudioOutput::process ([[maybe_unused]] int numSamples)
{
auto* source = getConnectedOutput (ConnectionType::Audio, 0);
if (!source)
{
buffer.clear();
return;
}

auto audio = source->getAudio();
for (int ch = 0; ch < std::min (buffer.getNumChannels(), static_cast<int> (audio.getNumChannels())); ++ch)
if (buffer.getWritePointer (ch) != audio.getChannelPointer (ch))
buffer.copyFrom (ch, 0, source->getAudio().getChannelPointer (ch), buffer.getNumSamples());

for (int ch = audio.getNumChannels(); ch < buffer.getNumChannels(); ++ch)
buffer.clear (ch, 0, buffer.getNumSamples());
}


// ================================================================================

ParameterInput::ParameterInput (DspProgram& program, const juce::ValueTree& node) : DspNode (program, node) { }
Expand Down
5 changes: 4 additions & 1 deletion modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ class AudioOutput : public DspNode
[[nodiscard]] juce::String getCategory() const override { return Category::InOut; }

void prepare ([[maybe_unused]] juce::dsp::ProcessSpec spec) override { }
void process ([[maybe_unused]] int numSamples) override { }
void process ([[maybe_unused]] int numSamples) override;

void setAudioBuffer (float* const* data, int numChannels, int numSamples);

FOLEYS_DECLARE_DSP_FACTORY (AudioOutput)
private:
juce::AudioBuffer<float> buffer;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioOutput)
};

Expand Down
3 changes: 3 additions & 0 deletions modules/foleys_dsp_magic/Nodes/foleys_Oscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void Oscilloscope::process ([[maybe_unused]] int numSamples)
if (auto* output = getConnectedOutput (ConnectionType::Audio, 0))
{
auto audio = output->getAudio();
if (audio.getNumSamples() == 0)
return;

float* pointers[audio.getNumChannels()];
for (size_t c = 0; c < audio.getNumChannels(); ++c)
pointers[c] = audio.getChannelPointer (c);
Expand Down

0 comments on commit 91b63e5

Please sign in to comment.