簡體   English   中英

AudioQueue 音量太低

[英]AudioQueue volume too low

我在使用 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);

對於那些仍然有這個問題的人,甚至在 SpeakHere 示例代碼中。 在所有其他解決方案中,這個解決方案對我來說效果很好:

//視圖控制器.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];

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM