Skip to content

Instantly share code, notes, and snippets.

@johnmckerrell
Created February 24, 2011 13:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmckerrell/842162 to your computer and use it in GitHub Desktop.
Save johnmckerrell/842162 to your computer and use it in GitHub Desktop.
Code to play a buffer of ADPCM IMA4 data
OSStatus s;
if (!self.aq) {
AudioStreamBasicDescription asbd;
asbd.mSampleRate = 8000;
asbd.mFormatID = kAudioFormatAppleIMA4;
asbd.mFormatFlags = 0;
asbd.mBytesPerPacket = 0;
asbd.mFramesPerPacket = 0;
asbd.mBytesPerFrame = 0;
asbd.mChannelsPerFrame = 1;
asbd.mBitsPerChannel = 0;
asbd.mReserved = 0;
s = AudioQueueNewOutput(&asbd, aq_callback, NULL, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &_aq);
s = AudioQueueStart(self.aq, NULL);
}
int bufferSizeBytes = [audioData length];
// Go over each object in the audio buffer and queue it up
for (NSMutableData *audioPacket in self.audioBuffer) {
AudioQueueBufferRef aq_buffer;
s = AudioQueueAllocateBuffer(self.aq, bufferSizeBytes, &aq_buffer);
aq_buffer->mAudioDataByteSize = bufferSizeBytes;
[audioPacket getBytes:aq_buffer->mAudioData length:bufferSizeBytes];
s = AudioQueueEnqueueBuffer(self.aq, aq_buffer, 0, NULL);
}
// Then clear it out for the next run
[self.audioBuffer removeAllObjects];
@johnmckerrell
Copy link
Author

FYI self.audioBuffer is simply an NSMutableArray containing a buffer of up to 5 data packets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment