Inherits from NSObject
Declared in PXSound.h
PXSound.m

Overview

Represents a loaded sound. Sounds should never be initialized manually, but through a PXSoundLoader or this class’s utility creation methods.

Tasks

Properties

is3DReady

If the sound is mono and of file type “wav” or “caf” then it is considered to be 3D ready.

@property (nonatomic, readonly) BOOL is3DReady

Discussion

YES if the conditions for being 3D are met, NO otherwise.

Example:

PXSound *mp3Sound = [PXSound soundWithContentsOfFile:@"sound.mp3"];
[mp3Sound is3DReady];
// Will return NO.
PXSound *wavSound = [PXSound soundWithContentsOfFile:@"sound.wav"];
[wavSound is3DReady];
// Will return YES if the wav sound was mono.

Declared In

PXSound.h

length

The length, in milliseconds, of the sound.

@property (nonatomic, readonly) unsigned length

Declared In

PXSound.h

Class Methods

soundWithContentsOfFile:

Creates a sound by loading the file at the given path.

+ (PXSound *)soundWithContentsOfFile:(NSString *)path

Parameters

filePath

The path of the file.

Return Value

The loaded and parsed sound, if the sound fails loading then nil is returned instead.

Example:

PXSound *sound = [PXSound soundWithContentsOfFile:@"sound.wav"];
// Sound is loaded and ready to go.

Declared In

PXSound.m

soundWithContentsOfFile:modifier:

Creates a sound by loading the file at the given path.

+ (PXSound *)soundWithContentsOfFile:(NSString *)path modifier:(id<PXSoundModifier>)modifier

Parameters

modifier

The modifier is used to modify the loaded bytes; once set, it can not be un-done. The modifier will be ignored if the data is not modifiable.

filePath

The path of the file.

Return Value

The loaded and parsed sound, if the sound fails loading then nil is returned instead.

Example:

PXSound *sound = [PXSound soundWithContentsOfFile:@"sound.wav" modifier:[PXSoundModifiers soundModifierToMono]];
// Sound is loaded, converted to mono, and ready to go.

Declared In

PXSound.m

soundWithContentsOfURL:

Creates a sound by loading the file at the given url.

+ (PXSound *)soundWithContentsOfURL:(NSURL *)url

Parameters

url

The url of the file.

Return Value

The loaded and parsed sound, if the sound fails loading then nil is returned instead.

Example:

PXSound *sound = [PXSound soundWithContentsOfURL:@"www.mywebsite.com/sound.wav"];
// Sound is loaded and ready to go.

Declared In

PXSound.m

soundWithContentsOfURL:modifier:

Creates a sound by loading the file at the given url.

+ (PXSound *)soundWithContentsOfURL:(NSURL *)url modifier:(id<PXSoundModifier>)modifier

Parameters

url

The url of the file.

modifier

The modifier is used to modify the loaded bytes; once set, it can not be un-done. The modifier will be ignored if the data is not modifiable.

Return Value

The loaded and parsed sound, if the sound fails loading then nil is returned instead.

Example:

PXSound *sound = [PXSound soundWithContentsOfURL:@"www.mywebsite.com/sound.wav" modifier:[PXSoundModifiers soundModifierToMono]];
// Sound is loaded, converted to mono, and ready to go.

Declared In

PXSound.m

soundWithData:

Creates a sound by parsing the data.

+ (PXSound *)soundWithData:(NSData *)data

Parameters

data

The raw data.

Return Value

The loaded and parsed sound, if the sound fails loading then nil is returned instead.

Example:

NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sound.wav" ofType:nil]];
PXSound *sound = [PXSound soundWithData:data];
// Sound is parsed, converted to mono, and ready to go.

Declared In

PXSound.m

soundWithData:modifier:

Creates a sound by parsing the data.

+ (PXSound *)soundWithData:(NSData *)data modifier:(id<PXSoundModifier>)modifier

Parameters

data

The raw data.

modifier

The modifier is used to modify the loaded bytes; once set, it can not be un-done. The modifier will be ignored if the data is not modifiable.

Return Value

The loaded and parsed sound, if the sound fails loading then nil is returned instead.

Example:

NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sound.wav" ofType:nil]];
PXSound *sound = [PXSound soundWithData:data modifier:[PXSoundModifiers soundModifierToMono]];
// Sound is parsed, converted to mono, and ready to go.

Declared In

PXSound.m

Instance Methods

initWithData:

Creates a sound using the data given. The data is parsed into a usable format.

- (id)initWithData:(NSData *)data

Parameters

data

The raw data.

Return Value

The parsed sound.

Example:

NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sound.wav" ofType:nil]];
PXSound *sound = [[PXSound alloc] initWithData:data];
PXSoundChannel *channel = [sound play];
// The sound will begin playing, and channel will be your reference.

Declared In

PXSound.m

initWithData:modifier:

Creates a sound using the data given. The data is parsed into a usable format.

- (id)initWithData:(NSData *)data modifier:(id<PXSoundModifier>)modifier

Parameters

data

The raw data.

modifier

The modifier is used to modify the loaded bytes; once set, it can not be un-done. The modifier will be ignored if the data is not modifiable.

Return Value

The parsed sound.

Example:

NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sound.wav" ofType:nil]];
PXSound *sound = [[PXSound alloc] initWithData:data modifier:[PXSoundModifiers soundModifierToMono]];
PXSoundChannel *channel = [sound play];
// The sound will be converted to mono, then begin playing, and channel will
// be your reference.

Declared In

PXSound.m

play

Plays a sound from the start, doesn’t loop and has a volume and pitch of 1.0f.

- (PXSoundChannel *)play

Return Value

The reference to the sound channel that will be playing.

Example:

PXSound *sound = [PXSound soundWithContentsOfFile:@"sound.wav"];
PXSoundChannel *channel = [sound play];
// The sound will begin playing, and channel will be your reference.

Declared In

PXSound.m

playWithStartTime:loopCount:soundTransform:

Plays a sound from the start, doesn’t loop and has a volume and pitch of 1.0f.

- (PXSoundChannel *)playWithStartTime:(unsigned)startTime loopCount:(int)loopCount soundTransform:(PXSoundTransform *)soundTransform

Parameters

startTime

The time in milliseconds for the sound to begin. Each loop will also begin at this time. You should not set a start time for larger then the length of the sound.

loopCount

The quantity of times you wish the sound to loop. If 0 is stated, the sound only plays once. If 10 is stated, the sound plays 11 times. If PX_SOUND_INFINITE_LOOPS is stated, then the sound plays for infinate times.

soundTransform

The the transform for the sound.

Return Value

The reference to the sound channel that will be playing.

Example:

PXSoundLoader *soundLoader = [[PXSoundLoader alloc] initWithContentsOfFile:@"sound.wav"];
PXSound *sound = [soundLoader newSound];

PXSoundTransform3D *soundTransform3D = [[PXSoundTransform3D alloc] initWithVolume:1.2f pitch:0.8f];
soundTransform3D.x = 40.0f;
soundTransform3D.y = 15.0f;
// The sound can only be 3D if it is mono and the correct file type.  To
// check for this, you can use the is3DReady method.

PXSoundChannel *channel = [sound playWithStartTime:4500 loopCount:PX_SOUND_INFINITE_LOOPS soundTransform:soundTransform3D];
// The sound will begin at, and loop from, 4.5 seconds for an indefinite
// quantity of time.  It's volume will be 120% and pitch 80% at position
// [40.0f,15.0f,0.0f] with velocity [0.0f,0.0f,0.0f].

// Release the memory
[soundTransform3D release];
[soundLoader release];
[sound release];

Declared In

PXSound.m