Пример #1
0
OSStatus AKSampler_Plugin::Render(AudioUnitRenderActionFlags &ioActionFlags, const AudioTimeStamp &inTimeStamp, UInt32 nFrames)
{
    AUOutputElement* outputBus = GetOutput(0);
    outputBus->PrepareBuffer(nFrames); // prepare the output buffer list
    
    AudioBufferList& outputBufList = outputBus->GetBufferList();
    AUBufferList::ZeroBuffer(outputBufList);
    
    float* outBuffers[2];
    outBuffers[0] = (float*)(outputBufList.mBuffers[0].mData);
    outBuffers[1] = (float*)(outputBufList.mBuffers[1].mData);
    
    // process in chunks of maximum length CHUNKSIZE
    for (int frameIndex = 0; frameIndex < nFrames; frameIndex += CHUNKSIZE) {
        int chunkSize = nFrames - frameIndex;
        if (chunkSize > CHUNKSIZE) chunkSize = CHUNKSIZE;
        
        // Any ramping parameters would be updated here...
        
        unsigned channelCount = outputBufList.mNumberBuffers;
        AKCoreSampler::render(channelCount, chunkSize, outBuffers);
        
        outBuffers[0] += CHUNKSIZE;
        outBuffers[1] += CHUNKSIZE;
    }
    
    return noErr;
}
OSStatus 	SonogramViewDemo::Render(	AudioUnitRenderActionFlags		&ioActionFlags,
												const AudioTimeStamp &			inTimeStamp,
												UInt32							inFramesToProcess )
{
	UInt32 actionFlags = 0;
	OSStatus err = PullInput(0, actionFlags, inTimeStamp, inFramesToProcess);
	if (err) return err;
	
	AUInputElement* inputBus = GetInput(0);
	AUOutputElement* outputBus = GetOutput(0);	
	outputBus->PrepareBuffer(inFramesToProcess); // prepare the output buffer list	
	AudioBufferList& inputBufList = inputBus->GetBufferList();
	
	if (
		mSpectralProcessor->ProcessForwards(inFramesToProcess, &inputBufList)
	){
		
		
		AudioBufferList* sdBufferList = &mSpectralDataBufferList->GetModifiableBufferList(); 
		mSpectralProcessor->GetMagnitude(sdBufferList, mMinAmp, mMaxAmp);
		// copy mNumBins of numbers out
			
		SampleTime s = (SampleTime) (mRenderStamp.mSampleTime);
		mSpectrumBuffer->Store(sdBufferList, 1, s);
		
		mRenderStamp.mSampleTime += 1; 
	}			
	return AUEffectBase::Render(ioActionFlags, inTimeStamp, inFramesToProcess);

}
Пример #3
0
ComponentResult 	SooperLooperAU::Render(	AudioUnitRenderActionFlags &ioActionFlags,
											const AudioTimeStamp &		inTimeStamp,
											UInt32						nFrames)
{
		// save the timestamp
	_curr_stamp = inTimeStamp;
	
	if (_last_rendered_frames != nFrames) {
		_last_rendered_frames = nFrames;
		ConnectionsChanged(); // emit
	}
	
	// if we're bypassed we need to passthru the other buses
	if (ShouldBypassEffect())
	{
		
		for (size_t n=1; n < SL_MAXLOOPS; ++n) 
		{
			try {
				AUOutputElement *theOutput = GetOutput(n);	// throws if error
				AUInputElement *theInput = GetInput(n);
				if (theOutput && theInput) {
					OSStatus result = theInput->PullInput(ioActionFlags, _curr_stamp, 0 /* element */, nFrames);
					
					if (result == noErr) {
						if(ProcessesInPlace() )
						{
							theOutput->SetBufferList(theInput->GetBufferList() );
						}
						else {
							theOutput->PrepareBuffer(nFrames);
						}
						
						// leave silence bit alone
						if(!ProcessesInPlace() )
						{
							theInput->CopyBufferContentsTo (theOutput->GetBufferList());
						}
					}
				}
			} catch (...) {
				//cerr << "got exception: " << endl;	
			}
		}
		
	}
	
	return AUMIDIEffectBase::Render (ioActionFlags, inTimeStamp, nFrames);
}
Пример #4
0
OSStatus MT32Synth::Render(AudioUnitRenderActionFlags &ioActionFlags, const AudioTimeStamp &inTimeStamp, UInt32 inNumberFrames) {

    if(!synth) {
        return noErr;
    }
    
    AUOutputElement* outputBus = GetOutput(0);
	outputBus->PrepareBuffer(inNumberFrames);
	
	AudioBufferList& outputBufList = outputBus->GetBufferList();
	AUBufferList::ZeroBuffer(outputBufList);

    UInt32 ioOutputDataPackets = inNumberFrames * destFormat.mFramesPerPacket;
    AudioConverterFillComplexBuffer(audioConverterRef, EncoderDataProc, (void*) this, &ioOutputDataPackets, &outputBufList, NULL);

    return noErr;
}
Пример #5
0
OSStatus 	AUPinkNoise::Render(		AudioUnitRenderActionFlags &ioActionFlags,
												const AudioTimeStamp &		inTimeStamp,
												UInt32						nFrames)
{		
	AUOutputElement* outputBus = GetOutput(0);
	outputBus->PrepareBuffer(nFrames); // prepare the output buffer list
	
	AudioBufferList& outputBufList = outputBus->GetBufferList();
	AUBufferList::ZeroBuffer(outputBufList);	
	
	// only render if the on parameter is true. Otherwise send the zeroed buffer
	if (Globals()->GetParameter(kParam_On))
	{
		for (UInt32 i=0; i < outputBufList.mNumberBuffers; i++)
			mPink->Render((Float32*)outputBufList.mBuffers[i].mData, nFrames, Globals()->GetParameter(kParam_Volume));
	}	
	return noErr;
}
Пример #6
0
OSStatus			SooperLooperAU::ProcessBufferLists(
											   AudioUnitRenderActionFlags &	ioActionFlags,
											   const AudioBufferList &			inBuffer,
											   AudioBufferList &				outBuffer,
											   UInt32							inFramesToProcess )
{	
	// deinterleaved		
	//const AudioBuffer *srcBuffer = inBuffer.mBuffers;
	//AudioBuffer *destBuffer = outBuffer.mBuffers;
	
		
	if (inBuffer.mNumberBuffers == 1) {
		if (_chancnt > 1) {
			//cerr << "interleaved " << _chancnt << endl;
			ioActionFlags |= kAudioUnitRenderAction_OutputIsSilence;
			return kAudioUnitErr_InvalidParameter;
		}
	}
	
	_in_buflist[0] = (AudioBufferList *) &inBuffer;
	_out_buflist[0] = &outBuffer;

//cerr << "main bus:  " << _out_buflist[0] << " count: " << outBuffer.mNumberBuffers << endl;

	// this is called with the main bus (0) buffers
	// we really should subclass Render here, but instead
	// we'll just get the other busses data too

	for (size_t n=1;  n < SL_MAXLOOPS; ++n) 
	{
		try {
			AUOutputElement *theOutput = GetOutput(n);	// throws if error
			AUInputElement *theInput = GetInput(n);
			if (theOutput && theInput) {
				OSStatus result = theInput->PullInput(ioActionFlags, _curr_stamp, 0 /* element */, inFramesToProcess);
			
				if (result == noErr) {
					if(ProcessesInPlace() )
					{
						theOutput->SetBufferList(theInput->GetBufferList() );
					}
					else {
						theOutput->PrepareBuffer(inFramesToProcess);
					}
					_in_buflist[n] = &theInput->GetBufferList();
				}
				else {
					// no input, just do output
					theOutput->PrepareBuffer(inFramesToProcess);
				}
				
				if (n > _engine->loop_count()) {
					// zero the buffer
					AUBufferList::ZeroBuffer(theOutput->GetBufferList());
				} else if (_engine->get_loop_channel_count(n-1, true) == 1) {
					// for the sidechain outputs that are mono, set the 2nd channel to be == to the first					
					//theOutput->SetBuffer(1, theOutput->GetBufferList().mBuffers[0]);
				}
				
								
				_out_buflist[n] = &theOutput->GetBufferList();
				//cerr << "got bus output: " << n <<  "  " << _out_buflist[n] << " count: " << theOutput->GetBufferList().mNumberBuffers << endl;

								
			}
			else {
				//cerr << "don't have both in and out for: " << n << endl;
			}
		} catch (...) {
				//cerr << "got exception: with bus " << n <<  endl;	
		}
	}
		

	// actually do the work

	_engine->process (inFramesToProcess);
	
	

	_in_buflist[0] = 0;
	_out_buflist[0] = 0;
	
	for (size_t n=1; n <= _engine->loop_count() && n < SL_MAXLOOPS; ++n) {
		if (_engine->get_loop_channel_count(n-1, true) == 1) {
			memcpy(_out_buflist[n]->mBuffers[1].mData, _out_buflist[n]->mBuffers[0].mData, sizeof(float) * inFramesToProcess);
		}
		
		
		_in_buflist[n] = 0;	
		_out_buflist[n] = 0;			
	}

	// force output to be something
	ioActionFlags &= ~kAudioUnitRenderAction_OutputIsSilence;
	
	return noErr;
}