Send amount in AudioProcessorGraph

4 posts / 0 new
Last post
siedschl
Offline
Last seen: 4 days 8 hours ago
Joined: 7 Nov 2007 - 09:56
Send amount in AudioProcessorGraph

Can I ask for something? I made an addition to the AudioProcessorGraph, namely the possibility to add a property called "sendAmount" to a node, which can range from 0 to 1 where 0 is complete bypass and 1 a full insert. For this to work, I made the following changes to the ProcessBufferOp class (everything commented with "CS" is my stuff). I think this is a useful feature to have, any chance to add this to the official JUCE code?

class ProcessBufferOp : public AudioGraphRenderingOp
{
public:
    ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
                     const Array <int>& audioChannelsToUse_,
                     const int totalChans_,
                     const int midiBufferToUse_)
        : node (node_),
          processor (node_->getProcessor()),
          audioChannelsToUse (audioChannelsToUse_),
          totalChans (jmax (1, totalChans_)),
          midiBufferToUse (midiBufferToUse_)
    {
        channels.calloc ((size_t) totalChans);

        while (audioChannelsToUse.size() < totalChans)
            audioChannelsToUse.add (0);
        //begin CS
		sendAmount=node->properties.getWithDefault("sendAmount",1);
               delaySamples=node->getProcessor()->getLatencySamples();
		DelayChannelOp *DOP=0;
		if (delaySamples>0)
		{
			for (int i=0;i<totalChans;i++) 
			{
				DOP = new DelayChannelOp(0,delaySamples); //buffer will be 1-D, so channel 0, not i
				DelayOps.add(DOP);
			}
		}
		//end CS
    }
    ~ProcessBufferOp()
	{
		DelayOps.clear(true);
	}

    void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
    {
        for (int i = totalChans; --i >= 0;)
            channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);

        AudioSampleBuffer buffer (channels, totalChans, numSamples);
        //begin CS
		AudioSampleBuffer bypassBuffer(totalChans, numSamples);
		AudioSampleBuffer delayBuffer(1,numSamples);
		if (sendAmount<1)
		{
			bypassBuffer=buffer;
			buffer.applyGain(0,numSamples,sendAmount);
			bypassBuffer.applyGain(0,numSamples,1-sendAmount);
		} 
        //end CS
        processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
        //begin CS
		if (sendAmount<1) 
		{
			if (delaySamples>0) 
				for (int i=0;i<totalChans;i++) 
				{
					delayBuffer.copyFrom(0,0,bypassBuffer,i,0,numSamples);
					DelayOps[i]->perform(delayBuffer,sharedMidiBuffers,numSamples); //CS: MIDI buffers useless
					bypassBuffer.copyFrom(i,0,delayBuffer,0,0,numSamples);
				}
			for (int i=0;i<totalChans;i++) buffer.addFrom(i,0,bypassBuffer,i,0,numSamples);
		} 
       //end CS
    }

    const AudioProcessorGraph::Node::Ptr node;
    AudioProcessor* const processor;

private:
    Array <int> audioChannelsToUse;
    HeapBlock <float*> channels;
    OwnedArray<DelayChannelOp> DelayOps; //CS
    float sendAmount; //CS
    int delaySamples; //CS
    int totalChans;
    int midiBufferToUse;

    JUCE_DECLARE_NON_COPYABLE (ProcessBufferOp);
};
jules
Offline
Last seen: 6 hours 23 min ago
Joined: 29 Apr 2013 - 18:37
Re: Send amount in AudioProcessorGraph

I'd have thought it's more the responsibility of the AudioProcessor to do that..?

siedschl
Offline
Last seen: 4 days 8 hours ago
Joined: 7 Nov 2007 - 09:56
Re: Send amount in AudioProcessorGraph

Fair enough... then how about something like that in the processor class? Of course I could subclass, but as I said, I think this would be a useful feature in general.

jules
Offline
Last seen: 6 hours 23 min ago
Joined: 29 Apr 2013 - 18:37
Re: Send amount in AudioProcessorGraph

Well, I kind of meant that it's your own AudioProcessor that should probably handle that kind of thing, not the base class at all.