Packageorg.as3wavsound
Classpublic class WavSound
InheritanceWavSound Inheritance Object

Sound extension that directly plays WAVE data. Also backwards compatible with MP3's played through the load() function. This class acts as facade to loading, extracting, decoding and playing wav sound data and represents a single sound. This class is analog to Adobe's Sound class and is designed to function the same way. Usage: Simply embed .wav files as you would mp3's and play with this Sound class. Make sure you provide mimetype 'application/octet-stream' when embedding to ensure Flash embeds the data as ByteArray. Example: [Embed(source = "drumloop.wav", mimeType = "application/octet-stream")] public const DrumLoop:Class; public const rain:WavSound = new WavSound(new DrumLoop() as ByteArray);



Public Properties
 PropertyDefined By
  bytesLoaded : uint
[read-only] Returns the total bytes of the wavData a WavSound was created with.
WavSound
  bytesTotal : int
[read-only] Returns the total bytes of the wavData a WavSound was created with.
WavSound
  length : Number
[read-only] Returns the total length of the sound in milliseconds.
WavSound
  playbackSettings : AudioSetting
[read-only] _playbackSettings is set when the load() function is called.
WavSound
  samples : AudioSamples
[read-only]
WavSound
Public Methods
 MethodDefined By
  
WavSound(wavData:ByteArray, audioSettings:AudioSetting = null)
Constructor: loads wavdata using load().
WavSound
  
extract(target:ByteArray, length:Number, startPosition:Number = -1):Number
No idea if this works.
WavSound
  
load(wavData:ByteArray, audioSettings:AudioSetting = null):void
Key function: loads WAVE data and decodes it into playable samples.
WavSound
  
play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null):WavSoundChannel
See Adobe's Sound.play(): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#play().
WavSound
Property Detail
bytesLoadedproperty
bytesLoaded:uint  [read-only]

Returns the total bytes of the wavData a WavSound was created with. Note: This function is probably legacy, since we're not extending Adobe's Sound anymore (backwards compatibility was dropped in v0.7.


Implementation
    public function get bytesLoaded():uint
bytesTotalproperty 
bytesTotal:int  [read-only]

Returns the total bytes of the wavData a WavSound was created with. Note: This function is probably legacy, since we're not extending Adobe's Sound anymore (backwards compatibility was dropped in v0.7.


Implementation
    public function get bytesTotal():int
lengthproperty 
length:Number  [read-only]

Returns the total length of the sound in milliseconds.


Implementation
    public function get length():Number
playbackSettingsproperty 
playbackSettings:AudioSetting  [read-only]

_playbackSettings is set when the load() function is called.


Implementation
    public function get playbackSettings():AudioSetting
samplesproperty 
samples:AudioSamples  [read-only]


Implementation
    public function get samples():AudioSamples
Constructor Detail
WavSound()Constructor
public function WavSound(wavData:ByteArray, audioSettings:AudioSetting = null)

Constructor: loads wavdata using load(). loads WAVE data and decodes it into playable samples. Finally calculates the length of the sound in milliseconds.

Parameters
wavData:ByteArray — A ByteArray containing uncmopressed wav data.
 
audioSettings:AudioSetting (default = null) — An optional playback configuration (mono/stereo, sample rate and bit rate).
Method Detail
extract()method
public function extract(target:ByteArray, length:Number, startPosition:Number = -1):Number

No idea if this works. Alpha state. Read up on Sound.extract(): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#extract() Apparently, some people have used this succesfully, see comment 1 on Issue 11: http://code.google.com/p/as3wavsound/issues/detail?id=11#c1

Parameters

target:ByteArray
 
length:Number
 
startPosition:Number (default = -1)

Returns
Number
load()method 
public function load(wavData:ByteArray, audioSettings:AudioSetting = null):void

Key function: loads WAVE data and decodes it into playable samples. Finally calculates the length of the sound in milliseconds.

Parameters

wavData:ByteArray — The byte array that is the embedded .was file (octet-stream).
 
audioSettings:AudioSetting (default = null) — Optional settings for playback (samplerate will enforced if it differs from the .wav header data or header is missing).

See also

Wav.decode(ByteArray)
play()method 
public function play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null):WavSoundChannel

See Adobe's Sound.play(): http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#play(). Playback function that performs the following tasks: - calculates the startingPhase, bases on startTime in ms. - initializes loopsLeft variable - adds the playing channel in combination with its originating WavSound to the playingWavSounds

Parameters

startTime:Number (default = 0) — The starting time in milliseconds, applies to each loop (as with regular MP3 Sounds).
 
loops:int (default = 0) — The number of loops to take in dditionto the default playback (loops == 2 means 3 playthroughs).
 
sndTransform:SoundTransform (default = null) — An optional soundtransform to apply for playback that controls volume and panning.

Returns
WavSoundChannel — The SoundChannel used for playing back the sound (and stopping the sound).