views:

200

answers:

1

The following code used to work for me in the past. I'm trying it now with iOS4 without luck. It is working in the simulator, but I don't hear anything on the device itself. I first try to record few samples into a NSMutableData variable, and then I try to play them back.

I've tried the SpeakHere sample from Apple - which works (but it playbacks from a file - not memory).

Any idea what am I missing?

AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; 
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioSessionSetActive(true);

AudioQueueNewOutput(&m_format,&OutputCallback,self,CFRunLoopGetCurrent(), kCFRunLoopCommonModes,0,&m_device);   
AudioQueueBufferRef nBuffer=NULL;
AudioQueueAllocateBuffer(m_device,[data length],&nBuffer);
nBuffer->mAudioDataByteSize=[data length];
[data getBytes:(nBuffer->mAudioData) length:(nBuffer->mAudioDataByteSize)];
AudioQueueEnqueueBuffer(m_device,nBuffer,0,NULL);
AudioQueueStart(m_device,NULL);
A: 

The main things I can suggest are:

(1) make sure the device is not muted and the volume is up

(2) Check the result codes. For instance:

OSStatus errorCode = AudioQueueNewOutput (...) ;

if ( errorCode ) NSLog ( @"Error: %u" , errorCode ) ;

Something else that would give you a little bit more information:

While it is supposed to be running, try adjusting the volume. If it adjusts the ringer volume, the AudioQueue is not playing and/or setup correctly. If it adjusts the playback volume, than the AudioQueue is probably not getting data when it asks for it.

For the record, I have a an application that's using the AudioQueue on iOS 4 on all devices, so I know it works and it's not a bug.

Keep at it: the AudioQueue can be very, very annoying at times.

Alakazam