Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#import "SCListener.h" // Remember to link to AudioToolbox.framework.
// Start listening.
[[SCListener sharedListener] listen];
// Retrieve the average power.
[[SCListener sharedListener] averagePower];
// Retrieve the peak power.
[[SCListener sharedListener] peakPower];
// Hmm...we're using this guy a lot...
SCListener *listener = [SCListener sharedListener];
// We can temporarily stop returning levels
[listener pause];
[listener listen]; // Quick.
// Or free up resources when we're not listening for awhile.
[listener stop];
[listener listen]; // Slower.
// Advanced!:
//
// If you're using the average and the peak, fetch both at once.
if (![listener isListening]) // If listener has paused or stopped...
return; // ...bail.
AudioQueueLevelMeterState *levels = [listener levels];
Float32 peak = levels[0].mPeakPower;
Float32 average = levels[0].mAveragePower;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment