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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:55:46+00:00 2026-06-06T23:55:46+00:00

So I am having some trouble here with my AudioUnit taking in data from

  • 0

So I am having some trouble here with my AudioUnit taking in data from microphone/line-in in iOS. I am able to set everything up to what I think is okay and it is calling my recordingCallback, but the data that I am getting out of the buffer is not correct. It always returns exactly the same thing, which is mostly zeros and random large numbers. Does anyone know what could be causing this. My code is as follows.

Setting up Audio Unit

OSStatus status;

// Describe audio component
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;

// Get component
AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
status = AudioComponentInstanceNew(inputComponent, &audioUnit);

// Enable IO for recording
UInt32 flag = 1;
status = AudioUnitSetProperty(audioUnit, 
                              kAudioOutputUnitProperty_EnableIO, 
                              kAudioUnitScope_Input, 
                              kInputBusNumber,
                              &flag, 
                              sizeof(flag));
// Disable playback IO
flag = 0;
status = AudioUnitSetProperty(audioUnit, 
                              kAudioOutputUnitProperty_EnableIO, 
                              kAudioUnitScope_Output, 
                              kOutputBusNumber,
                              &flag, 
                              sizeof(flag));

// Describe format
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate         = 44100.00;
audioFormat.mFormatID           = kAudioFormatLinearPCM;
audioFormat.mFormatFlags        = kAudioFormatFlagsNativeFloatPacked |kAudioFormatFlagIsNonInterleaved;
audioFormat.mFramesPerPacket    = 1;
audioFormat.mChannelsPerFrame   = 1;
audioFormat.mBitsPerChannel     = 32;
audioFormat.mBytesPerPacket     = 4;
audioFormat.mBytesPerFrame      = 4;

// Apply format
status = AudioUnitSetProperty(audioUnit, 
                              kAudioUnitProperty_StreamFormat, 
                              kAudioUnitScope_Output, 
                              kInputBusNumber, 
                              &audioFormat, 
                              sizeof(audioFormat));

// Set input callback
AURenderCallbackStruct callbackStruct;
callbackStruct.inputProc = recordingCallback;
callbackStruct.inputProcRefCon = (__bridge void*)self;
status = AudioUnitSetProperty(audioUnit, 
                              kAudioOutputUnitProperty_SetInputCallback, 
                              kAudioUnitScope_Global, 
                              kInputBusNumber, 
                              &callbackStruct, 
                              sizeof(callbackStruct));
status = AudioUnitInitialize(audioUnit);

Input Callback

static OSStatus recordingCallback(void *inRefCon, 
                                  AudioUnitRenderActionFlags *ioActionFlags, 
                                  const AudioTimeStamp *inTimeStamp, 
                                  UInt32 inBusNumber, 
                                  UInt32 inNumberFrames, 
                                  AudioBufferList *ioData) {

    AudioBufferList bufferList;
    bufferList.mNumberBuffers = 1;
    bufferList.mBuffers[0].mDataByteSize = 4;
    bufferList.mBuffers[0].mNumberChannels = 1;
    bufferList.mBuffers[0].mData = malloc(sizeof(float)*inNumberFrames); //
    InputAudio *input = (__bridge InputAudio*)inRefCon;

    OSStatus status;

    status = AudioUnitRender([input audioUnit], 
                             ioActionFlags, 
                             inTimeStamp, 
                             inBusNumber, 
                             inNumberFrames, 
                             &bufferList);

    float* result = (float*)&bufferList.mBuffers[0].mData;

    if (input->counter == 5) {
        for (int i = 0;i<inNumberFrames;i++) {
            printf("%f ",result[i]);
        }
    }
    input->counter++;
    return noErr;
}

Anyone ever encounter a similar problem or see something clearly wrong in my code. Thanks in advance for any help!

I am basing all of it off of Michael Tysons Core Audio RemoteIO code

  • 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-06T23:55:47+00:00Added an answer on June 6, 2026 at 11:55 pm

    If I remember correctly, the samples you get from the audio buffer in the callback aren’t floats, they’re SInt16. Try casting the samples like this:

    SInt16 *sn16AudioData= (SInt16 *)(bufferList.mBuffers[0].mData);
    

    And these should be the max and min values:

    #define sn16_MAX_SAMPLE_VALUE 32767
    #define sn16_MIN_SAMPLE_VALUE -32768
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble in filtering objects from a set of models. Here is
Hey, I'm having some trouble here... How can I delete an entire text from
I'm having some trouble getting the text field from the page found here: Here
I am having some trouble here, my json data is outputting as follows: {date:[{day_w:Tuesday,day_n:28,month:Dec}],subscriptions:[{subscribe:example1},{subscribe:example2},{subscribe:example3}]}
I'm having some trouble aligning buttons and small images from a jscript source... Here's
I am having some real trouble around here giving command line arguments to Visual
I am having some trouble with really quite simple collision detection. Here is my
I am having some trouble with writing classes in Arduino. Here is a class
I'm having some trouble with the jQuery hover method. Here's the relevant JavaScript code:
I'm having some trouble floating images properly alongside text in a contenteditable div. Here's

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.