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 AudioQueueBuffer
s by some volume factor yourself to produce a volume adjustment.
精彩评论