Created
March 2, 2009 18:52
-
-
Save stephencelis/72914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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