Packagecom.anttikupila.media
Classpublic class SoundFX
InheritanceSoundFX Inheritance flash.media.Sound

Provides an easy way to transform audio output in real time with a syntax familiar from display object filters

     var sound : SoundFX = new SoundFX( new URLRequest( "music.mp3" ) );
     sound.filters = [ new CutoffFilter( 12000 ) ];
     sound.play( );
     

SoundFX also provides greated control over buffering and precise seeking

     var sound : SoundFX = new SoundFX( null, null, 3 ); // 3 seconds need to be loaded before playback starts
     sound.load( new URLRequest( "music.mp3" ) );
     sound.play( );
     // a bit later..
     sound.position = 3.12312;
     



Public Properties
 PropertyDefined By
  filters : Array
Indexed array of filters to process the audio through before output
SoundFX
  isBuffering : Boolean
[read-only]
SoundFX
  networkBuffer : Number
Amount of seconds that need to be buffered before sound will start playing
SoundFX
  outputBuffer : Number
Output buffer size
SoundFX
  paused : Boolean
Specifies if the track is paused.
SoundFX
  position : Number
Current playhead position
SoundFX
Public Methods
 MethodDefined By
  
SoundFX(stream:URLRequest = null, context:SoundLoaderContext = null, networkBufferSeconds:Number, outputBufferLength:int)
SoundFX
  
getLength():Number
Return an estimated length based on currently loaded bytes While the result isn't exactly correct it is useful for showing progress of the playing track, dividing SoundFX.position with SoundFX.getLenght()
SoundFX
  
load(stream:URLRequest, context:SoundLoaderContext = null):void
SoundFX
  
play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null):SoundChannel
Starts playing the sound Note: unlike flash.media.Sound play() does not return a SoundChannel
SoundFX
Protected Methods
 MethodDefined By
  
bufferTimerHandler(event:TimerEvent):void
SoundFX
  
soundCompleteHandler(event:Event):void
SoundFX
Public Constants
 ConstantDefined By
  DEFAULT_NETWORK_BUFFER : Number = 1
[static]
SoundFX
  DEFAULT_OUTPUT_BUFFER : int = 2048
[static]
SoundFX
  SAMPLE_RATE : int = 44100
[static]
SoundFX
Property Detail
filtersproperty
filters:Array  [read-write]

Indexed array of filters to process the audio through before output


Implementation
    public function get filters():Array
    public function set filters(value:Array):void
isBufferingproperty 
isBuffering:Boolean  [read-only]


Implementation
    public function get isBuffering():Boolean
networkBufferproperty 
networkBuffer:Number  [read-write]

Amount of seconds that need to be buffered before sound will start playing


Implementation
    public function get networkBuffer():Number
    public function set networkBuffer(value:Number):void
outputBufferproperty 
outputBuffer:Number  [read-write]

Output buffer size


Implementation
    public function get outputBuffer():Number
    public function set outputBuffer(value:Number):void
pausedproperty 
paused:Boolean  [read-write]

Specifies if the track is paused. Unlike stopping a track pausing it will continue to process filters without advancing the playhead.


Implementation
    public function get paused():Boolean
    public function set paused(value:Boolean):void
positionproperty 
position:Number  [read-write]

Current playhead position


Implementation
    public function get position():Number
    public function set position(value:Number):void
Constructor Detail
SoundFX()Constructor
public function SoundFX(stream:URLRequest = null, context:SoundLoaderContext = null, networkBufferSeconds:Number, outputBufferLength:int)

Parameters
stream:URLRequest (default = null) — File to load
 
context:SoundLoaderContext (default = null) — Context
 
networkBufferSeconds:Number (default = NaN) — Network buffer in seconds. Similar to the buffer in NetStream
 
outputBufferLength:int (default = NaN) — Output buffer in samples. If the output is choppy even if the network is smooth try increasing the output buffer
Method Detail
bufferTimerHandler()method
protected function bufferTimerHandler(event:TimerEvent):void

Parameters

event:TimerEvent

getLength()method 
public function getLength():Number

Return an estimated length based on currently loaded bytes

While the result isn't exactly correct it is useful for showing progress of the playing track, dividing SoundFX.position with SoundFX.getLenght()

Returns
Number — An estimated length

See also

load()method 
override public function load(stream:URLRequest, context:SoundLoaderContext = null):void

Parameters

stream:URLRequest
 
context:SoundLoaderContext (default = null)

See also

flash.media.Sound.load()
play()method 
override public function play(startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null):SoundChannel

Starts playing the sound

Note: unlike flash.media.Sound play() does not return a SoundChannel

Parameters

startTime:Number (default = 0) — Start time in seconds
 
loops:int (default = 0) — Number of loops
 
sndTransform:SoundTransform (default = null) — Sound transform

Returns
SoundChannel — null
soundCompleteHandler()method 
protected function soundCompleteHandler(event:Event):void

Parameters

event:Event

Constant Detail
DEFAULT_NETWORK_BUFFERConstant
public static const DEFAULT_NETWORK_BUFFER:Number = 1

DEFAULT_OUTPUT_BUFFERConstant 
public static const DEFAULT_OUTPUT_BUFFER:int = 2048

SAMPLE_RATEConstant 
public static const SAMPLE_RATE:int = 44100