【问题标题】:AudioQueue volume too lowAudioQueue 音量太低
【发布时间】:2015-09-16 03:39:18
【问题描述】:

我在使用 AudioQueue 播放 PCM 数据时遇到问题。使用 iPhone 的扬声器时音量偏低;我什至把系统音量调到最大。但是,我使用耳机时音量很好。

我像这样将数据插入到队列中:

    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);

【问题讨论】:

  • 你检查AudioQueueSetParameter的结果了吗?确保它成功。
  • 我打印了AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0),结果为0,是不是设置参数失败? @KudoCC
  • 不,0 表示noErr

标签: ios objective-c audioqueue


【解决方案1】:

对于那些仍然有这个问题的人,甚至在 SpeakHere 示例代码中。在所有其他解决方案中,这个解决方案对我来说效果很好:

//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];

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    相关资源
    最近更新 更多