[VST3] Adding a sidechain audio input to again

To add a sidechain audio input to the again VST3 plug-in is actually very simple.
You need to add the input in the initialize(…) method of the AGain class:

  1. addAudioInput  (USTRING ("Sidechain Mono In"),  SpeakerArr::kMono, kAux);

After that you can check in the process function if the sidechain is active :

  1. BusList* busList = getBusList (kAudio, kInput);
  2. Bus* bus = busList ? (Bus*)busList->at (1) : 0;
  3. if (bus && bus->isActive ())
  4. {
  5.         // sidechain is active !!!
  6.         float* sidechainIn  = data.inputs[1].channelBuffers32[0];
  7.         // do some processing with the input samples …
  8. }

To get this all working with AGain there are some more change to be done in AGain::setBusArrangements(…):

  1. tresult PLUGIN_API AGain::setBusArrangements (SpeakerArrangement* inputs, int32 numIns, SpeakerArrangement* outputs, int32 numOuts)
  2. {
  3.   if (numIns == 2 && numOuts == 1)  // Sidechain chain, was: numIns == 1
  4.   {
  5.     if (inputs[0] == SpeakerArr::kMono && outputs[0] == SpeakerArr::kMono)
  6.     {
  7.       AudioBus* bus = (AudioBus*)(audioInputs.at (0));
  8.       if (bus)
  9.       {
  10.         if (bus->getArrangement () != SpeakerArr::kMono)
  11.         {
  12.           removeAudioBusses ();
  13.           addAudioInput  (USTRING ("Mono In"),  SpeakerArr::kMono);
  14.           addAudioOutput (USTRING ("Mono Out"), SpeakerArr::kMono);
  15.           addAudioInput  (USTRING ("Sidechain Mono In"),  SpeakerArr::kMono, kAux); // add sidechain, always mono
  16.         }
  17.         return kResultOk;
  18.       }
  19.     }
  20.     else
  21.     {
  22.       AudioBus* bus = (AudioBus*)(audioInputs.at (0));
  23.       if (bus)
  24.       {
  25.         if (bus->getArrangement () != SpeakerArr::kStereo)
  26.         {
  27.           removeAudioBusses ();
  28.           addAudioInput  (USTRING ("Stereo In"),  SpeakerArr::kStereo);
  29.           addAudioOutput (USTRING ("Stereo Out"), SpeakerArr::kStereo);
  30.           addAudioInput  (USTRING ("Sidechain Mono In"),  SpeakerArr::kMono, kAux); // add sidechain, always mono
  31.         }
  32.         return kResultOk;
  33.       }
  34.     }
  35.   }
  36.   return kResultFalse;
  37. }

No Comments! Be The First!

Leave a Reply