Send amount in AudioProcessorGraph

Discussion and support for general JUCE issues

Send amount in AudioProcessorGraph

Postby siedschl » Fri Jun 15, 2012 9:33 am

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?

Code: Select all
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);
};
siedschl
JUCE UberWeenie
 
Posts: 273
Joined: Wed Nov 07, 2007 10:56 am

Re: Send amount in AudioProcessorGraph

Postby jules » Fri Jun 15, 2012 11:29 am

I'd have thought it's more the responsibility of the AudioProcessor to do that..?
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Send amount in AudioProcessorGraph

Postby siedschl » Fri Jun 15, 2012 1:26 pm

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.
siedschl
JUCE UberWeenie
 
Posts: 273
Joined: Wed Nov 07, 2007 10:56 am

Re: Send amount in AudioProcessorGraph

Postby jules » Fri Jun 15, 2012 5:29 pm

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.
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK


Return to General JUCE discussion

Who is online

Users browsing this forum: Alatar and 4 guests