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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:37:54+00:00 2026-05-12T21:37:54+00:00

As a throwaway project for the iPhone to get me up to speed with

  • 0

As a throwaway project for the iPhone to get me up to speed with Objective C and the iPhone libraries, I’ve been trying to create an app that will play different kinds of random noise.

I’ve been constructing the noise as an array of floats normalized from [-1,1].

Where I’m stuck is in playing that generated data. It seems like this should be fairly simple, but I’ve looked into using AudioUnit and AVAudioPlayer, and neither of these seem optimal.

AudioUnit requires apparently a few hundred lines of code to do even this simple task, and AVAudioPlayer seems to require me to convert the audio into something CoreAudio can understand (as best I can tell, that means LPCM put into a WAV file).

Am I overlooking something, or are these really the best ways to play some sound data stored in array form?

  • 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-12T21:37:54+00:00Added an answer on May 12, 2026 at 9:37 pm

    Here’s some code to use AudioQueue, which I’ve modified from the SpeakHere example. I kind of pasted the good parts, so there may be something dangling here or there, but this should be a good start if you want to use this approach:

    AudioStreamBasicDescription format;
    memset(&format, 0, sizeof(format));
    format.mSampleRate = 44100;
    format.mFormatID = kAudioFormatLinearPCM;
    format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
    format.mChannelsPerFrame = 1;
    format.mBitsPerChannel = 16;
    format.mBytesPerFrame = (format.mBitsPerChannel / 8) * format.mChannelsPerFrame;
    format.mFramesPerPacket = 1;
    format.mBytesPerPacket = format.mBytesPerFrame * format.mFramesPerPacket;
    
    AudioQueueRef queue;
    
    AudioQueueNewOutput(&format, 
                AQPlayer::AQOutputCallback, 
                this,  // opaque reference to whatever you like
                CFRunLoopGetCurrent(), 
                kCFRunLoopCommonModes, 
                0, 
                &queue); 
    
    const int bufferSize = 0xA000;  // 48K - around 1/2 sec of 44kHz 16 bit mono PCM        
    for (int i = 0; i < kNumberBuffers; ++i)
        AudioQueueAllocateBufferWithPacketDescriptions(queue, bufferSize, 0, &mBuffers[i]);
    
    AudioQueueSetParameter(queue, kAudioQueueParam_Volume, 1.0);
    
    UInt32 category = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
    
    AudioSessionSetActive(true);
    
    // prime the queue with some data before starting
    for (int i = 0; i < kNumberBuffers; ++i)
        OutputCallback(queue, mBuffers[i]);
    
    AudioQueueStart(queue, NULL);
    

    The code above refers to this output callback. Each time this callback executes, fill the buffer passed in with your generated audio. Here, I’m filling it with random noise.

    void OutputCallback(void* inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer) {
        // Fill 
        //AQPlayer* that = (AQPlayer*) inUserData;
        inCompleteAQBuffer->mAudioDataByteSize = next->mAudioDataBytesCapacity; 
        for (int i = 0; i < inCompleteAQBuffer->mAudioDataByteSize; ++i)
            next->mAudioData[i] = rand();
        AudioQueueEnqueueBuffer(queue, inCompleteAQBuffer, 0, NULL);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project that's been accepted as a proof of concept and
I have been refactoring throwaway code which I wrote some years ago in a
I've got a project in a git repository that uses some custom (and so
I wanted to create a throwaway struct object to keep various status flags. My
Recently, I've heard a number of different people lamenting the speed differences in IE
I am trying to developing p a JRPG/dungeon crawler as a summer project and
Using Rebol/View 2.7.7, I'm trying to create a card game based on Nick's Rebol
I frequently write throwaway code (in a research environment ) - for example to
I need to develop a basic web app very quickly (1 week) for a
Like most people new to Git, I've had my share of confusion trying to

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.