Audio Yu Feng CGDD 4903
Review 1. Set up 2. IOS sound – Core Audio – Short Sound – Long Sound – Control Sound – Background Sound 3.Cocos2d sound
Set up
Core Audio High level System Sound API– short sounds AVAudioPlayer (AVFoundation)– Long sounds Lower level Audio Toolbox – recording and playback, streaming, full control Audio Units – processing audio OpenAL – 3D positional sound
Short Sounds Less than 5 seconds No looping No volume control Immediate playback Limited set of formats (wav)
Short Sound Code Two process: 1. register the sound and get a ID 2. play the sound Using AduioToolkit
Long Sound Play longer sounds (> 5 seconds) Locally stored files or in-memory Can loop, seek, play, pause Provides metering Play multiple sounds simultaneously Supports many more formats
Long Sound Code [player play];
Simple Ways to Control Audio 1. Move Forward and Backward –Use Button –Use Slider
2.Change Volume
3.Play, Pause and Reset
4.Interruption
Background Music
Add Audio in Cocos2d Audio Library: CocosDenshion Three ways to import audio: SimpleAudioEngine CDSoundEngine CDAudioManager
SimpleAudioEngine How it works: 1.Add header -- “SimpleAudioEngine.h” and “CocosDenshion.h” 2.Add sound file into support file 3.Code:
Different method playEffect: play a sound, play once handle sound effect: stopEffect playEffect preloadEffect unloadEffect playBackgroundMusic: user can set loop times (.numberOfLoops=2) handle background music: pauseBackgroundMusic resumeBackgroundMusic rewindBackgroundMusic preloadBackgroundMusic