AUEffectBase and Stream formats
AUEffectBase and Stream formats
- Subject: AUEffectBase and Stream formats
- From: Bill Stewart <email@hidden>
- Date: Sat, 29 Mar 2003 13:22:02 -0800
One change I am exploring in AUEffect base is the disallowing of
setting stream formats on an effect once it has been initialized.
There are two reasons for this.
Currently, whenever a format is set on an effect, the MaintainKernels()
method is called which maintains the per-channel set of kernels that
are used in the render operation. As an AU is set for its different
channels on input and output, this leads to this work being done on
each format set...
Secondly, I'd like to tighten up the enforcement of the assumption that
an Effect that doesn't publish a custom set of channel valences on in
and output, will ONLY accept matching input and output channel numbers.
To that affect, I'd propose the following changes to AUEffectBase. I'm
posting them here as I would like to get some feedback from these
changes before I release them in an SDK. If these changes cause
problems, and they are in the SDK, there is the unfortunate likelihood
that those changes will live on past their time of usefuleness.
So, here's the changes. I've tested these with our AUs in both Logic
and Spark and don't see any problems.. I'd like to see some more
testing (which I'll try myself... but confirmation would be nice:)...
ComponentResult AUEffectBase::Initialize()
{
// This base class only supports effects that have the same number of
// channels in and out - so we check here that this is the case
if ((GetNumberOfChannels() !=
GetInput(0)->GetStreamFormat().mChannelsPerFrame) ||
(GetNumberOfChannels() == 0))
{
return kAudioUnitErr_FormatNotSupported;
}
MaintainKernels();
return noErr;
}
This enforcement cannot be guaranteed if the format can be set after
initialization because the AU can't distinguish between setting formats
that are going to be legal (say you are changing input and output -
that is 2 calls - I can't validate that in the process of setting those
formats)
Here the change is to validate that the channels map on in and out
before initialization will succeed. If not, the AU now tells you that
there is an error...
The MaintainKernels should of course have the fix that Marc described:
for(unsigned int i = 0; i < nChannels; i++ )
{
if(mKernelList[i]) mKernelList[i]->SetLastKernel(i == nChannels-1 );
}
(ie. check that mKernelList[i] is NOT NULL:)
You need to add this change (ie. can't set a format if you are
initialized)...
bool AUEffectBase::StreamFormatWritable( AudioUnitScope scope,
AudioUnitElement element)
{
return IsInitialized() ? false : true;
}
Then, ChangeStreamFormat will not have to call MaintainKernels - as
that is now taken care of in Initialization...
ComponentResult AUEffectBase::ChangeStreamFormat( AudioUnitScope
inScope,
AudioUnitElement inElement,
const CAStreamBasicDescription & inPrevFormat,
const CAStreamBasicDescription & inNewFormat)
{
ComponentResult result = AUBase::ChangeStreamFormat(inScope,
inElement, inPrevFormat, inNewFormat);
if (result == noErr)
{
// for the moment this is the only dependency we know about
// where a parameter's range may change with a different sample rate
if (GetParamHasSampleRateDependency() && inPrevFormat.mSampleRate !=
inNewFormat.mSampleRate)
PropertyChanged(kAudioUnitProperty_ParameterList,
kAudioUnitScope_Global, 0);
}
return result;
}
This also removes the need to make this check WHILST in the render call
- this is in ProcessBufferLists and can I think be removed:
First the general check at the start:
if ((nBuffers=inBuffer.mNumberBuffers) != outBuffer.mNumberBuffers ||
nBuffers == 0)
return kAudioUnitErr_FormatNotSupported;
Then for the mono or interleaved case:
if ((nChannels=inBuffer.mBuffers[0].mNumberChannels) !=
outBuffer.mBuffers[0].mNumberChannels
|| nChannels != mKernelList.size())
return kAudioUnitErr_FormatNotSupported;
For the deinterleaved case:
// deinterleaved
if (nBuffers != mKernelList.size())
return kAudioUnitErr_FormatNotSupported;
It doesn't seem good to me that the only time you would find out about
this format mis-match is when you try to render...
Bill
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________
__
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.