diff --git a/modules/foleys_dsp_magic/DSP/foleys_DspProgram.cpp b/modules/foleys_dsp_magic/DSP/foleys_DspProgram.cpp index 11c05221..d39d2ebb 100644 --- a/modules/foleys_dsp_magic/DSP/foleys_DspProgram.cpp +++ b/modules/foleys_dsp_magic/DSP/foleys_DspProgram.cpp @@ -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 (i)); + audioOutputs[i]->setAudioBuffer (busBuffer.getArrayOfWritePointers(), busBuffer.getNumChannels(), busBuffer.getNumSamples()); + } + for (auto* node: order) node->process (buffer.getNumSamples()); } diff --git a/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.cpp b/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.cpp index 59b9149a..575eccb4 100644 --- a/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.cpp +++ b/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.cpp @@ -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 (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) { } diff --git a/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.h b/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.h index 04435a9b..3d296d58 100644 --- a/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.h +++ b/modules/foleys_dsp_magic/Nodes/foleys_BuiltinNodes.h @@ -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 buffer; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioOutput) }; diff --git a/modules/foleys_dsp_magic/Nodes/foleys_Oscilloscope.cpp b/modules/foleys_dsp_magic/Nodes/foleys_Oscilloscope.cpp index 3bcdd129..7908bf71 100644 --- a/modules/foleys_dsp_magic/Nodes/foleys_Oscilloscope.cpp +++ b/modules/foleys_dsp_magic/Nodes/foleys_Oscilloscope.cpp @@ -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);