Go to the documentation of this file.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
00026
00070 #import <UIKit/UIKit.h>
00071 #import <OpenAL/al.h>
00072 #import <OpenAL/alc.h>
00073 #import <AudioToolbox/AudioToolbox.h>
00074 #import "CDConfig.h"
00075
00076 #if !defined(CD_DEBUG) || CD_DEBUG == 0
00077 #define CDLOG(...) do {} while (0)
00078 #define CDLOGINFO(...) do {} while (0)
00079
00080 #elif CD_DEBUG == 1
00081 #define CDLOG(...) NSLog(__VA_ARGS__)
00082 #define CDLOGINFO(...) do {} while (0)
00083
00084 #elif CD_DEBUG > 1
00085 #define CDLOG(...) NSLog(__VA_ARGS__)
00086 #define CDLOGINFO(...) NSLog(__VA_ARGS__)
00087 #endif // CD_DEBUG
00088
00089
00090 #import "CDOpenALSupport.h"
00091
00092
00093 #define CD_SOURCE_LIMIT 32 //Total number of sources we will ever want, may actually get less
00094 #define CD_NO_SOURCE 0xFEEDFAC //Return value indicating playback failed i.e. no source
00095 #define CD_IGNORE_AUDIO_SESSION 0xBEEFBEE //Used internally to indicate audio session will not be handled
00096 #define CD_MUTE 0xFEEDBAB //Return value indicating sound engine is muted or non functioning
00097 #define CD_NO_SOUND = -1;
00098
00099 #define CD_SAMPLE_RATE_HIGH 44100
00100 #define CD_SAMPLE_RATE_MID 22050
00101 #define CD_SAMPLE_RATE_LOW 16000
00102 #define CD_SAMPLE_RATE_BASIC 8000
00103 #define CD_SAMPLE_RATE_DEFAULT 44100
00104
00105 enum bufferState {
00106 CD_BS_EMPTY = 0,
00107 CD_BS_LOADED = 1,
00108 CD_BS_FAILED = 2
00109 };
00110
00111 typedef struct _sourceGroup {
00112 int startIndex;
00113 int currentIndex;
00114 int totalSources;
00115 bool enabled;
00116 bool nonInterruptible;
00117 int *sourceStatuses;
00118 } sourceGroup;
00119
00120 typedef struct _bufferInfo {
00121 ALuint bufferId;
00122 int bufferState;
00123 void* bufferData;
00124 } bufferInfo;
00125
00126 typedef struct _sourceInfo {
00127 bool usable;
00128 ALuint sourceId;
00129 ALuint attachedBufferId;
00130 } sourceInfo;
00131
00132 #pragma mark CDAudioTransportProtocol
00133
00134 @protocol CDAudioTransportProtocol <NSObject>
00136 -(BOOL) play;
00138 -(BOOL) pause;
00140 -(BOOL) stop;
00142 -(BOOL) rewind;
00143 @end
00144
00145 #pragma mark CDAudioInterruptProtocol
00146
00147 @protocol CDAudioInterruptProtocol <NSObject>
00149 -(BOOL) mute;
00151 -(void) setMute:(BOOL) muteValue;
00153 -(BOOL) enabled;
00155 -(void) setEnabled:(BOOL) enabledValue;
00156 @end
00157
00158 #pragma mark CDUtilities
00159
00162 @interface CDUtilities : NSObject
00163 {
00164 }
00165
00167 +(NSString*) fullPathFromRelativePath:(NSString*) relPath;
00168
00169 @end
00170
00171
00172 #pragma mark CDSoundEngine
00173
00188 @class CDSoundSource;
00189 @interface CDSoundEngine : NSObject <CDAudioInterruptProtocol> {
00190
00191 bufferInfo *_buffers;
00192 sourceInfo *_sources;
00193 sourceGroup *_sourceGroups;
00194 ALCcontext *context;
00195 int _sourceGroupTotal;
00196 UInt32 _audioSessionCategory;
00197 BOOL _handleAudioSession;
00198 BOOL mute_;
00199 BOOL enabled_;
00200 ALfloat _preMuteGain;
00201
00202 ALenum lastErrorCode_;
00203 BOOL functioning_;
00204 float asynchLoadProgress_;
00205 BOOL getGainWorks_;
00206
00207
00208 int sourceTotal_;
00209 int bufferTotal;
00210
00211 }
00212
00213 @property (readwrite, nonatomic) ALfloat masterGain;
00214 @property (readonly) ALenum lastErrorCode;
00215 @property (readonly) BOOL functioning;
00216 @property (readwrite) float asynchLoadProgress;
00217 @property (readonly) BOOL getGainWorks;
00219 @property (readonly) int sourceTotal;
00221 @property (readonly) int sourceGroupTotal;
00222
00224 +(void) setMixerSampleRate:(Float32) sampleRate;
00225
00227 -(id)init;
00229 -(id)init:(UInt32) audioSessionCategory;
00230
00232 -(ALuint) playSound:(int) soundId sourceGroupId:(int)sourceGroupId pitch:(float) pitch pan:(float) pan gain:(float) gain loop:(BOOL) loop;
00233
00236 -(CDSoundSource *) soundSourceForSound:(int) soundId sourceGroupId:(int) sourceGroupId;
00237
00239 - (void) stopSound:(ALuint) sourceId;
00241 - (void) stopSourceGroup:(int) sourceGroupId;
00243 -(void) stopAllSounds;
00244 -(void) defineSourceGroups:(NSArray*) sourceGroupDefinitions;
00245 -(void) defineSourceGroups:(int[]) sourceGroupDefinitions total:(int) total;
00246 -(void) setSourceGroupNonInterruptible:(int) sourceGroupId isNonInterruptible:(BOOL) isNonInterruptible;
00247 -(void) setSourceGroupEnabled:(int) sourceGroupId enabled:(BOOL) enabled;
00248 -(BOOL) sourceGroupEnabled:(int) sourceGroupId;
00249 -(BOOL) loadBufferFromData:(int) soundId soundData:(ALvoid*) soundData format:(ALenum) format size:(ALsizei) size freq:(ALsizei) freq;
00250 -(BOOL) loadBuffer:(int) soundId filePath:(NSString*) filePath;
00251 -(void) loadBuffersAsynchronously:(NSArray *) loadRequests;
00252 -(BOOL) unloadBuffer:(int) soundId;
00253 -(ALCcontext *) openALContext;
00254 -(void) audioSessionInterrupted;
00255 -(void) audioSessionResumed;
00256
00258 -(void) _soundSourcePreRelease:(CDSoundSource *) soundSource;
00259
00260 @end
00261
00262 #pragma mark CDSoundSource
00263
00270 @interface CDSoundSource : NSObject <CDAudioTransportProtocol, CDAudioInterruptProtocol> {
00271 ALenum lastError;
00272 @public
00273 ALuint _sourceId;
00274 ALuint _sourceIndex;
00275 CDSoundEngine* _engine;
00276 int _soundId;
00277 float _preMuteGain;
00278 BOOL enabled_;
00279 BOOL mute_;
00280 }
00281 @property (readwrite, nonatomic) float pitch;
00282 @property (readwrite, nonatomic) float gain;
00283 @property (readwrite, nonatomic) float pan;
00284 @property (readwrite, nonatomic) BOOL looping;
00285 @property (readonly) BOOL isPlaying;
00286 @property (readwrite, nonatomic) int soundId;
00287
00289 @property (readonly) ALenum lastError;
00291 -(id)init:(ALuint) theSourceId sourceIndex:(int) index soundEngine:(CDSoundEngine*) engine;
00292
00293 @end
00294
00295 #pragma mark CDAudioInterruptTargetGroup
00296
00301 @interface CDAudioInterruptTargetGroup : NSObject <CDAudioInterruptProtocol> {
00302 BOOL mute_;
00303 BOOL enabled_;
00304 NSMutableArray *children_;
00305 }
00306 -(void) addAudioInterruptTarget:(NSObject<CDAudioInterruptProtocol>*) interruptibleTarget;
00307 @end
00308
00309 #pragma mark CDAsynchBufferLoader
00310
00314 @interface CDAsynchBufferLoader : NSOperation {
00315 NSArray *_loadRequests;
00316 CDSoundEngine *_soundEngine;
00317 }
00318
00319 -(id) init:(NSArray *)loadRequests soundEngine:(CDSoundEngine *) theSoundEngine;
00320
00321 @end
00322
00323 #pragma mark CDBufferLoadRequest
00324
00326 @interface CDBufferLoadRequest: NSObject
00327 {
00328 NSString *filePath;
00329 int soundId;
00330
00331 }
00332
00333 @property (readonly) NSString *filePath;
00334 @property (readonly) int soundId;
00335
00336 - (id)init:(int) theSoundId filePath:(NSString *) theFilePath;
00337 @end
00338
00340 typedef enum {
00341 kIT_Linear,
00342 kIT_SCurve,
00343 kIT_Exponential
00344 } tCDInterpolationType;
00345
00346 #pragma mark CDFloatInterpolator
00347 @interface CDFloatInterpolator: NSObject
00348 {
00349 float start;
00350 float end;
00351 float lastValue;
00352 tCDInterpolationType interpolationType;
00353 }
00354 @property (readwrite, nonatomic) float start;
00355 @property (readwrite, nonatomic) float end;
00356 @property (readwrite, nonatomic) tCDInterpolationType interpolationType;
00357
00360 -(float) interpolate:(float) t;
00361 -(id) init:(tCDInterpolationType) type startVal:(float) startVal endVal:(float) endVal;
00362
00363 @end
00364
00365 #pragma mark CDPropertyModifier
00366
00368 @interface CDPropertyModifier: NSObject
00369 {
00370 CDFloatInterpolator *interpolator;
00371 float startValue;
00372 float endValue;
00373 id target;
00374 BOOL stopTargetWhenComplete;
00375
00376 }
00377 @property (readwrite, nonatomic) BOOL stopTargetWhenComplete;
00378 @property (readwrite, nonatomic) float startValue;
00379 @property (readwrite, nonatomic) float endValue;
00380 @property (readwrite, nonatomic) tCDInterpolationType interpolationType;
00381
00382 -(id) init:(id) theTarget interpolationType:(tCDInterpolationType) type startVal:(float) startVal endVal:(float) endVal;
00384 -(void) modify:(float) t;
00385
00386 -(void) _setTargetProperty:(float) newVal;
00387 -(float) _getTargetProperty;
00388 -(void) _stopTarget;
00389 -(Class) _allowableType;
00390
00391 @end
00392
00393 #pragma mark CDSoundSourceFader
00394
00396 @interface CDSoundSourceFader : CDPropertyModifier{}
00397 @end
00398
00399 #pragma mark CDSoundSourcePanner
00400
00402 @interface CDSoundSourcePanner : CDPropertyModifier{}
00403 @end
00404
00405 #pragma mark CDSoundSourcePitchBender
00406
00408 @interface CDSoundSourcePitchBender : CDPropertyModifier{}
00409 @end
00410
00411 #pragma mark CDSoundEngineFader
00412
00414 @interface CDSoundEngineFader : CDPropertyModifier{}
00415 @end
00416
00417
00418
00419