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

  •   modifier

    A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

    property
  • – initWithContentsOfFile: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.

  • – initWithContentsOfURL: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.

  • – newSound

    Creates a new PXSound object containing all information needed to play the sound.

  • + 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.

  • + soundLoaderWithContentsOfURL:

    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.

  • + soundLoaderWithContentsOfURL: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.

Other 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.

Other Methods

  • – initWithContentsOfURL:

    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.

Properties

modifier

A modifier is used to modify the loaded bytes, a backup is kept so can set this to nil after getting a new sound, and still have your previously loaded data.

@property (nonatomic, retain) id<PXSoundModifier> modifier

Discussion

Default: nil

Declared In

PXSoundLoader.h

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>)modifier

Parameters

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.m

soundLoaderWithContentsOfURL:

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

Parameters

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.m

soundLoaderWithContentsOfURL: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>)modifier

Parameters

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.m

Instance 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 *)path

Parameters

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.m

initWithContentsOfFile: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>)_modifier

Parameters

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.m

initWithContentsOfURL:

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

Parameters

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.m

initWithContentsOfURL: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>)_modifier

Parameters

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

newSound

Creates a new PXSound object containing all information needed to play the sound.

- (PXSound *)newSound

Return Value

The new PXSound object.

Declared In

PXSoundLoader.m