PXSoundLoader Class Reference
| Inherits from | PXLoader : NSObject |
| Declared in | PXSoundLoader.h PXSoundLoader.m |
Overview
A PXSoundLoader Loads sounds synchronously and creates PXSound objects.
Once instantiated with a valid file path, objects of the PXSound class will hold the necessary info to play the sound.
For most uses generating more than one PXSound object is unnecessary as a single PXSound may be shared among many #PXSoundChannels.
Once a PXSound instance has been created, the PXSoundLoader instance may be
safely deallocated by calling release. Since PXSoundLoader
keeps a copy of the loaded data, it is advisable to release all unneeded
instances as soon as a PXSound object has been created in order to free up
memory.
The following sound formats are supported natively:
Can be 3D (if mono)
- .wav
- .caf
Cannot be 3D
- .mp3
- .m4a
- .alac and .acc
- .aiff, .aif and .aifc
Example:
// Create a loader object to load and parse the wav from the application
// bundle.
PXSoundLoader *loader = [[PXSoundLoader alloc] initWithContentsOfFile:@"sound.wav"];
// Turn the loaded data to an OpenAL sound
PXSound *sound = [loader newSound];
// The loader is no longer needed
[loader release];
loader = nil;
// Create a PXSoundChannel object to play the sound
PXSoundChannel *channel = [sound playWithStartTime:0 loopCount:0 soundTransform:nil];
[sound release];
sound = nil;
// Create a loader object to load and parse the mp3 from the application
// bundle.
loader = [[PXSoundLoader alloc] initWithContentsOfFile:@"sound.mp3"];
// Turn the loaded data to an AVAudio sound
PXSound *sound = [loader newSound];
// The loader is no longer needed
[loader release];
loader = nil;
// Create a PXSoundChannel object to play the sound
PXSoundChannel *channel = [sound playWithStartTime:0 loopCount:0 soundTransform:nil];
[sound release];
sound = nil;
Tasks
Other Methods
-
modifierA modifier is used to modify the loaded bytes, a backup is kept so can set this to
propertynilafter getting a new sound, and still have your previously loaded data. -
– initWithContentsOfFile:modifier:Creates a new PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported. -
– initWithContentsOfURL:modifier:Creates a new PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported. -
– newSoundCreates a new PXSound object containing all information needed to play the sound.
-
+ soundLoaderWithContentsOfFile:modifier:Creates a PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported. -
+ soundLoaderWithContentsOfURL:Creates a PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported. -
+ soundLoaderWithContentsOfURL:modifier:Creates a PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported.
Other Methods
-
– initWithContentsOfFile:Creates a new PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported.
Other Methods
-
– initWithContentsOfURL:Creates a new PXSoundLoader object containing the loaded sound data. Returns
nilif the file could not be found, or the file type isn’t supported.
Class Methods
soundLoaderWithContentsOfFile:modifier:
Creates a PXSoundLoader object containing the loaded sound data. Returns
nil if the file could not be found, or the file type isn’t
supported.
+ (PXSoundLoader *)soundLoaderWithContentsOfFile:(NSString *)path modifier:(id<PXSoundModifier>)modifierParameters
- modifier
If a modifier is stated, it will be used on the loaded bytes to modify them.
- filePath
The path of the sound file to load. The file path may be absolute or relative to the application bundle.
Return Value
The resulting, autoreleased, PXSoundLoader object.
Example:
PXSoundLoader *loader = [PXSoundLoader soundLoaderWithContentsOfFile:@"sound.wav" modifier:[PXSoundModifiers soundModifierToMono]];
// Loads the wav sound and converts it to mono if it is not.
Declared In
PXSoundLoader.msoundLoaderWithContentsOfURL:
Creates a PXSoundLoader object containing the loaded sound data. Returns
nil if the file could not be found, or the file type isn’t
supported.
+ (PXSoundLoader *)soundLoaderWithContentsOfURL:(NSURL *)urlParameters
- url
The url of the sound file to load.
Return Value
The resulting, autoreleased, PXSoundLoader object.
Example:
NSURL *url = [NSURL URLWithString:@"www.website.com/sound.wav"];
PXSoundLoader *loader = [PXSoundLoader soundLoaderWithContentsOfURL:url];
// Loads the wav sound.
Declared In
PXSoundLoader.msoundLoaderWithContentsOfURL:modifier:
Creates a PXSoundLoader object containing the loaded sound data. Returns
nil if the file could not be found, or the file type isn’t
supported.
+ (PXSoundLoader *)soundLoaderWithContentsOfURL:(NSURL *)url modifier:(id<PXSoundModifier>)modifierParameters
- url
The url of the sound file to load.
- modifier
If a modifier is stated, it will be used on the loaded bytes to modify them.
Return Value
The resulting, autoreleased, PXSoundLoader object.
Example:
NSURL *url = [NSURL URLWithString:@"www.website.com/sound.wav"];
PXSoundLoader *loader = [PXSoundLoader soundLoaderWithContentsOfURL:url modifier:[PXSoundModifiers soundModifierToMono]];
// Loads the wav sound and converts it to mono if it is not.
Declared In
PXSoundLoader.mInstance Methods
initWithContentsOfFile:
Creates a new PXSoundLoader object containing the loaded sound data.
Returns nil if the file could not be found, or the file type
isn’t supported.
- (id)initWithContentsOfFile:(NSString *)pathParameters
- filePath
The path of the sound file to load. The file path may be absolute or relative to the application bundle.
Example:
PXSoundLoader *loader = [[PXSoundLoader alloc] initWithContentsOfFile:@"sound.wav"]; // Loads the wav sound.
Declared In
PXSoundLoader.minitWithContentsOfFile:modifier:
Creates a new PXSoundLoader object containing the loaded sound data.
Returns nil if the file could not be found, or the file type
isn’t supported.
- (id)initWithContentsOfFile:(NSString *)path modifier:(id<PXSoundModifier>)_modifierParameters
- modifier
If a modifier is stated, it will be used on the loaded bytes to modify them.
Example:
PXSoundLoader *loader = [[PXSoundLoader alloc] initWithContentsOfFile:@"sound.wav" modifier:[PXSoundModifiers soundModifierToMono]]; // Loads the wav sound and converts it to mono if it is not.
- filePath
The path of the sound file to load. The file path may be absolute or relative to the application bundle.
Declared In
PXSoundLoader.minitWithContentsOfURL:
Creates a new PXSoundLoader object containing the loaded sound data.
Returns nil if the file could not be found, or the file type
isn’t supported.
- (id)initWithContentsOfURL:(NSURL *)urlParameters
- url
The url of the sound file to load.
Example:
NSURL *url = [NSURL URLWithString:@"www.website.com/sound.wav"]; PXSoundLoader *loader = [[PXSoundLoader alloc] initWithContentsOfURL:url]; // Loads the wav sound.
Declared In
PXSoundLoader.minitWithContentsOfURL:modifier:
Creates a new PXSoundLoader object containing the loaded sound data.
Returns nil if the file could not be found, or the file type
isn’t supported.
- (id)initWithContentsOfURL:(NSURL *)url modifier:(id<PXSoundModifier>)_modifierParameters
- url
The url of the sound file to load.
- modifier
If a modifier is stated, it will be used on the loaded bytes to modify them.
Example:
NSURL *url = [NSURL URLWithString:@"www.website.com/sound.wav"]; PXSoundLoader *loader = [[PXSoundLoader alloc] initWithContentsOfURL:url modifier:[PXSoundModifiers soundModifierToMono]]; // Loads the wav sound and converts it to mono if it is not.
Declared In
PXSoundLoader.m