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 8956241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:44:46+00:00 2026-06-15T14:44:46+00:00

I am currently learning to use Audio Queue Services in iOS. For this, I

  • 0

I am currently learning to use Audio Queue Services in iOS. For this, I followed Audio Queue Services Programming Guide – Recording Audio. This works.

Now I would like to update a UI element (a power meter) when the callback function receives the input data from the microphone. This is where I run into a problem.

I am not sure what is a good way to call from the callback function into the view/view controller for updating the power meter. I tried this:
To the custom struct to manage state, which is described in the guide, I added a pointer to my view controller:

struct AQRecorderState {
    AudioStreamBasicDescription  mDataFormat;                   // 2
    AudioQueueRef                mQueue;                        // 3
    AudioQueueBufferRef          mBuffers[kNumberBuffers];      // 4
    AudioFileID                  mAudioFile;                    // 5
    UInt32                       bufferByteSize;                // 6
    SInt64                       mCurrentPacket;                // 7
    bool                         mIsRunning;                    // 8
    void*                        mViewController; // <- I've added this line
};

I initialize this pointer when I start recording. This is done in a method of the view controller, which gets called when the start button receives a TouchUp event:

- (IBAction)startAudioRecording:(id)sender {

    struct AQRecorderState* aqData = createAQRecorderState();

    void* pViewControllerAsVoidPointer = (__bridge void*) self;
    aqData->mViewController = pViewControllerAsVoidPointer;

//...

The method createAQRecorderState(), which allocates the struct, looks as follows:

struct AQRecorderState* createAQRecorderState() {
    struct AQRecorderState* pAqData = (struct AQRecorderState*) malloc(sizeof(AQRecorderState));

    initializeAQRecorderState(*pAqData); // sets members of the struct; does not set pointer to view controller

    return pAqData;
}

AFAIK, the very instance of the struct that I create when starting recording gets delivered to later calls to the callback function. For this reason, I’ve added the following code to my callback function in order to then call to the view controller:

void HandleInputBuffer(
                       void                                 *aqData,
                       AudioQueueRef                        inAQ,
                       AudioQueueBufferRef                  inBuffer,
                       const AudioTimeStamp                 *inStartTime,
                       UInt32                               inNumPackets,
                       const AudioStreamPacketDescription   *inPacketDesc
                       ) {

//...

NSLog(@"interesting part start");

void* pViewControllerAsVoidPtr = pAqData->mViewController;
NSLog(@"localized pointer to void");

ViewController* pViewController = (__bridge ViewController*) pViewControllerAsVoidPtr;  //EXC_BAD_ACCESS
NSLog(@"localized pointer to ViewController");

//...
}

However, I get a EXC_BAD_ACCESS (code=1, address=0xffffffff) in the callback function above in the marked line when I do the bridged pointer conversion. I’ve then checked this with the debugger and in fact pViewControllerAsVoidPtr does not hold the address that I stored in pAqData->mViewController during the execution of the method startAudioRecording:.

Why does that pointer get changed? Or alternatively: How to correctly call from my callback function into the view controller for updating the UI?

  • 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-15T14:44:47+00:00Added an answer on June 15, 2026 at 2:44 pm

    I found my mistake. It’s in how I do the step Creating a Recording Audio Queue. I do it exactly as copy-pasted from the guide:

    AudioQueueNewInput (                              // 1
        &aqData.mDataFormat,                          // 2
        HandleInputBuffer,                            // 3
        &aqData, //<------------------ HERE           // 4
        NULL,                                         // 5
        kCFRunLoopCommonModes,                        // 6
        0,                                            // 7
        &aqData.mQueue                                // 8
    );
    

    The problem was that in the guide, the variable aqData is a struct and therefor needs to be referenced (leading & sign) to convert it to a pointer, whereas my variable aqData already is a pointer to a struct and therefor the referencing (leading & sign) changes it to a “pointer to pointer to struct”. Hence I passed the address of the pointer instead of the address of the struct to the function AudioQueueNewInput(...), which is wrong, and of course the memory at this other location has different content.

    The compiler does not complain about this wrong type, because it expects a (void*), which can be any pointer, including (struct**), a pointer to a pointer to a struct.

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

Sidebar

Related Questions

I am currently learning the zsh and now I wanted to use strftime but
I'm currently learning ASP.NET MVC and using Nhibernate. I would like to use Cascading
As I'm currently learning to use WCF Services, I am constantly encountering tutorials on
I'm currently learning to use Core Data on iOS , in my test application
I am currently learning about these maps. Now I would like to create a
Hi I am currently learning how to use service and notifications in android and
I'm currently learning on how to use the Python optparse module. I'm trying the
i am currently learning Zend Framework 1.10 and intend to use Doctrine 2. however
I'm currently learning the C programming language (coming from Java) and I'm a bit
I'm currently learning to use MasterPages and ContentPlaceHolders in ASP.NET 3.5 and C# -

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.