OALSimpleAudio Class Reference
| Inherits from | NSObject |
| Declared in | OALSimpleAudio.h |
Overview
A simpler interface to the ObjectAL sound library. This singleton can be used alone for simpler audio needs, or in conjunction with user-created audio objects for more advanced needs (as is done in many of the demos).
For sound effects, it initializes OpenAL with the default ALDevice, an ALContext, and an ALChannelSource consisting of all 32 interruptible ALSource objects (the maximum currently allowed for iOS). If you want to create your own sources as well, change the reservedSources property.
For background audio, it creates a single OALAudioTrack, which will not reserve resources unless used. (you can create more OALAudioTrack objects for your own use if you want).
This singleton also provides access to the more common configuration options available in OALAudioSupport.
All audio playback commands are delegated either to the ALChannelSource (for sound effects), or to the OALAudioTrack (for BG music).
Tasks
-
allowIpodIf YES, allow ipod music to continue playing (NOT SUPPORTED ON THE SIMULATOR). Note: If this is enabled, and another app is playing music, background audio playback will use the SOFTWARE codecs, NOT hardware.
property -
useHardwareIfAvailableDetermines what to do if no other application is playing audio and allowIpod = YES (NOT SUPPORTED ON THE SIMULATOR).
property -
honorSilentSwitchIf true, mute when backgrounded, screen locked, or the ringer switch is turned off (NOT SUPPORTED ON THE SIMULATOR).
property -
reservedSourcesThe number of sources OALSimpleAudio is using (max 32 on current iOS devices).
property -
channelThe channel source used by OALSimpleAudio. Only mess with this if you know what you are doing!
property -
backgroundTrackURLBackground audio URL
property -
backgroundTrackBackground audio track
property -
bgPausedPauses BG music playback
property -
bgMutedMutes BG music playback
property -
bgPlayingIf true, BG music is currently playing
property -
bgVolumeBackground music playback gain/volume (0.0 – 1.0)
property -
effectsPausedPauses effects playback
property -
effectsMutedMutes effects playback
property -
effectsVolumeMaster effects gain/volume (0.0 – 1.0)
property -
pausedPauses everything
property -
mutedMutes all audio
property -
preloadCacheEnabledEnables/disables the preload cache. If the preload cache is disabled, effects preloading will do nothing (BG preloading will still work).
property -
preloadCacheCountThe number of items currently in the preload cache.
property -
manuallySuspendedSet to YES to manually suspend the sound system.
property -
interruptedIf YES, the sound system is interrupted.
property -
suspendedIf YES, the sound system is suspended.
property -
+ sharedInstanceWithSources:Start OALSimpleAudio with the specified number of reserved sources. Call this initializer if you want to use OALSimpleAudio, but keep some of the device’s audio sources (there are 32 in total) for your own use.
Note: This method must be called ONLY ONCE, BEFORE any attempt is made to access the shared instance. To change the reserved sources after instantiation, modify reservedSources. -
+ sharedInstanceWithReservedSources:monoSources:stereoSources:Start OALSimpleAudio with the specified parameters.
-
– initWithSources:(INTERNAL USE) Initialize with the specified number of reserved sources.
-
– initWithReservedSources:monoSources:stereoSources:(INTERNAL USE) Initialize with the specified parameters.
-
– preloadBg:Preload background music.
-
– preloadBg:seekTime:Preload background music.
-
– playBgPlay whatever background music is preloaded.
-
– playBgWithLoop:Play whatever background music is preloaded.
-
– playBg:Play the background music at the specified path. If the music has not been preloaded, this method will load the music and then play, incurring a slight delay.
-
– playBg:loop:Play the background music at the specified path. If the music has not been preloaded, this method will load the music and then play, incurring a slight delay.
-
– playBg:volume:pan:loop:Play the background music at the specified path. If the music has not been preloaded, this method will load the music and then play, incurring a slight delay.
-
– stopBgStop the background music playback and rewind.
-
– preloadEffect:Preload and cache a sound effect for later playback.
-
– preloadEffect:reduceToMono:Preload and cache a sound effect for later playback.
-
– preloadEffect:reduceToMono:completionBlock:Asynchronous preload and cache sound effect for later playback.
-
– preloadEffects:reduceToMono:progressBlock:Asynchronous preload and cache multiple sound effects for later playback.
-
– unloadEffect:Unload a preloaded effect.
-
– unloadAllEffectsUnload all preloaded effects. It is useful to put a call to this method in “applicationDidReceiveMemoryWarning” in your app delegate.
-
– playEffect:Play a sound effect with volume 1.0, pitch 1.0, pan 0.0, loop NO. The sound will be loaded and cached if it wasn’t already.
-
– playEffect:loop:Play a sound effect with volume 1.0, pitch 1.0, pan 0.0. The sound will be loaded and cached if it wasn’t already.
-
– playEffect:volume:pitch:pan:loop:Play a sound effect. The sound will be loaded and cached if it wasn’t already.
-
– playBuffer:volume:pitch:pan:loop:Play a sound effect from a user-supplied buffer.
-
– stopAllEffectsStop ALL sound effect playback.
-
– stopEverythingStop all effects and bg music.
-
– resetToDefaultReset everything in this object to its default state.
Properties
allowIpod
If YES, allow ipod music to continue playing (NOT SUPPORTED ON THE SIMULATOR).
Note: If this is enabled, and another app is playing music, background audio
playback will use the SOFTWARE codecs, NOT hardware.
@property (readwrite, assign) bool allowIpodDiscussion
If allowIpod = NO, the application will ALWAYS use hardware decoding.
See Also
@property useHardwareIfAvailable
Default value: YES
Declared In
OALSimpleAudio.hbackgroundTrack
Background audio track
@property (nonatomic, readonly) OALAudioTrack *backgroundTrackDeclared In
OALSimpleAudio.hbackgroundTrackURL
Background audio URL
@property (nonatomic, readonly) NSURL *backgroundTrackURLDeclared In
OALSimpleAudio.hbgMuted
Mutes BG music playback
@property (readwrite, assign) bool bgMutedDeclared In
OALSimpleAudio.hbgPaused
Pauses BG music playback
@property (readwrite, assign) bool bgPausedDeclared In
OALSimpleAudio.hbgPlaying
If true, BG music is currently playing
@property (nonatomic, readonly) bool bgPlayingDeclared In
OALSimpleAudio.hbgVolume
Background music playback gain/volume (0.0 – 1.0)
@property (readwrite, assign) float bgVolumeDeclared In
OALSimpleAudio.hchannel
The channel source used by OALSimpleAudio. Only mess with this if you know what you are doing!
@property (nonatomic, readonly) ALChannelSource *channelDeclared In
OALSimpleAudio.heffectsMuted
Mutes effects playback
@property (readwrite, assign) bool effectsMutedDeclared In
OALSimpleAudio.heffectsPaused
Pauses effects playback
@property (readwrite, assign) bool effectsPausedDeclared In
OALSimpleAudio.heffectsVolume
Master effects gain/volume (0.0 – 1.0)
@property (readwrite, assign) float effectsVolumeDeclared In
OALSimpleAudio.hhonorSilentSwitch
If true, mute when backgrounded, screen locked, or the ringer switch is
turned off (NOT SUPPORTED ON THE SIMULATOR).
@property (readwrite, assign) bool honorSilentSwitchDiscussion
Default value: YES
Declared In
OALSimpleAudio.hinterrupted
If YES, the sound system is interrupted.
@property (nonatomic, readonly) bool interruptedDeclared In
OALSimpleAudio.hmanuallySuspended
Set to YES to manually suspend the sound system.
@property (readwrite, assign) bool manuallySuspendedDeclared In
OALSimpleAudio.hpreloadCacheCount
The number of items currently in the preload cache.
@property (nonatomic, readonly) NSUInteger preloadCacheCountDeclared In
OALSimpleAudio.hpreloadCacheEnabled
Enables/disables the preload cache. If the preload cache is disabled, effects preloading will do nothing (BG preloading will still work).
@property (readwrite, assign) bool preloadCacheEnabledDeclared In
OALSimpleAudio.hreservedSources
The number of sources OALSimpleAudio is using (max 32 on current iOS devices).
@property (readwrite, assign) int reservedSourcesDeclared In
OALSimpleAudio.hsuspended
If YES, the sound system is suspended.
@property (nonatomic, readonly) bool suspendedDeclared In
OALSimpleAudio.huseHardwareIfAvailable
Determines what to do if no other application is playing audio and allowIpod = YES
(NOT SUPPORTED ON THE SIMULATOR).
@property (readwrite, assign) bool useHardwareIfAvailableDiscussion
If NO, the application will ALWAYS use software decoding. The advantage to this is that
the user can background your application and then start audio playing from another
application. If useHardwareIfAvailable = YES, the user won’t be able to do this.
If this is set to YES, the application will use hardware decoding if no other application
is currently playing audio. However, no other application will be able to start playing
audio if it wasn’t playing already.
Note: This switch has no effect if allowIpod = NO.
See Also
Default value: YES
Declared In
OALSimpleAudio.hClass Methods
sharedInstanceWithReservedSources:monoSources:stereoSources:
Start OALSimpleAudio with the specified parameters.
+ (OALSimpleAudio *)sharedInstanceWithReservedSources:(int)reservedSources monoSources:(int)monoSources stereoSources:(int)stereoSourcesParameters
- reservedSources
The number of sources to reserve for OALSimpleAudio’s use when initializing. iOS currently supports up to 32 sources total.
- monoSources
The GLOBAL number of sources supporting mono (default 28).
- stereoSources
The GLOBAL number of sources supporting stereo (default 4).
Return Value
The shared instance.
Discussion
With this initializer, you can set the total number of mono and stereo sources
available, as well as how many sources are to be reserved by OALSimpleAudio.
The number of mono and stereo sources represents the GLOBAL number of sources
available for EVERYONE, not just OALSimpleAudio. Their combined values must
not exceed 32 (the max allowed sources in iOS).
reservedSources is independent of this; it represents how many of the above
mentioned sources to reserve for OALSimpleAudio’s use.
Note: This method must be called ONLY ONCE, BEFORE
any attempt is made to access the shared instance.
Declared In
OALSimpleAudio.hsharedInstanceWithSources:
Start OALSimpleAudio with the specified number of reserved sources.
Call this initializer if you want to use OALSimpleAudio, but keep some of the device’s
audio sources (there are 32 in total) for your own use.
Note: This method must be called ONLY ONCE, BEFORE
any attempt is made to access the shared instance.
To change the reserved sources after instantiation, modify reservedSources.
+ (OALSimpleAudio *)sharedInstanceWithSources:(int)sourcesParameters
- sources
the number of sources OALSimpleAudio will reserve for itself.
Return Value
The shared instance.
Declared In
OALSimpleAudio.hInstance Methods
initWithReservedSources:monoSources:stereoSources:
(INTERNAL USE) Initialize with the specified parameters.
- (id)initWithReservedSources:(int)reservedSources monoSources:(int)monoSources stereoSources:(int)stereoSourcesParameters
- reservedSources
The number of sources to reserve for OALSimpleAudio’s use when initializing.
- monoSources
The GLOBAL number of sources supporting mono (default 28).
- stereoSources
The GLOBAL number of sources supporting stereo (default 4).
Return Value
The shared instance.
Declared In
OALSimpleAudio.hinitWithSources:
(INTERNAL USE) Initialize with the specified number of reserved sources.
- (id)initWithSources:(int)reservedSourcesParameters
- reservedSources
the number of sources to reserve when initializing.
Return Value
The shared instance.
Declared In
OALSimpleAudio.hplayBg
Play whatever background music is preloaded.
- (bool)playBgReturn Value
TRUE if the operation was successful.
Declared In
OALSimpleAudio.hplayBg:
Play the background music at the specified path.
If the music has not been preloaded, this method
will load the music and then play, incurring a slight delay.
- (bool)playBg:(NSString *)pathParameters
- path
The path containing the background music.
Return Value
TRUE if the operation was successful.
Discussion
Note: only ONE background music file may be played or preloaded at a time via OALSimpleAudio. If you play or preload another file, the one currently playing will stop.
Declared In
OALSimpleAudio.hplayBg:loop:
Play the background music at the specified path.
If the music has not been preloaded, this method
will load the music and then play, incurring a slight delay.
- (bool)playBg:(NSString *)path loop:(bool)loopParameters
- path
The path containing the background music.
- loop
If true, loop the bg track.
Return Value
TRUE if the operation was successful.
Discussion
Note: only ONE background music file may be played or preloaded at a time via OALSimpleAudio. If you play or preload another file, the one currently playing will stop.
Declared In
OALSimpleAudio.hplayBg:volume:pan:loop:
Play the background music at the specified path.
If the music has not been preloaded, this method
will load the music and then play, incurring a slight delay.
- (bool)playBg:(NSString *)filePath volume:(float)volume pan:(float)pan loop:(bool)loopParameters
- filePath
The path containing the sound data.
- volume
The volume (gain) to play at (0.0 – 1.0).
- pan
Left-right panning (-1.0 = far left, 1.0 = far right) (Only on iOS 4.0+).
- loop
If TRUE, the sound will loop until you call “stopBg”.
Return Value
TRUE if the operation was successful.
Discussion
Note: only ONE background music
file may be played or preloaded at a time via OALSimpleAudio.
If you play or preload another file, the one currently playing
will stop. To play multiple audio tracks, create an OALAudioTrack.
Note: pan will have no effect when running on iOS versions prior to 4.0.
Declared In
OALSimpleAudio.hplayBgWithLoop:
Play whatever background music is preloaded.
- (bool)playBgWithLoop:(bool)loopParameters
- loop
If true, loop the bg track.
Return Value
TRUE if the operation was successful.
Declared In
OALSimpleAudio.hplayBuffer:volume:pitch:pan:loop:
Play a sound effect from a user-supplied buffer.
- (id<ALSoundSource>)playBuffer:(ALBuffer *)buffer volume:(float)volume pitch:(float)pitch pan:(float)pan loop:(bool)loopParameters
- buffer
The buffer containing the sound data.
- volume
The volume (gain) to play at (0.0 – 1.0).
- pitch
The pitch to play at (1.0 = normal pitch).
- pan
Left-right panning (-1.0 = far left, 1.0 = far right).
- loop
If TRUE, the sound will loop until you call “stop” on the returned sound source.
Return Value
The sound source being used for playback, or nil if an error occurred (You’ll need to keep this if you want to be able to stop a looped playback).
Declared In
OALSimpleAudio.hplayEffect:
Play a sound effect with volume 1.0, pitch 1.0, pan 0.0, loop NO. The sound will be loaded and cached if it wasn’t already.
- (id<ALSoundSource>)playEffect:(NSString *)filePathParameters
- filePath
The path containing the sound data.
Return Value
The sound source being used for playback, or nil if an error occurred.
Declared In
OALSimpleAudio.hplayEffect:loop:
Play a sound effect with volume 1.0, pitch 1.0, pan 0.0. The sound will be loaded and cached if it wasn’t already.
- (id<ALSoundSource>)playEffect:(NSString *)filePath loop:(bool)loopParameters
- filePath
The path containing the sound data.
- loop
If TRUE, the sound will loop until you call “stop” on the returned sound source.
Return Value
The sound source being used for playback, or nil if an error occurred.
Declared In
OALSimpleAudio.hplayEffect:volume:pitch:pan:loop:
Play a sound effect. The sound will be loaded and cached if it wasn’t already.
- (id<ALSoundSource>)playEffect:(NSString *)filePath volume:(float)volume pitch:(float)pitch pan:(float)pan loop:(bool)loopParameters
- filePath
The path containing the sound data.
- volume
The volume (gain) to play at (0.0 – 1.0).
- pitch
The pitch to play at (1.0 = normal pitch).
- pan
Left-right panning (-1.0 = far left, 1.0 = far right).
- loop
If TRUE, the sound will loop until you call “stop” on the returned sound source.
Return Value
The sound source being used for playback, or nil if an error occurred (You’ll need to keep this if you want to be able to stop a looped playback).
Declared In
OALSimpleAudio.hpreloadBg:
Preload background music.
- (bool)preloadBg:(NSString *)pathParameters
- path
The path containing the background music.
Return Value
TRUE if the operation was successful.
Discussion
Note: only ONE background music file may be played or preloaded at a time via OALSimpleAudio. If you play or preload another file, the one currently playing will stop.
Declared In
OALSimpleAudio.hpreloadBg:seekTime:
Preload background music.
- (bool)preloadBg:(NSString *)path seekTime:(NSTimeInterval)seekTimeParameters
- path
The path containing the background music.
- seekTime
the position in the file to start playing at.
Return Value
TRUE if the operation was successful.
Discussion
Note: only ONE background music file may be played or preloaded at a time via OALSimpleAudio. If you play or preload another file, the one currently playing will stop.
Declared In
OALSimpleAudio.hpreloadEffect:
Preload and cache a sound effect for later playback.
- (ALBuffer *)preloadEffect:(NSString *)filePathParameters
- filePath
The path containing the sound data.
Declared In
OALSimpleAudio.hpreloadEffect:reduceToMono:
Preload and cache a sound effect for later playback.
- (ALBuffer *)preloadEffect:(NSString *)filePath reduceToMono:(bool)reduceToMonoParameters
- filePath
The path containing the sound data.
- reduceToMono
If true, reduce the sample to mono (stereo samples don’t support panning or positional audio).
Declared In
OALSimpleAudio.hpreloadEffect:reduceToMono:completionBlock:
Asynchronous preload and cache sound effect for later playback.
- (BOOL)preloadEffect:(NSString *)filePath reduceToMono:(bool)reduceToMono completionBlock:(void ( ^ ) ( ALBuffer *))completionBlockParameters
- filePath
an NSString with the path containing the sound data.
- reduceToMono
If true, reduce the sample to mono (stereo samples don’t support panning or positional audio).
- completionBlock
Executed when loading is complete.
Declared In
OALSimpleAudio.hpreloadEffects:reduceToMono:progressBlock:
Asynchronous preload and cache multiple sound effects for later playback.
- (void)preloadEffects:(NSArray *)filePaths reduceToMono:(bool)reduceToMono progressBlock:(void ( ^ ) ( uint progress , uint successCount , uint total ))progressBlockParameters
- filePaths
An NSArray of NSStrings with the paths containing the sound data.
- reduceToMono
If true, reduce the samples to mono (stereo samples don’t support panning or positional audio).
- progressBlock
Executed regularly while file loading is in progress.
Declared In
OALSimpleAudio.hresetToDefault
Reset everything in this object to its default state.
- (void)resetToDefaultDeclared In
OALSimpleAudio.h