我正在尝试在 GLES 应用程序(Unity3d)中编写麦克风功率计模块。它在 UIKit 应用程序中运行良好。但是当我集成到我的unity3d项目中时,AudioQueue无法启动属性。调用AudioQueueStart的结果代码总是-50,但是-50是什么意思呢?我在 iOS 开发人员库中找不到参考。
我已经搜索过这个问题,并且知道有人在 cocos2d 应用程序中遇到了同样的问题。也许这有一些相关性。
这是我的启动音频队列代码:
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