开发者

Setting the input volume on an audio queue

So I can't find anything online that says I can't do this, but whenever I try to do it on the iPhone, errors are returned from AudioQueueSetParameter. Specifically, if I try this code:

AudioQueueParameterValue val = f;
XThrowIfError(AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, val), "set queue volume");

Then I get the following error: kAudioQueueErr_InvalidP开发者_如何学编程arameter. Which Apple's documentation says it means: "The specified parameter ID is invalid".

But if I try the same exact code on an output queue, it works just fine. Does anyone have any idea why I can change the volume on output, but not input?

Thanks


According to Apple's Audio Queue Services Reference AudioQueue Parameters apply only to playback audio queues.

To retrieve information about your input stream try to use AudioQueue Properties.

// streamDescription here means your AudioStreamBasicDescription
UInt32 levelSize = sizeof(AudioQueueLevelMeterState) * streamDescription.mChannelsPerFrame;
AudioQueueLevelMeterState *level = (AudioQueueLevelMeterState*)malloc(levelSize);
if (AudioQueueGetProperty(inQueue,
                          kAudioQueueProperty_CurrentLevelMeter,
                          &levelSize,
                          &level) == noErr) {
    printf("Current peak: %f", level[0].mPeakPower);
}


I presume you could just multiply the PCM values of the AudioQueueBuffers by some volume factor yourself to produce a volume adjustment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜