Created
February 24, 2011 13:40
-
-
Save johnmckerrell/842162 to your computer and use it in GitHub Desktop.
Code to play a buffer of ADPCM IMA4 data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI self.audioBuffer is simply an NSMutableArray containing a buffer of up to 5 data packets.