Re: extaudiofileread stereo float (iOS)
Re: extaudiofileread stereo float (iOS)
- Subject: Re: extaudiofileread stereo float (iOS)
- From: "Support (One Red Dog)" <email@hidden>
- Date: Sun, 26 Feb 2012 17:03:25 +1100
Or even alloca() or #pragma pack(1) for MSVC compatibility
With alloca() you are guaranteed to get local stack allocation rather than any register allocation the optimiser may or may not do. But depending on your process or threads stack size, it's safer to place large buffers on the heap. A heap allocation is also more likely to guarantee word alignment. OS X and it's sibling iOS does word aligned heap allocations as opposed to requiring something like mm_malloc.
peter johnson
one red dog media
On 25/02/2012, at 12:33 PM, Brian Willoughby wrote:
> Michael,
>
> I hate to sound rude, but that is awful code. Declaring a pair of variables as separate fields in a structure on the stack and then depending upon the compiler to make them concatenated into a single array is very bad code. The behavior is very dependent upon the alignment and packing settings at compile time. It might work for you now, but any number of architecture changes or compiler revisions could cause your fragile construct to fail without warning. Note that if the C Language standard guarantees that separate variables declared in proximity on the stack are guaranteed to work like you're using them, then please point to the specification because it would be news to me.
>
> The proper way to handle variable length arrays is to work with pointers and allocated contiguous memory with a call to malloc() or calloc().
>
>
> Greg,
>
> Don't forget that the Xcode debugger (gdb) has a command line. You can examine variable-length arrays by simply typing in a display command with the appropriate index. I run into so many examples where the Xcode variable browser does not access the information that I need, that I frequently just use the debugger's command line to access the data by basically typing the C code.
>
> Brian Willoughby
> Sound Consulting
>
>
> On Feb 23, 2012, at 20:25, Gregory Wieber wrote:
>> I'm not entirely hazy on the variable length array concept, but I'm wondering (and this is more a general C thing, so I should post elsewhere) how to debug a variable length array. Because, as far as the debugger is concerned it is still an array of length 1; even though clearly the two buffers have been allocated. It just makes it hard for me to peak under the hood and solve the problem. When I simply print the values in the buffers, they're identical for left and right.
>
>
>
> On Thu, Feb 23, 2012 at 12:04 PM, Michael Tyson <email@hidden> wrote:
>> It can be a little confusing, because the AudioBufferList structure defines only a single AudioBuffer within it - you have to either allocate space for the buffer list + the extra buffer, or use a struct or something on the stack.
>>
>> For example, to prepare an AudioBufferList on the stack, to receive kBufferSize floating-point, stereo, non-interleaved samples:
>>
>> struct { AudioBufferList bufferList; AudioBuffer secondBuffer; } buffers;
>> buffers.bufferList.mNumberBuffers = 2;
>> for ( int i=0; i<buffers.bufferList.mNumberBuffers; i++ ) {
>> buffers.bufferList.mBuffers[i].mNumberOfChannels = 1;
>> buffers.bufferList.mBuffers[i].mDataByteSize = kBufferSize * sizeof(float);
>> buffers.bufferList.mBuffers[i].mData = malloc(kBufferSize * sizeof(float));
>> }
>
>
> _______________________________________________
> 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
_______________________________________________
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