简体   繁体   English

使用AudioQueue播放PCM音频流时音量较低

[英]Using AudioQueue to play PCM audio stream have low volume

I am having a problem when using AudioQueue to play PCM data. 使用AudioQueue播放PCM数据时出现问题。 The volume is low when using the iPhone's speaker; 使用iPhone的扬声器时音量太低; I have even turned the system volume up to maximum. 我什至将系统音量调到最大。 However, the volume is fine when I am using the earphones. 但是,使用耳机时音量很好。

I inserted the data into the queue like this: 我将数据插入队列中,如下所示:

memcpy(mBuffers[mIndex]->mAudioData, pcmData, mBufferByteSize);
mBuffers[mIndex]->mAudioDataByteSize = mBufferByteSize;
mBuffers[mIndex]->mPacketDescriptionCount = mBufferByteSize/2;
OSStatus status = AudioQueueEnqueueBuffer(mQueue, mBuffers[mIndex], 0, NULL);
NSLog(@"fill audio queue buffer[%d]",mIndex);
if(mIndex == kNumberBuffers - 1) {
    isStartPlay = YES;
    mIndex = 0;
    AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0);
    status = AudioQueueStart(mQueue, NULL);
}else {
    mIndex++;
}

I have set the volume like this: 我将音量设置为:

AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0);

Are you using the AVAudioSessionCategoryPlayAndRecord audio session category? 您是否正在使用AVAudioSessionCategoryPlayAndRecord音频会话类别? If so, then you're probably playing back through the receiver, which is very quiet. 如果是这样,那么您可能正在通过接收器进行播放,这非常安静。

This bizarre default behaviour harks back to the days when play-and-record category was imagined to be useful mainly for VOIP apps, which, even more strangely, were banned from the AppStore. 这种奇怪的默认行为可以追溯到人们认为播放和录制类别主要对VOIP应用有用的时代,更奇怪的是,VOIP应用被AppStore禁止了。

To override playback through the normal speaker, try adding AVAudioSessionCategoryOptionDefaultToSpeaker to your category options: 要通过普通扬声器覆盖播放,请尝试将AVAudioSessionCategoryOptionDefaultToSpeaker添加到类别选项:

[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM