Re: ExtAudioFileRead: how to create AudioBufferList
Re: ExtAudioFileRead: how to create AudioBufferList
- Subject: Re: ExtAudioFileRead: how to create AudioBufferList
- From: William Stewart <email@hidden>
- Date: Mon, 20 Nov 2006 12:06:00 -0800
On 20/11/2006, at 11:48 AM, David Duncan wrote:
On Nov 20, 2006, at 11:26 AM, William Stewart wrote:
The idiom is a common one for allocating variable length arrays.
This can be done easily with malloc() and other byte-oriented
allocators like this:
mInputBuffer = (AudioBufferList*)malloc(sizeof(AudioBufferList) +
(numBuffers-1) * sizeof(AudioBuffer));
This is not quite correct and won't work correctly for 64 bit. The
correct way is to use the offsetof operator:
mBufferList = reinterpret_cast<AudioBufferList*>(new Byte[offsetof
(AudioBufferList, mBuffers) + (mNumberBuffers * sizeof
(AudioBuffer))]);
I'm interested in why the my code isn't compatible with 64-bit,
mostly for my own education, but also because it's just extending a
pre-existing array by the number of additional buffers needed.
Actually - my mistake.
The code we currently have in Tiger was doing this:
mBufferList = reinterpret_cast<AudioBufferList*>(new Byte[sizeof
(UInt32) + (mNumberBuffers * sizeof(AudioBuffer))]);
However, due to different padding with LP_64 this was leading to an
incorrect (too small) allocation. The code we settled on for handling
ABL sizes is the code I posted above - so that's what you will see in
the Leopard SDK code.
Bill
--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who
try.
David Duncan
--
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
________________________________________________________________________
__
_______________________________________________
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