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

  • Home
  • SEARCH
  • 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 5985079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:28:34+00:00 2026-05-22T22:28:34+00:00

I am Using AUdioQueue to record the audio from built-in mic and send it

  • 0

I am Using AUdioQueue to record the audio from built-in mic and send it over socket, I have set the AudioQueue buffer to record buffer of say 30 sec in once shot and allocating bufferSize appropriately,
This is the function i am using to set the AudioDataFormat.

AudioStreamBasicDescription sRecordFormat;
 FillOutASBDForLPCM (sRecordFormat,
                    16000,
                    1,
                    16,
                    16,
                    false,
                    false
                    );

Following Code calculate the bufferSize that needs to be allocated to capture the audio,

int AQRecorder::ComputeRecordBufferSize(const AudioStreamBasicDescription *format, float seconds)
{
    int packets, frames, bytes = 0;
    try {
        frames = (int)ceil(seconds * format->mSampleRate);

        if (format->mBytesPerFrame > 0)
            bytes = frames * format->mBytesPerFrame;
        else {
            UInt32 maxPacketSize;
            if (format->mBytesPerPacket > 0)
                maxPacketSize = format->mBytesPerPacket;    // constant packet size
            else {
                UInt32 propertySize = sizeof(maxPacketSize);
                XThrowIfError(AudioQueueGetProperty(mQueue, kAudioQueueProperty_MaximumOutputPacketSize, &maxPacketSize,
                                                 &propertySize), "couldn't get queue's maximum output packet size");
            }
            if (format->mFramesPerPacket > 0)
                packets = frames / format->mFramesPerPacket;
            else
                packets = frames;   // worst-case scenario: 1 frame in a packet
            if (packets == 0)       // sanity check
                packets = 1;
            bytes = packets * maxPacketSize;
        }
    } catch (CAXException e) {
        char buf[256];
        gLog<<[[NSString stringWithFormat:@"Error:%s (%s)\n",e.mOperation,e.FormatError(buf)] UTF8String]<<endl;
        return 0;
    }   
    return bytes;
}

Following code Sample to allocate the buffer,

    // allocate and enqueue buffers
    bufferByteSize = ComputeRecordBufferSize(&mRecordFormat, kBufferDurationSeconds);   // enough bytes for 20 ms
    for (i = 0; i < kNumberRecordBuffers; ++i) {
        XThrowIfError(AudioQueueAllocateBuffer(mQueue, bufferByteSize, &mBuffers[i]),
                   "AudioQueueAllocateBuffer failed");
        XThrowIfError(AudioQueueEnqueueBuffer(mQueue, mBuffers[i], 0, NULL),
                   "AudioQueueEnqueueBuffer failed");
    }

Yes, you guessed it right, most of the code referred from SpeakHere example,
When it comes to AudioCallback, i need to Capture the buffer and send it to other machine over socket,

// ____________________________________________________________________________________
// AudioQueue callback function, called when an input buffers has been filled.
void AQRecorder::MyInputBufferHandler(  void *                              inUserData,
                                        AudioQueueRef                       inAQ,
                                        AudioQueueBufferRef                 inBuffer,
                                        const AudioTimeStamp *              inStartTime,
                                        UInt32                              inNumPackets,
                                        const AudioStreamPacketDescription* inPacketDesc)
{
    AQRecorder *aqr = (AQRecorder *)inUserData;
    try {
           NSLog([NSString stringWithFormat:"Inside AudioBufferCallback no of packet [%d]",inMumPackets]);
        if (inNumPackets > 0) {
            // write packets to file 
                    // This is only for the test 
            XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize,
                                              inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData),
                       "AudioFileWritePackets failed");
            aqr->mRecordPacket += inNumPackets;

            if(aqr->pInputListener){
                aqr->pInputListener(aqr->pClientUserData,inBuffer->mAudioData,(int)inBuffer->mAudioDataByteSize);
            }
        }

        // if we're not stopping, re-enqueue the buffe so that it gets filled again
        if (aqr->IsRunning())
            XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed");
    } 
}

Now when i see the log, data are coming but it says no of packets are 256, 320 like that, when i pass the data at the other end, its not audible, Can anyone tell me, what do i need to do WIth the packetSize, i was under impression to bufferSize is enough to send the data but i guess, something has got to do with the Number of Packet also.

  • 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-05-22T22:28:35+00:00Added an answer on May 22, 2026 at 10:28 pm

    Some problem in buffer management,
    This application needs to send data in 20 ms +- 5 ms possible, in my case, this particular case was not handled.

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

Sidebar

Related Questions

I am using AudioQueue to stream audio from an arbitrary source (the class basically
I am using the Audio Queue services to record audio on the iPhone. I
I am currently using Audio Queues on the iPhone to record and playback audio.
I have written a voice streaming application in iPhone using AudioQue. At the audio
Does anybody know of any examples using AudioQueue that play from an in-memory source?
In my app, i would be receiving audio data over socket in Linear PCM
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using JDeveloper , I started developing a set of web pages for a project
I am using AudioQueue for recording voice. I want to know how can we

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.