Skip to content

Instantly share code, notes, and snippets.

@stephencelis
Created March 2, 2009 18:52
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save stephencelis/72914 to your computer and use it in GitHub Desktop.
Save stephencelis/72914 to your computer and use it in GitHub Desktop.
#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