The CDAudioManager
class
wraps the AVAudioPlayer
class. Using this class gives us access to lower level audio functions. In this recipe, we will dynamically read the average level and peak level of background music currently playing. We can use this information to sync or cue animations.
Execute the following code:
#import "SimpleAudioEngine.h" @implementation Ch6_MeteringMusic -(CCLayer*) runRecipe { //Initialize the audio engine sae = [SimpleAudioEngine sharedEngine]; //Background music is stopped on resign and resumed on becoming active [[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay autoHandle:YES]; //Set peak and average power initially peakPower = 0; avgPower = 0; //Init speaker sprites (speakerBase, speakerLarge and speakerSmall) /* CODE OMITTED */ //Init meter sprites (avgMeter and peakMeter) /* CODE OMITTED...