Re: Audio Unit with SideChain
Re: Audio Unit with SideChain
- Subject: Re: Audio Unit with SideChain
- From: Stefan Huber <email@hidden>
- Date: Mon, 20 Feb 2012 22:19:46 +0100
Hi,
I have been facing the same problem regarding sidechain inputs for some time. If no sidechain input is selected, the sidechain buffer simply points to the buffer of the first input.
I compared the code below with mine, but there essentially is no difference (except for the part about the preference option, which I suppose is a parameter that is set somehow manually).
If I launch the debugger to see what is going on, the following things happen with NO sidechain connected (Using Logic Pro 8 and 10.6.8)
> try { sidechainIsAvailable = HasInput(1); }
sets sidechainsIsAvailable to true
> theSidechainInput = GetInput(1);
returns the sidechain input
> status = theSidechainInput->PullInput(dummyFlags, inTimeStamp,1, nFrames);
sets status to 0, which is noErr
> long scnb = sidechainBufferList->mNumberBuffers;
returns 1
Unfortunately I don't see any way to determine if the sidechain is not connected or if it is just set to the same channel the plug-in is used on. Has anyone gotten different results? Maybe something has changed with Logic 9? (I am still running version 8)
Best,
Stefan
>
> This is how we do this in our plug ins (code courtesy of Stephan
> Bernsee and a couple of others here on the list):
>
> // -----------------------------------------------------------------------------------------------------------------------------------
>
> /*! @method Render */
> ComponentResult myAuClassName::Render( AudioUnitRenderActionFlags
> & ioActionFlags,
> const AudioTimeStamp & inTimeStamp,
> UInt32 nFrames)
>
> {
> if (!HasInput(0))
> return kAudioUnitErr_NoConnection;
>
> ComponentResult result = noErr;
> AUOutputElement *theOutput = GetOutput(0); // throws if error
>
> AUInputElement *theInput = GetInput(0);
> result = theInput->PullInput(ioActionFlags, inTimeStamp, 0 /* element
> */, nFrames);
>
> if (result == noErr)
> {
> if(ProcessesInPlace() ) {
> theOutput->SetBufferList(theInput->GetBufferList() );
> }
>
> if (ShouldBypassEffect()) {
> // leave silence bit alone
>
> if(!ProcessesInPlace() ) {
> theInput->CopyBufferContentsTo (theOutput->GetBufferList());
> }
>
> } else {
>
> // this is set as a preference option for the plug in
> if (mAllowSideChain) {
>
> OSStatus status = noErr;
> AudioBufferList *mainBufferList = &(theInput->GetBufferList());
> AudioBufferList *sidechainBufferList = NULL;
> AUInputElement *theSidechainInput = NULL;
> AudioUnitRenderActionFlags dummyFlags=ioActionFlags;
> bool sidechainIsAvailable = false;
> try { sidechainIsAvailable = HasInput(1); }
> catch (...) { sidechainIsAvailable = false; }
> if (sidechainIsAvailable) {
> theSidechainInput = GetInput(1);
> if (theSidechainInput != NULL) {
> status = theSidechainInput->PullInput(dummyFlags, inTimeStamp,
> 1, nFrames);
> if (status == noErr)
> sidechainBufferList = &(theSidechainInput->GetBufferList());
> }
> }
>
> if (sidechainBufferList != NULL) {
>
> // we have a sidechain
> long scnb = sidechainBufferList->mNumberBuffers;
> long mnb = mainBufferList->mNumberBuffers;
>
> // we should not alloc here but rather do this somewhere else
> AudioBufferList *abl = AllocateAudioBufferList(mnb+scnb,
> nFrames*sizeof(float));
> long idx = 0;
> for (long v = 0; v < mnb; v++) {
> memmove(abl->mBuffers[idx].mData,
> mainBufferList->mBuffers[v].mData, nFrames*sizeof(float));
> idx++;
> }
> for (long v = 0; v < scnb; v++) {
> memmove(abl->mBuffers[idx].mData,
> sidechainBufferList->mBuffers[v].mData, nFrames*sizeof(float));
> idx++;
> }
>
> // this will read/write silence bit
> result = ProcessBufferLists(ioActionFlags, *abl,
> theOutput->GetBufferList(), nFrames);
>
> DestroyAudioBufferList(abl);
>
> } else {
> // this will read/write silence bit
> result = ProcessBufferLists(ioActionFlags,
> theInput->GetBufferList(), theOutput->GetBufferList(), nFrames);
> }
>
> // side chain is switched off
> } else result = ProcessBufferLists(ioActionFlags,
> theInput->GetBufferList(), theOutput->GetBufferList(), nFrames);
>
> }
>
> if ( (ioActionFlags & kAudioUnitRenderAction_OutputIsSilence) &&
> !ProcessesInPlace() )
> {
> AUBufferList::ZeroBuffer(theOutput->GetBufferList() );
> }
> }
>
> return result;
> }
>
>
> // -----------------------------------------------------------------------------------------------------------------------------------
>
> On Nov 24, 2011, at 9:03 PM, email@hidden wrote:
>
>> Date: Thu, 24 Nov 2011 14:29:27 +0100
>> From: Fokke de Jong <email@hidden>
>> Subject: Audio Unit with SideChain
>> To: coreAudio list <email@hidden>
>> Message-ID: <email@hidden>
>> Content-Type: text/plain; charset=us-ascii
>>
>> Hi All,
>>
>> I'm writing an AU with sidechain input. so I have created 2 input busses. Under 'normal' circumstances this is working. But when in Logic Pro 9 I set the sidechain input to "None", the sidechain input actually contains a pointer to the same data as my 'regular' input (input 0). I would expect this to be null. Is there some other way I can check if my sidechain is connected or not? (In Ableton Live the inputs have different buffers)
>>
>>
>> Thanks,
>> Fokke
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden