cocos2d for iPhone 1.0.0
2D engine for iOS and OS X
/Users/rquesada/progs/cocos2d-iphone/CocosDenshion/CocosDenshion/CDAudioManager.h
00001 /*
00002  Copyright (c) 2010 Steve Oldmeadow
00003  
00004  Permission is hereby granted, free of charge, to any person obtaining a copy
00005  of this software and associated documentation files (the "Software"), to deal
00006  in the Software without restriction, including without limitation the rights
00007  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  copies of the Software, and to permit persons to whom the Software is
00009  furnished to do so, subject to the following conditions:
00010  
00011  The above copyright notice and this permission notice shall be included in
00012  all copies or substantial portions of the Software.
00013  
00014  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020  THE SOFTWARE.
00021  
00022  $Id$
00023  */
00024 
00025 #import "CocosDenshion.h"
00026 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
00027     #import <AVFoundation/AVFoundation.h>
00028 #else
00029     #import "CDXMacOSXSupport.h"
00030 #endif
00031 
00033 typedef enum {
00034         kAMM_FxOnly,                                    
00035         kAMM_FxPlusMusic,                               
00036         kAMM_FxPlusMusicIfNoOtherAudio, 
00037         kAMM_MediaPlayback,                             
00038         kAMM_PlayAndRecord                              
00039 } tAudioManagerMode;
00040 
00042 typedef enum {
00043         kAMStateUninitialised, 
00044         kAMStateInitialising,  
00045         kAMStateInitialised        
00046 } tAudioManagerState;
00047 
00048 typedef enum {
00049         kAMRBDoNothing,                     //Audio manager will not do anything on resign or becoming active
00050         kAMRBStopPlay,                          //Background music is stopped on resign and resumed on become active
00051         kAMRBStop                                       //Background music is stopped on resign but not resumed - maybe because you want to do this from within your game
00052 } tAudioManagerResignBehavior;
00053 
00055 extern NSString * const kCDN_AudioManagerInitialised;
00056 
00057 @interface CDAsynchInitialiser : NSOperation {} 
00058 @end
00059 
00061 typedef enum {
00062         kASC_Left = 0,
00063         kASC_Right = 1
00064 } tAudioSourceChannel;  
00065 
00066 typedef enum {
00067         kLAS_Init,
00068         kLAS_Loaded,
00069         kLAS_Playing,
00070         kLAS_Paused,
00071         kLAS_Stopped,
00072 } tLongAudioSourceState;
00073 
00074 @class CDLongAudioSource;
00075 @protocol CDLongAudioSourceDelegate <NSObject>
00076 @optional
00078 - (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource;
00080 - (void) cdAudioSourceFileDidChange:(CDLongAudioSource *) audioSource;
00081 @end
00082 
00092 @interface CDLongAudioSource : NSObject <AVAudioPlayerDelegate, CDAudioInterruptProtocol>{
00093         AVAudioPlayer   *audioSourcePlayer;
00094         NSString                *audioSourceFilePath;
00095         NSInteger               numberOfLoops;
00096         float                   volume;
00097         id<CDLongAudioSourceDelegate> delegate; 
00098         BOOL                    mute;
00099         BOOL                    enabled_;
00100         BOOL                    backgroundMusic;
00101 @public 
00102         BOOL                    systemPaused;//Used for auto resign handling
00103         NSTimeInterval  systemPauseLocation;//Used for auto resign handling
00104 @protected
00105         tLongAudioSourceState state;
00106 }       
00107 @property (readonly) AVAudioPlayer *audioSourcePlayer;
00108 @property (readonly) NSString *audioSourceFilePath;
00109 @property (readwrite, nonatomic) NSInteger numberOfLoops;
00110 @property (readwrite, nonatomic) float volume;
00111 @property (assign) id<CDLongAudioSourceDelegate> delegate;
00112 /* This long audio source functions as background music */
00113 @property (readwrite, nonatomic) BOOL backgroundMusic;
00114 
00116 -(void) load:(NSString*) filePath;
00118 -(void) play;
00120 -(void) stop;
00122 -(void) pause;
00124 -(void) rewind;
00126 -(void) resume;
00128 -(BOOL) isPlaying;
00129 
00130 @end
00131 
00145 @interface CDAudioManager : NSObject <CDLongAudioSourceDelegate, CDAudioInterruptProtocol, AVAudioSessionDelegate> {
00146         CDSoundEngine           *soundEngine;
00147         CDLongAudioSource       *backgroundMusic;
00148         NSMutableArray          *audioSourceChannels;
00149         NSString*                       _audioSessionCategory;
00150         BOOL                            _audioWasPlayingAtStartup;
00151         tAudioManagerMode       _mode;
00152         SEL backgroundMusicCompletionSelector;
00153         id backgroundMusicCompletionListener;
00154         BOOL willPlayBackgroundMusic;
00155         BOOL _mute;
00156         BOOL _resigned;
00157         BOOL _interrupted;
00158         BOOL _audioSessionActive;
00159         BOOL enabled_;
00160         
00161         //For handling resign/become active
00162         BOOL _isObservingAppEvents;
00163         tAudioManagerResignBehavior _resignBehavior;
00164 }
00165 
00166 @property (readonly) CDSoundEngine *soundEngine;
00167 @property (readonly) CDLongAudioSource *backgroundMusic;
00168 @property (readonly) BOOL willPlayBackgroundMusic;
00169 
00171 + (CDAudioManager *) sharedManager;
00172 + (tAudioManagerState) sharedManagerState;
00174 + (void) configure: (tAudioManagerMode) mode;
00176 + (void) initAsynchronously: (tAudioManagerMode) mode;
00178 - (id) init: (tAudioManagerMode) mode;
00179 -(void) audioSessionInterrupted;
00180 -(void) audioSessionResumed;
00181 -(void) setResignBehavior:(tAudioManagerResignBehavior) resignBehavior autoHandle:(BOOL) autoHandle;
00183 -(BOOL) isDeviceMuted;
00185 -(BOOL) isOtherAudioPlaying;
00187 -(void) setMode:(tAudioManagerMode) mode;
00189 +(void) end;
00190 
00192 - (void) applicationWillResignActive;
00194 - (void) applicationDidBecomeActive;
00195 
00196 //New AVAudioPlayer API
00198 -(CDLongAudioSource*) audioSourceLoad:(NSString*) filePath channel:(tAudioSourceChannel) channel;
00200 -(CDLongAudioSource*) audioSourceForChannel:(tAudioSourceChannel) channel;
00201 
00202 //Legacy AVAudioPlayer API
00206 -(void) playBackgroundMusic:(NSString*) filePath loop:(BOOL) loop;
00208 -(void) preloadBackgroundMusic:(NSString*) filePath;
00210 -(void) stopBackgroundMusic;
00212 -(void) pauseBackgroundMusic;
00214 -(void) rewindBackgroundMusic;
00216 -(void) resumeBackgroundMusic;
00218 -(BOOL) isBackgroundMusicPlaying;
00219 
00220 -(void) setBackgroundMusicCompletionListener:(id) listener selector:(SEL) selector;
00221 
00222 @end
00223 
00225 @interface CDLongAudioSourceFader : CDPropertyModifier{}
00226 @end
00227 
00228 static const int kCDNoBuffer = -1;
00229 
00231 @interface CDBufferManager:NSObject{
00232         NSMutableDictionary* loadedBuffers;
00233         NSMutableArray  *freedBuffers;
00234         CDSoundEngine *soundEngine;
00235         int nextBufferId;
00236 }
00237 
00238 -(id) initWithEngine:(CDSoundEngine *) theSoundEngine;
00239 -(int) bufferForFile:(NSString*) filePath create:(BOOL) create;
00240 -(void) releaseBufferForFile:(NSString *) filePath;
00241 
00242 @end
00243 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

cocos2d for iPhone API Reference - Generated using Doxygen 1.7.4