I'm trying to write a microphone power meter module in a GLES app (Unity3d). It works fine in UIKit application. But when I integrate into my unity3d project, the AudioQueue cannot start property.The result code of calling AudioQueueStart is always -50, but what does -50 mean? I can't find a reference in iOS Developer Library.
I have searched about this problem and know someone has the same problem in a cocos2d application. Maybe this has some relevance.
Here is my code for Start Audio Queue:
UInt32 ioDataSize = sizeof(sampleRate);
AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate, &ioDataSize, &sampleRate); //returns noErr
format.mSampleRate = sampleRate;
format.mFormatID = kAudioFormatLinearPCM;
format.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
format.mFramesPerPacket = format.mChannelsPerFrame = 1;
format.mBitsPerChannel = 16;
format.mBytesPerPacket = format.mBytesPerFrame = 2;
AudioQueueNewInput(&format, listeningCallback, self, NULL, NULL, 0, &queue); //returns noErr
AudioQueueBufferRef buffers[3];
for (NSInteger i = 0; i < 3; ++i) {
AudioQueueAllocateBuffer(queue, 735, &buffers[i]); //returns noErr
AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL); //returns noErr
}
levels = (AudioQueueLevelMeterState *)calloc(sizeof(AudioQueueLevelMeterState), format.mChannelsPerFrame);
UInt32 trueValue = true;
AudioQueueSetProperty(queue, kAudioQueueProperty_EnableLevelMetering, &trueValue, sizeof(UInt32)); //returns noErr
AudioQueueStart(queue, NULL); //returns -50