Sunday, July 15, 2012

iOS: AudioQueue Get Audio Level

A very good example of this is found in the "SpeakHere" reference project provided by Apple:
Link: http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html

Just some gotcha's and points to note:

You need to call AudioQueueSetProperty to enable the level metering feature in the first place:
UInt32 enableMetering = 1;
AudioQueueSetProperty(audioQueue, kAudioQueueProperty_EnableLevelMetering, &enableMetering, sizeof(UInt32));

The number returned by the AudioQueue will be a negative number with a maximum value of 0. To convert it to a number on a linear scale (i.e. gain level), use the following formula:
float level = pow(10., 0.05 * averagePower);

Where averagePower is the value returned by the AudioQueue for the audio level average power.

The rest should be pretty straight-forward from studying the example.

Links and References:

No comments:

Post a Comment