00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #import "CocosDenshion.h"
00026 #import <AVFoundation/AVFoundation.h>
00027
00029 typedef enum {
00030 kAMM_FxOnly,
00031 kAMM_FxPlusMusic,
00032 kAMM_FxPlusMusicIfNoOtherAudio,
00033 kAMM_MediaPlayback,
00034 kAMM_PlayAndRecord
00035 } tAudioManagerMode;
00036
00038 typedef enum {
00039 kAMStateUninitialised,
00040 kAMStateInitialising,
00041 kAMStateInitialised
00042 } tAudioManagerState;
00043
00044 typedef enum {
00045 kAMRBDoNothing,
00046 kAMRBStopPlay,
00047 kAMRBStop
00048 } tAudioManagerResignBehavior;
00049
00050
00051 @interface CDAsynchInitialiser : NSOperation {}
00052 @end
00053
00055 typedef enum {
00056 kASC_Left = 0,
00057 kASC_Right = 1
00058 } tAudioSourceChannel;
00059
00060 typedef enum {
00061 kLAS_Init,
00062 kLAS_Loaded,
00063 kLAS_Playing,
00064 kLAS_Paused,
00065 kLAS_Stopped,
00066 } tLongAudioSourceState;
00067
00068 @class CDLongAudioSource;
00069 @protocol CDLongAudioSourceDelegate <NSObject>
00070 @optional
00072 - (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource;
00074 - (void) cdAudioSourceFileDidChange:(CDLongAudioSource *) audioSource;
00075 @end
00076
00086 @interface CDLongAudioSource : NSObject <AVAudioPlayerDelegate, CDAudioInterruptProtocol>{
00087 AVAudioPlayer *audioSourcePlayer;
00088 NSString *audioSourceFilePath;
00089 NSInteger numberOfLoops;
00090 float volume;
00091 id<CDLongAudioSourceDelegate> delegate;
00092 BOOL mute;
00093 BOOL enabled_;
00094 @public
00095 BOOL systemPaused;
00096 NSTimeInterval systemPauseLocation;
00097 @protected
00098 tLongAudioSourceState state;
00099 }
00100 @property (readonly) AVAudioPlayer *audioSourcePlayer;
00101 @property (readonly) NSString *audioSourceFilePath;
00102 @property (readwrite, nonatomic) NSInteger numberOfLoops;
00103 @property (readwrite, nonatomic) float volume;
00104 @property(assign) id<CDLongAudioSourceDelegate> delegate;
00105
00107 -(void) load:(NSString*) filePath;
00109 -(void) play;
00111 -(void) stop;
00113 -(void) pause;
00115 -(void) rewind;
00117 -(void) resume;
00119 -(BOOL) isPlaying;
00120
00121 @end
00122
00136 @interface CDAudioManager : NSObject <CDLongAudioSourceDelegate, CDAudioInterruptProtocol> {
00137 CDSoundEngine *soundEngine;
00138 CDLongAudioSource *backgroundMusic;
00139 NSMutableArray *audioSourceChannels;
00140 UInt32 _audioSessionCategory;
00141 BOOL _audioWasPlayingAtStartup;
00142 tAudioManagerMode _mode;
00143 SEL backgroundMusicCompletionSelector;
00144 id backgroundMusicCompletionListener;
00145 BOOL willPlayBackgroundMusic;
00146 BOOL _mute;
00147 BOOL _resigned;
00148 BOOL enabled_;
00149
00150
00151 BOOL _isObservingAppEvents;
00152 tAudioManagerResignBehavior _resignBehavior;
00153 }
00154
00155 @property (readonly) CDSoundEngine *soundEngine;
00156 @property (readonly) CDLongAudioSource *backgroundMusic;
00157 @property (readonly) BOOL willPlayBackgroundMusic;
00158
00160 + (CDAudioManager *) sharedManager;
00161 + (tAudioManagerState) sharedManagerState;
00163 + (void) configure: (tAudioManagerMode) mode;
00165 + (void) initAsynchronously: (tAudioManagerMode) mode;
00167 - (id) init: (tAudioManagerMode) mode;
00168 -(void) audioSessionInterrupted;
00169 -(void) audioSessionResumed;
00170 -(void) setResignBehavior:(tAudioManagerResignBehavior) resignBehavior autoHandle:(BOOL) autoHandle;
00172 -(BOOL) isDeviceMuted;
00174 -(BOOL) isOtherAudioPlaying;
00176 -(void) setMode:(tAudioManagerMode) mode;
00178 +(void) end;
00179
00180
00182 -(CDLongAudioSource*) audioSourceLoad:(NSString*) filePath channel:(tAudioSourceChannel) channel;
00184 -(CDLongAudioSource*) audioSourceForChannel:(tAudioSourceChannel) channel;
00185
00186
00190 -(void) playBackgroundMusic:(NSString*) filePath loop:(BOOL) loop;
00192 -(void) preloadBackgroundMusic:(NSString*) filePath;
00194 -(void) stopBackgroundMusic;
00196 -(void) pauseBackgroundMusic;
00198 -(void) rewindBackgroundMusic;
00200 -(void) resumeBackgroundMusic;
00202 -(BOOL) isBackgroundMusicPlaying;
00203
00204 -(void) setBackgroundMusicCompletionListener:(id) listener selector:(SEL) selector;
00205
00206 @end
00207
00209 @interface CDLongAudioSourceFader : CDPropertyModifier{}
00210 @end
00211
00212 static const int kCDNoBuffer = -1;
00213
00215 @interface CDBufferManager:NSObject{
00216 NSMutableDictionary* loadedBuffers;
00217 NSMutableArray *freedBuffers;
00218 CDSoundEngine *soundEngine;
00219 int nextBufferId;
00220 }
00221
00222 -(id) initWithEngine:(CDSoundEngine *) theSoundEngine;
00223 -(int) bufferForFile:(NSString*) filePath create:(BOOL) create;
00224 -(void) releaseBufferForFile:(NSString *) filePath;
00225
00226 @end
00227