Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Figured it out. Here's a simple, complete and <em>working</em> white noise generator using AudioQueue created from the Window-based Application project template.</p> <p><strong>StaticAppDelegate.h:</strong></p> <pre><code>// StaticAppDelegate.h #import &lt;UIKit/UIKit.h&gt; // STATIC ADDITIONS // Add &gt; Existing Frameworks... &gt; AudioToolbox.framework to your Target #import &lt;AudioToolbox/AudioToolbox.h&gt; // END STATIC ADDITIONS @interface StaticAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow *window; // STATIC ADDITIONS - (void)startStatic; - (void)handleBufferCompleteForQueue:(AudioQueueRef)inAQ buffer:(AudioQueueBufferRef)inBuffer; // END STATIC ADDITIONS @end </code></pre> <p><strong>StaticAppDelegate.m:</strong></p> <pre><code>// StaticAppDelegate.m #import "StaticAppDelegate.h" // STATIC ADDITIONS #define kNumberBuffers 4 #define kBufferSize 2048 // AudioQueue callback void AQOutputCallback( void *inData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer ) { StaticAppDelegate *staticApp = (StaticAppDelegate *)inData; [staticApp handleBufferCompleteForQueue:inAQ buffer:inBuffer]; } // END STATIC ADDITIONS @implementation StaticAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; // STATIC ADDITIONS [self startStatic]; // END STATIC ADDITIONS } - (void)dealloc { [window release]; [super dealloc]; } // STATIC ADDITIONS - (void)startStatic { srandom(time(NULL)); // initiate audio session AudioSessionInitialize(NULL, NULL, NULL, NULL); UInt32 category = kAudioSessionCategory_MediaPlayback; // plays through sleep lock and silent switch AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &amp;category); AudioSessionSetActive(true); // following is modified from http://stackoverflow.com/questions/1710133/playing-generated-audio-on-an-iphone // setup queue AudioQueueRef audioQueue; AudioQueueBufferRef buffers[kNumberBuffers]; AudioStreamBasicDescription format; memset(&amp;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; AudioQueueNewOutput(&amp;format, AQOutputCallback, self, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &amp;audioQueue); // allocate and fill the buffers for (int i = 0; i &lt; kNumberBuffers; ++i) { AudioQueueAllocateBuffer(audioQueue, kBufferSize, &amp;buffers[i]); AQOutputCallback(self, audioQueue, buffers[i]); } AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, 1.0); AudioQueueStart(audioQueue, NULL); } - (void)handleBufferCompleteForQueue:(AudioQueueRef)inAQ buffer:(AudioQueueBufferRef)inBuffer { inBuffer-&gt;mAudioDataByteSize = inBuffer-&gt;mAudioDataBytesCapacity; int *buffer = (int *)inBuffer-&gt;mAudioData; for (int i = 0; i &lt; inBuffer-&gt;mAudioDataByteSize/sizeof(int); ++i) { buffer[i] = (int)rand(); // refill the buffer } AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL); } // END STATIC ADDITIONS @end </code></pre> <p>Once I figured out how to actually refill the buffer (<code>inBuffer-&gt;mAudioData</code> with some type casting) everything else fell into place.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload