AudioBufferList & AUBufferList::PrepareBuffer(const CAStreamBasicDescription &format, UInt32 nFrames) { if (nFrames > mAllocatedFrames) COMPONENT_THROW(kAudioUnitErr_TooManyFramesToProcess); UInt32 nStreams; UInt32 channelsPerStream; if (format.IsInterleaved()) { nStreams = 1; channelsPerStream = format.mChannelsPerFrame; } else { nStreams = format.mChannelsPerFrame; channelsPerStream = 1; if (nStreams > mAllocatedStreams) COMPONENT_THROW(kAudioUnitErr_FormatNotSupported); } AudioBufferList *abl = mPtrs; abl->mNumberBuffers = nStreams; AudioBuffer *buf = abl->mBuffers; Byte *mem = mMemory; UInt32 streamInterval = (mAllocatedFrames * format.mBytesPerFrame + 0xF) & ~0xF; UInt32 bytesPerBuffer = nFrames * format.mBytesPerFrame; for ( ; nStreams--; ++buf) { buf->mNumberChannels = channelsPerStream; buf->mData = mem; buf->mDataByteSize = bytesPerBuffer; mem += streamInterval; } if (UInt32(mem - mMemory) > mAllocatedBytes) COMPONENT_THROW(kAudioUnitErr_TooManyFramesToProcess); mPtrState = kPtrsToMyMemory; return *mPtrs; }
//_____________________________________________________________________________ // UInt32 AUPannerBase::GetAudioChannelLayout( AudioUnitScope inScope, AudioUnitElement inElement, AudioChannelLayout * outLayoutPtr, Boolean & outWritable) { SetDefaultChannelLayoutsIfNone(); outWritable = true; CAAudioChannelLayout* caacl = NULL; switch (inScope) { case kAudioUnitScope_Input: caacl = &mInputLayout; break; case kAudioUnitScope_Output: caacl = &mOutputLayout; break; default: COMPONENT_THROW(kAudioUnitErr_InvalidScope); } if (inElement != 0) COMPONENT_THROW(kAudioUnitErr_InvalidElement); UInt32 size = caacl->IsValid() ? caacl->Size() : 0; if (size > 0 && outLayoutPtr) memcpy(outLayoutPtr, &caacl->Layout(), size); return size; }
UInt32 AUPinkNoise::GetChannelLayoutTags( AudioUnitScope scope, AudioUnitElement element, AudioChannelLayoutTag * outLayoutTags) { if (scope != kAudioUnitScope_Output) COMPONENT_THROW(kAudioUnitErr_InvalidScope); if (element != 0) COMPONENT_THROW(kAudioUnitErr_InvalidElement); if (outLayoutTags) { UInt32 numChannels = GetOutput(element)->GetStreamFormat().NumberChannels(); if(numChannels == 1) outLayoutTags[0] = kAudioChannelLayoutTag_Mono; else if(numChannels == 2) outLayoutTags[0] = kAudioChannelLayoutTag_Stereo; else if(numChannels == 4) outLayoutTags[0] = kAudioChannelLayoutTag_Quadraphonic; else if(numChannels == 5) outLayoutTags[0] = kAudioChannelLayoutTag_Pentagonal; else if(numChannels == 6) outLayoutTags[0] = kAudioChannelLayoutTag_Hexagonal; else if(numChannels == 8) outLayoutTags[0] = kAudioChannelLayoutTag_Octagonal; else COMPONENT_THROW(kAudioUnitErr_InvalidPropertyValue); } return 1; }
UInt32 AUPinkNoise::GetAudioChannelLayout( AudioUnitScope scope, AudioUnitElement element, AudioChannelLayout * outLayoutPtr, Boolean & outWritable) { if (scope != kAudioUnitScope_Output) COMPONENT_THROW(kAudioUnitErr_InvalidScope); if (element != 0) COMPONENT_THROW(kAudioUnitErr_InvalidElement); UInt32 size = mOutputChannelLayout.IsValid() ? mOutputChannelLayout.Size() : 0; if (size > 0 && outLayoutPtr) memcpy(outLayoutPtr, mOutputChannelLayout, size); outWritable = true; return size; }
AudioBufferList & AUBufferList::PrepareNullBuffer(const CAStreamBasicDescription &format, UInt32 nFrames) { UInt32 nStreams; UInt32 channelsPerStream; if (format.IsInterleaved()) { nStreams = 1; channelsPerStream = format.mChannelsPerFrame; } else { nStreams = format.mChannelsPerFrame; channelsPerStream = 1; if (nStreams > mAllocatedStreams) COMPONENT_THROW(kAudioUnitErr_FormatNotSupported); } AudioBufferList *abl = mPtrs; abl->mNumberBuffers = nStreams; AudioBuffer *buf = abl->mBuffers; UInt32 bytesPerBuffer = nFrames * format.mBytesPerFrame; for ( ; nStreams--; ++buf) { buf->mNumberChannels = channelsPerStream; buf->mData = NULL; buf->mDataByteSize = bytesPerBuffer; } mPtrState = kPtrsToExternalMemory; return *mPtrs; }
void AUInlineKernelBase::Process(const Float32 * srcp, Float32 * dstp, UInt32 frames, UInt32 channels, bool & silence) { if ((srcp != dstp) || (channels != 1)) { COMPONENT_THROW(kAudioUnitErr_FormatNotSupported); } Process(dstp, frames, silence); }
//_____________________________________________________________________________ // // Helper method. // returns the ParameterMapEvent object associated with the paramID // inline ParameterMapEvent& AUElement::GetParamEvent(AudioUnitParameterID paramID) { ParameterMapEvent *event; if(mUseIndexedParameters) { if(paramID >= mIndexedParameters.size() ) COMPONENT_THROW(kAudioUnitErr_InvalidParameter); event = &mIndexedParameters[paramID]; } else { ParameterMap::iterator i = mParameters.find(paramID); if (i == mParameters.end()) COMPONENT_THROW(kAudioUnitErr_InvalidParameter); event = &(*i).second; } return *event; }