AU ChangeStreamFormat() gotcha
AU ChangeStreamFormat() gotcha
- Subject: AU ChangeStreamFormat() gotcha
- From: Marc Poirier <email@hidden>
- Date: Tue, 20 Jul 2004 09:45:45 -0400
Hi folks. I just found a bug in Pluggo that was resulting in sample
rate changes being ignored, and I thought I'd share what I found since
I could imagine others possibly making the same mistake.
So my code looked a little like this:
ComponentResult Pluggo::ChangeStreamFormat(AudioUnitScope inScope,
AudioUnitElement inElement, const CAStreamBasicDescription &
inPrevFormat, const CAStreamBasicDescription & inNewFormat)
{
ComponentResult result = AUBase::ChangeStreamFormat(inScope,
inElement, inPrevFormat, inNewFormat);
if (result == noErr)
{
if (inPrevFormat.mSampleRate != inNewFormat.mSampleRate)
UpdateOurSampleRate(inNewFormat.mSampleRate);
}
return result;
}
The problem there is comparing inPrevFormat vs. inNewFormat after
calling AUBase::ChangeStreamFormat(). After that call, inPrevFormat is
set to inNewFormat. This is where C++ &-style variable passing (sorry,
I don't know the technical name for it) can get you. inPrevFormat is
actually the AUBase (or Scope, actually) member variable storing our
current state, not a local variable in ChangeStreamFormat. So if you
have code like what I had, you want to either store the original sample
rate to some local variable before calling AUBase::ChangeStreamFormat()
and then compare to that afterwards, or just don't bother comparing
values after the call.
Marc
_______________________________________________
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.