gpt4 book ai didi

ios - 音频队列 : AudioQueueStart returns -50

转载 作者:可可西里 更新时间:2023-11-01 06:11:20 27 4
gpt4 key购买 nike

我正在尝试在 GLES 应用程序 (Unity3d) 中编写麦克风功率计模块。它在 UIKit 应用程序中运行良好。但是当我集成到我的unity3d项目中时,AudioQueue无法启动属性。调用AudioQueueStart的结果代码总是-50,但-50是什么意思?我在 iOS Developer Library 中找不到引用。

我搜索过这个问题,知道有人在 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

最佳答案

以下对我有用:

添加这个:

AVAudioSession * session = [AVAudioSession sharedInstance];

if (!session) printf("ERROR INITIALIZING AUDIO SESSION! \n");
else{


[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&nsError];

if (nsError) printf("couldn't set audio category!");



[session setActive:YES error:&nsError];
if (nsError) printf("AudioSession setActive = YES failed");
}

AudioQueueStart(myQueue, NULL); 之前

关于ios - 音频队列 : AudioQueueStart returns -50,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12650263/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com