PXSound Class Reference
| 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
-
lengthThe length, in milliseconds, of the sound.
property -
is3DReadyIf the sound is mono and of file type “wav” or “caf” then it is considered to be 3D ready.
property -
– initWithData:Creates a sound using the data given. The data is parsed into a usable format.
-
– initWithData:modifier:Creates a sound using the data given. The data is parsed into a usable format.
-
– playPlays a sound from the start, doesn’t loop and has a volume and pitch of 1.0f.
-
– playWithStartTime:loopCount:soundTransform:Plays a sound from the start, doesn’t loop and has a volume and pitch of 1.0f.
-
+ soundWithContentsOfFile:Creates a sound by loading the file at the given path.
-
+ soundWithContentsOfFile:modifier:Creates a sound by loading the file at the given path.
-
+ soundWithContentsOfURL:Creates a sound by loading the file at the given url.
-
+ soundWithContentsOfURL:modifier:Creates a sound by loading the file at the given url.
-
+ soundWithData:Creates a sound by parsing the data.
-
+ soundWithData:modifier:Creates a sound by parsing the data.
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 is3DReadyDiscussion
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.hClass Methods
soundWithContentsOfFile:
Creates a sound by loading the file at the given path.
+ (PXSound *)soundWithContentsOfFile:(NSString *)pathParameters
- 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.msoundWithContentsOfFile:modifier:
Creates a sound by loading the file at the given path.
+ (PXSound *)soundWithContentsOfFile:(NSString *)path modifier:(id<PXSoundModifier>)modifierParameters
- 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.msoundWithContentsOfURL:
Creates a sound by loading the file at the given url.
+ (PXSound *)soundWithContentsOfURL:(NSURL *)urlParameters
- 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.msoundWithContentsOfURL:modifier:
Creates a sound by loading the file at the given url.
+ (PXSound *)soundWithContentsOfURL:(NSURL *)url modifier:(id<PXSoundModifier>)modifierParameters
- 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.msoundWithData:
Creates a sound by parsing the data.
+ (PXSound *)soundWithData:(NSData *)dataParameters
- 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.msoundWithData:modifier:
Creates a sound by parsing the data.
+ (PXSound *)soundWithData:(NSData *)data modifier:(id<PXSoundModifier>)modifierParameters
- 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.mInstance Methods
initWithData:
Creates a sound using the data given. The data is parsed into a usable format.
- (id)initWithData:(NSData *)dataParameters
- 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.minitWithData:modifier:
Creates a sound using the data given. The data is parsed into a usable format.
- (id)initWithData:(NSData *)data modifier:(id<PXSoundModifier>)modifierParameters
- 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.mplay
Plays a sound from the start, doesn’t loop and has a volume and pitch of 1.0f.
- (PXSoundChannel *)playReturn 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.mplayWithStartTime: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 *)soundTransformParameters
- 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_LOOPSis 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];
See Also
Declared In
PXSound.m