• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: extaudiofileread stereo float (iOS)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extaudiofileread stereo float (iOS)


  • Subject: Re: extaudiofileread stereo float (iOS)
  • From: Brian Willoughby <email@hidden>
  • Date: Fri, 24 Feb 2012 17:33:45 -0800

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


  • Follow-Ups:
    • Re: extaudiofileread stereo float (iOS)
      • From: "Support (One Red Dog)" <email@hidden>
    • Re: extaudiofileread stereo float (iOS)
      • From: Michael Tyson <email@hidden>
    • Re: extaudiofileread stereo float (iOS)
      • From: Michael Tyson <email@hidden>
    • Re: extaudiofileread stereo float (iOS)
      • From: Gregory Wieber <email@hidden>
References: 
 >extaudiofileread stereo float (iOS) (From: Gregory Wieber <email@hidden>)
 >Re: extaudiofileread stereo float (iOS) (From: Michael Tyson <email@hidden>)
 >Re: extaudiofileread stereo float (iOS) (From: Gregory Wieber <email@hidden>)
 >Re: extaudiofileread stereo float (iOS) (From: Michael Tyson <email@hidden>)
 >Re: extaudiofileread stereo float (iOS) (From: Gregory Wieber <email@hidden>)

  • Prev by Date: Re: extaudiofileread stereo float (iOS)
  • Next by Date: Re: extaudiofileread stereo float (iOS)
  • Previous by thread: Re: extaudiofileread stereo float (iOS)
  • Next by thread: Re: extaudiofileread stereo float (iOS)
  • Index(es):
    • Date
    • Thread