Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:41:50+00:00 2026-06-11T19:41:50+00:00

In iOS core audio there is the API AudioFileWritePackets that has a inPacketDescriptions parameter

  • 0

In iOS core audio there is the API AudioFileWritePackets that has a inPacketDescriptions parameter defined as
‘A pointer to an array of packet descriptions for the audio data.’

and it looks like this in the method signature:
const AudioStreamPacketDescription *inPacketDescriptions,

now the struct AudioStreamPacketDescription is defined as follows:

struct  AudioStreamPacketDescription
{
    SInt64  mStartOffset;
    UInt32  mVariableFramesInPacket;
    UInt32  mDataByteSize;
};
typedef struct AudioStreamPacketDescription AudioStreamPacketDescription;

I would like to know how to create and populate such a ‘pointer to an array of structs’, or even once given the variable, how to read it. Using the speakHere example from apple I put a breakpoint where I receive the variable and tried to dump all its contents to the log.. this is an example of an attempt:

void AQRecorder::printPacketDescriptionContents(const AudioStreamPacketDescription * inPacketDescriptions, UInt32 inNumberPackets)
{
    for (int i = 0; i < inNumberPackets; ++i)
    {
        NSLog(@"\n----------------\n");
        NSLog(@"this is packetDescriptionArray[%d].mStartOffset: %lld", i, (*inPacketDescriptions).mStartOffset);
        NSLog(@"this is packetDescriptionArray[%d].mVariableFramesInPacket: %lu", i, (*inPacketDescriptions).mVariableFramesInPacket);
        NSLog(@"this is packetDescriptionArray[%d].mDataByteSize: %lu", i, (*inPacketDescriptions).mDataByteSize);
        NSLog(@"\n----------------\n");   

    }        
}

any ideas?

Update: here is a sample log of me trying to mess around with it.. maybe it can help in the answer (notice at the bottom it keeps on appearing null.. it doesn’t make sense that the whole thing is just a pack of zeroes since it’s a variable returned by a callback that should be properly populated, also notice that it informs me about the number of packets I got back..).. also if i run the code with ((const AudioStreamPacketDescription *)(inPacketDescriptions +i))->mDataByteSize) i get a EXC_BAD_ACCESS error

(lldb) po **(inPacketDescriptions)
error: indirection requires pointer operand ('const AudioStreamPacketDescription' invalid)
error: 1 errors parsing expression
(lldb) po *(inPacketDescriptions)
(AudioStreamPacketDescription) $1 = [no Objective-C description available]
(lldb) po *(inPacketDescriptions).mStartOffset
error: member reference type 'const AudioStreamPacketDescription *' is a pointer; maybe you meant to use '->'?
error: indirection requires pointer operand ('SInt64' (aka 'long long') invalid)
error: 2 errors parsing expression
(lldb) po (*inPacketDescriptions).mStartOffset
(SInt64) $2 = 0 <nil>

(lldb) po (const AudioStreamPacketDescription *)(inPacketDescriptions +1)
(const class AudioStreamPacketDescription *) $3 = 0x00000010 [no Objective-C description available]
(lldb) po (const AudioStreamPacketDescription *)(inPacketDescriptions +1)->mStartOffset
error: Execution was interrupted, reason: Attempted to dereference an invalid pointer..
The process has been returned to the state before execution.
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +1))->mStartOffset
(SInt64) $5 = 0 <nil>
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +1))->mDataByteSize
(UInt32) $6 = 0 <nil>
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +100))->mDataByteSize
(UInt32) $7 = 0 <nil>
(lldb) po ((const AudioStreamPacketDescription *)(inPacketDescriptions +500))->mDataByteSize
(UInt32) $8 = 0 <nil>

(lldb) po inPacketDescriptions[0].mStartOffset
error: parent failed to evaluate: parent is NULL
(lldb) 

also here is what it looks like in the XCode inspector:enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:41:51+00:00Added an answer on June 11, 2026 at 7:41 pm

    I can’t remember an instance where this specific struct is ever populated by you, the client. You will need to create storage for these structs which you then pass across multiple calls in order to successfully deal with reading and writing audio data. Several non-PCM formats will need this information, depending on how the audio data has been stored.

    I would like to know how to create and populate such a ‘pointer to an array of structs’, or even once given the variable, how to read it.

    Well, there are a handful of APIs in AudioFile I/O and AudioConvertor interfaces which use this structure. Basically, you don’t populate this type yourself. The basic flow goes like this:

    // this is not for PCM audio data
    //
    // we'll read up to 8 packets at a time:
    const size_t MaxPacketsToRead(8);
    
    // allocate MaxPacketsToRead ASPDs on the stack:
    AudioStreamPacketDescription aspds[MaxPacketsToRead];
    
    // audio file read function:
    AudioFileID inAudioFile = ...;
    Boolean inUseCache = ...;
    UInt32 outNumBytes = ...;
    AudioStreamPacketDescription* outPacketDescriptions(aspds);
    SInt64 inStartingPacket = ...;
    UInt32 ioNumPackets = MaxPacketsToRead; // << you may not get all the packets
                                            // you request, but this sets the
                                            // upper limit.
    void* outBuffer = ...;
    
    
    OSStatus result(AudioFileReadPackets(inAudioFile,
                                         inUseCache,
                                         &outNumBytes,
                                         outPacketDescriptions,
                                         inStartingPacket,
                                         &ioNumPackets,
                                         outBuffer
    ));
    
    if (noErr != result) {
      ...uh-oh...
    }
    
    // *now* we know that we have ioNumPackets worth of valid ASPDs,
    // populated by the reader. and we have the associated audio data
    // in other parameters.
    // we can now safely pass all this information off to a function which 
    // reads the ASPDs, such as AudioFileWritePackets.
    

    (knowing the OP’s problem in some more detail) In many cases, you can avoid all this complexity and simply create an ExtAudioFile representation, and the specify kExtAudioFileProperty_ClientDataFormat for your destination sample format — then the ExtAudioFile APIs will create an internal convertor on your behalf which will convert the input of an audio file of an arbitrary type to some specified PCM representation which you can use for the playback sample data. Implementing all this at this level is actually quite complex if you want to support many file formats. ExtAudioFile makes converting the sample data very easy — if that is an option and if it plays nicely with your streaming scenario.

    As far as the logging, well you’re attempting to print the fields of a NULL structure, from the looks of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's a so called Core Audio SDK which Apple says is for Mac OS
I have been working on a Core Data iOS app that works perfectly through
What are the change in the iOS API for Core Data between iOS 4.3
A quick curiosity. If I develop an application with ios 5(e.g core audio kAudioUnitSubType_AudioFilePlayer)
I have a core data entity A that has a one-to-many relationship with entity
I have built an iOS app that leverages Core Location Framework. I have Xcode
I'm poking around the ios documentation at the moment in the core audio section.
I write an Desktop/iOS Game with OpenGL and want to play audio files (mp3
I am creating an iOS 5 app using Core Data. I have two entities
I'm following the example Navigation View template with core data in the latest iOS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.