Robbie
Robbie

Reputation: 841

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_InvalidParameter. 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

Upvotes: 2

Views: 1607

Answers (2)

user187676
user187676

Reputation:

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

Upvotes: 0

XcodeJunkie
XcodeJunkie

Reputation: 424

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

Upvotes: 2

Related Questions