Beispiel #1
0
OSStatus Talkbox::Render(AudioUnitRenderActionFlags & ioActionFlags, const AudioTimeStamp & inTimeStamp, UInt32 inFramesToProcess)
{
	if (! HasInput(0) )
{
//fprintf(stderr, "no input bus 0 connection\n");
		return kAudioUnitErr_NoConnection;
}

	OSStatus status = noErr;
	AUOutputElement * theOutput = GetOutput(0);	// throws if error

	AUInputElement * theInput = GetInput(0);
	status = theInput->PullInput(ioActionFlags, inTimeStamp, 0 /* element */, inFramesToProcess);
	if (status != noErr)
		return status;
	
	if (status == noErr)
	{
		if ( ProcessesInPlace() )
		{
			theOutput->SetBufferList( theInput->GetBufferList() );
		}

		AUInputElement * theInput2 = NULL;
		try
		{
			if ( HasInput(1) )
				theInput2 = GetInput(1);
		}
		catch (...) { theInput2 = NULL; }
		if (theInput2 != NULL)
		{
			bool mainInputSilentFlag = (ioActionFlags & kAudioUnitRenderAction_OutputIsSilence) ? true : false;
			status = theInput2->PullInput(ioActionFlags, inTimeStamp, 1 /* element */, inFramesToProcess);
//if (result != noErr) fprintf(stderr, "PullInput(bus 1) error %ld\n", result);
			if ( !mainInputSilentFlag && (ioActionFlags & kAudioUnitRenderAction_OutputIsSilence) )
				ioActionFlags &= ~kAudioUnitRenderAction_OutputIsSilence;
		}
		else
{
			status = kAudioUnitErr_NoConnection;
//fprintf(stderr, "could not access input bus 1 connection\n");
}

		if ( ShouldBypassEffect() || (status != noErr) )
		{
			status = noErr;
			// leave silence bit alone
			if (! ProcessesInPlace() )
			{
				theInput->CopyBufferContentsTo( theOutput->GetBufferList() );
			}
		}
		else
		{
			for (UInt32 i=0; i < numAllocatedChannels; i++)
			{
				dspKernels[i]->Process(theInput->GetChannelData(i), 
										theInput2->GetChannelData(i), 
										theOutput->GetChannelData(i), 
										inFramesToProcess);
			}
		}
	}

	return status;
}