Re: AudioUnitKernal constructor called twice...
Re: AudioUnitKernal constructor called twice...
- Subject: Re: AudioUnitKernal constructor called twice...
- From: Brian Willoughby <email@hidden>
- Date: Wed, 10 Aug 2011 16:43:02 -0700
On Aug 10, 2011, at 13:30, tahome izwah wrote:
Last time I checked separate channels are using separate kernel
instances, in order to be able to distribute processing across
multiple cores.
The reason that AUEffectBase creates a separate kernel for each
channel has nothing to do with multiple CPU cores or distributing the
CPU load. Creating a new C++ object instance has absolutely nothing
to do with creating a separate execution thread, the latter being
required to distribute processor across multiple cores. For the most
part, you will find that AudioUnits with multiple kernels will still
execute entirely on one thread and one core.
The actual reason that AUEffectBase creates a separate kernel for
each channel is so that your AudioUnit code can be written once and
reused to handle any number of channels, each with their own state.
The C++ kernel object holds any state variables needed by an
individual channel. The main AUEffectBase class holds any state
variables that are common to all channels. Each kernel object has a
pointer back to the main, common object instance. Such a design
allows the same code to work with mono, stereo, 5.1, 10.2, quad, or
any number of channels, whether or not the total channel count is
known at the time the code is written.
2011/8/9 email@hidden <email@hidden>:
I am making an audio unit called 'PlayerUnit'. I started with an
audio unit template, followed the audio unit tutorial docs, and am
adding code to the audio unit kernel constructor (in this case,
PlayerUnit::PlayerUnitKernel::PlayerUnitKernel() ). When I run my
project, xcode runs AU Lab, where PlayerUnit is instantiated as an
effect on an 'AU Generator' channel. 'PlayerUnit' can then print
values to the console so I can see what's going on.
After using 'printf()' a fair bit in the kernel constructor, it has
become apparent that this constructor is being called twice. I did
not expect this. I thought there would be one audio unit kernel
which processes interleaved audio data. Why is the constructor
being called twice? Is it something I have done wrong, or is it
related to my testing procedure? I am allocating memory in this
constructor, and I don't want to do this twice!
Interleaved audio processing is deprecated, or at the very least is
simply not used. Instead of one object to process interleaved stereo
data, you end up with two objects that each process non-interleaved
data for the channel in question. If you need any state to be shared
across multiple channels, such as gain in a linked stereo dynamics
processor, then you need to place those state variables in the master
object instead of in the individual channel kernel objects.
On the question of your memory allocations, if they are global for
the whole effect, then you should allocate the memory in the
AUEffectBase constructor. But if there is memory which is needed by
each channel, and particularly if these memory needs increase as the
channel count increases (think of 10.2 surround), then you should
allocate memory in the AUKernelBase constructor.
Brian Willoughby
Sound Consulting
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden