AudioQueue音量太低 [英] AudioQueue volume too low
本文介绍了AudioQueue音量太低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用AudioQueue播放PCM数据时出现问题.使用iPhone的扬声器时音量太低;我什至把系统音量调到最大.但是,当我使用耳机时,音量还是可以的.
I am having a problem when using AudioQueue to play PCM data. The volume is low when using the iPhone's speaker; 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++;
}
我已将音量设置如下:
AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0);
推荐答案
对于仍然存在此问题的用户,甚至在SpeakHere示例代码中也是如此.在所有其他解决方案中,该解决方案对我来说效果很好:
For those still having this issue which is even on SpeakHere sample code. This solution worked well for me out of all the other ones :
//ViewController.m
#import "ViewController.h"
@interface ViewController ()
{ AVAudioSession *session; }
- (void)viewDidLoad {
[super viewDidLoad];
//This ensures it plays properly on speaker output
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker
error:nil];
}
这篇关于AudioQueue音量太低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文