• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Audio Unit with SideChain
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Audio Unit with SideChain


  • Subject: Re: Audio Unit with SideChain
  • From: tahome izwah <email@hidden>
  • Date: Sat, 14 Jan 2012 18:14:11 +0100

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;
}


// -----------------------------------------------------------------------------------------------------------------------------------





2012/1/10 Stefan Wiegand <email@hidden>:
> Hi Fokke,
>
> Did you ever find a solution for this problem? I would be interested to
> know about the right way as well.
>
> Thanks,
> Stefan
>
> On 24.11.11 14:29, "Fokke de Jong" <email@hidden> wrote:
>
>>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
>
>  _______________________________________________
> 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
 _______________________________________________
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

References: 
 >Re: Audio Unit with SideChain (From: Stefan Wiegand <email@hidden>)

  • Prev by Date: Re: Reducing input sensitivity on external microphone
  • Next by Date: How to go about debugging transient "statics" using AudioUnit's RemoteIO
  • Previous by thread: Re: Audio Unit with SideChain
  • Next by thread: Updating Cocoa View of system-supplied Audio Units
  • Index(es):
    • Date
    • Thread