• 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: Sat, 25 Feb 2012 21:15:48 -0800

Your stack example still calls malloc() for the mData, so what is the advantage of the fragile code?

Coincidentally, I am porting some CoreMIDI code that I started writing way back in 2001 and 2002, and I had to remove various pack attributes to get it to compile with the more modern Xcode. Perhaps there is some obscure compiler option that I forgot to translate, but I rarely write code that is so dependent upon things that change from release to release. Thus, I still recommend that you stay far away from __attribute__((packed)) unless there is no other possible solution.

In this case, one additional malloc() when you're already using malloc () seems like no contest.

Brian Willoughby
Sound Consulting

p.s. as for gdb, the "po" command is nice for objects, but the "x" command can do what NSData is doing much faster and with more configurability. Try "x/200 array"


On Feb 25, 2012, at 03:01, Michael Tyson wrote:
Whoops - you're totally right, Brian! Thanks for pointing that out - I forgot to add the 'packed' attribute to the anonymous struct in that code, which, unless I'm mistaken, should resolve the problem by ensuring the two structures are packed together - but you're probably right; it's less error-prone to do it on the heap (just a little more work, in certain circumstances where you need to avoid allocating memory, because you then need to allocate it in advance).

Sorry for the misleading code snippet =)

So, unless I'm mistaken about this working (please correct me if I am!), it should've been:

struct { AudioBufferList bufferList; AudioBuffer secondBuffer; } __attribute__((packed)) 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));
}

Or, on the heap:

AudioBufferList *bufferList = (AudioBufferList*)malloc(sizeof (AudioBufferList) + sizeof(AudioBuffer));
bufferList->mNumberBuffers = 2;
for ( int i=0; i<bufferList->mNumberBuffers; i++ ) {
  bufferList->mBuffers[i].mNumberOfChannels = 1;
  bufferList->mBuffers[i].mDataByteSize = kBufferSize * sizeof(float);
  bufferList->mBuffers[i].mData = malloc(kBufferSize * sizeof(float));
}

...
free(bufferList);


Cheers =)
Michael


_______________________________________________
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: Michael Tyson <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>)
 >Re: extaudiofileread stereo float (iOS) (From: Brian Willoughby <email@hidden>)
 >Re: extaudiofileread stereo float (iOS) (From: Michael Tyson <email@hidden>)

  • Prev by Date: Re: Sound stops playing when I plug in the headphones
  • 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