com.flagstone.transform
Class FSSound

java.lang.Object
  extended by com.flagstone.transform.FSTransformObject
      extended by com.flagstone.transform.FSSound
All Implemented Interfaces:
java.lang.Cloneable

public class FSSound
extends FSTransformObject

The FSSound class identifies a sound (previously defined using The FSDefineSound class) and controls how it is played.

FSSound defines how the sound fades in and out, whether it is repeated as well as specifying an envelope that provides a finer degree of control over the levels at which the sound is played.

Attributes
identifier The identifier, in the range 1..65535, of the FSDefineSound object that contains the sound data.
mode Controls how the sound is played, either: Start - start playing the sound, Continue - start playing the sound if it is not already playing and Stop - stop playing the sound.
inPoint The sample number that the sound increases in volume to until full volume is reached. Optional. Set to 0 if the sound does not fade in.
outPoint The sample number at which the that the sound starts to fades until the sound has finished playing. Optional. Set to 0 if the sound does not fade out.
loopCount The number of times the sound is repeated. Optional. Must be at least 1 if a sound is being played. Set to 0 if a sound is being stopped.
envelopes An array of FSEnvelope objects that control how the sound is played. Optional. May be set to null or an empty array if no envelope is defined.

Not all the attributes are required to play a sound. Only the identifier and the mode is required. The other attributes are optional and may be added as a greater degree of control is required. The inPoint and outPoint attributes may be set to zero if the sound does not fade in or out respectively. The loopCount may be set to zero if a sound is being stopped. The envelopes array may be left empty if no envelope is defined for the sound. The class provides different constructors to specify different sets of attributes.

The in and out point specify the sample number which marks the point in time at which the sound stops increasing or starts decreasing in volume respectively. Sounds are played by the Flash player at 44.1KHz so the sample number also indicates the time when the total number of samples in the sound is taken into account.

History

The FSSound class is based on the SoundInfo data structure from the Macromedia Flash (SWF) File Format Specification. However it also contains the identifier for the sound which is a separate attribute in the data structures defined in the specification that contain SoundInfo data.


Field Summary
static int ADPCM
          Identifies an adaptive pulse code modulated sound.
static int Continue
          Start playing the sound or continues if it is already playing.
static int MP3
          Identifies an MP3 format sound.
static int NATIVE_PCM
          Identifies an uncompressed pulse code modulated sound.
static int NELLYMOSER
           
static int PCM
          Identifies an uncompressed pulse code modulated sound, little-endian byte order.
static int Start
          Start playing the sound.
static int Stop
          Stop playing the sound.
 
Constructor Summary
FSSound(FSCoder coder)
          Construct an FSSound object, initalizing it with values decoded from an encoded object.
FSSound(FSSound obj)
          Constructs an FSSound object by copying values from an existing object.
FSSound(int anIdentifier, int aMode)
          Constructs an FSSound object specifying how the sound is played.
FSSound(int anIdentifier, int aMode, int aCount)
          Constructs and FSSound object specifying how the sound is played and the number of times the sound is repeated.
FSSound(int anIdentifier, int aMode, int anInPoint, int anOutPoint)
          Constructs and FSSound object specifying how the sound is played and the points at which the sound fades in and out.
FSSound(int anIdentifier, int aMode, int anInPoint, int anOutPoint, int aCount)
          Constructs and FSSound object specifying how the sound is played, the point at which the sound fades in and out and the number of times the sound is repeated.
FSSound(int anIdentifier, int aMode, int anInPoint, int anOutPoint, int aCount, java.util.ArrayList anArray)
          Constructs and FSSound object specifying how the sound is played, the point at which the sound fades in and out, the number of times the sound is repeated and the envelopes used to control how the sound is played.
 
Method Summary
 void add(FSEnvelope anEnvelope)
          Add a FSEnvelope object to the array of envelope objects.
 void appendDescription(java.lang.StringBuffer buffer, int depth)
          AppendDescription is used to present a string description of the object including all nested objects up to a specified depth.
 java.lang.Object clone()
          Creates a deep copy of the entire object.
 void decode(FSCoder coder)
           
 void encode(FSCoder coder)
           
 boolean equals(java.lang.Object anObject)
          Returns true if anObject is equal to this one.
 java.util.ArrayList getEnvelopes()
          Gets the array of FSEnvelope objects that control the levels the sound is played.
 int getIdentifier()
          Gets the identifier of the sound to the played.
 int getInPoint()
          Gets the sample number at which the sound reaches full volume when fading in.
 int getLoopCount()
          Gets the number of times the sound will be repeated.
 int getMode()
          Gets the synchronisation mode: SyncNoMultiple - do not play the sound if it is already playing and SyncStop - stop playing the sound.
 int getOutPoint()
          Gets the sample number at which the sound starts to fade.
 int length(FSCoder coder)
           
 void setEnvelopes(java.util.ArrayList anArray)
          Sets the array of FSEnvelope objects that define the levels at which a sound is played over the duration of the sound.
 void setIdentifier(int anIdentifier)
          Sets the identifier of the sound to the played.
 void setInPoint(int aNumber)
          Sets the sample number at which the sound reaches full volume when fading in.
 void setLoopCount(int aNumber)
          Sets the number of times the sound is repeated.
 void setMode(int aMode)
          Sets how the sound is synchronised when the frames are displayed: Start - start playing the sound, Continue - do not play the sound if it is already playing and Stop - stop playing the sound.
 void setOutPoint(int aNumber)
          Sets the sample number at which the sound starts to fade.
 
Methods inherited from class com.flagstone.transform.FSTransformObject
name, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NATIVE_PCM

public static final int NATIVE_PCM
Identifies an uncompressed pulse code modulated sound. The byte-order for 16-bit sound samples is dependent on the host platform on which the sound is played.

See Also:
Constant Field Values

ADPCM

public static final int ADPCM
Identifies an adaptive pulse code modulated sound.

See Also:
Constant Field Values

MP3

public static final int MP3
Identifies an MP3 format sound.

See Also:
Constant Field Values

PCM

public static final int PCM
Identifies an uncompressed pulse code modulated sound, little-endian byte order.

See Also:
Constant Field Values

NELLYMOSER

public static final int NELLYMOSER
See Also:
Constant Field Values

Start

public static final int Start
Start playing the sound.

See Also:
Constant Field Values

Continue

public static final int Continue
Start playing the sound or continues if it is already playing.

See Also:
Constant Field Values

Stop

public static final int Stop
Stop playing the sound.

See Also:
Constant Field Values
Constructor Detail

FSSound

public FSSound(FSCoder coder)
Construct an FSSound object, initalizing it with values decoded from an encoded object.

Parameters:
coder - an FSCoder containing the binary data.

FSSound

public FSSound(int anIdentifier,
               int aMode)
Constructs an FSSound object specifying how the sound is played.

Parameters:
anIdentifier - the unique identifier of the object that contains the sound data.
aMode - how the sound is synchronised when the frames are displayed: Start - start playing the sound, Continue - do not play the sound if it is already playing and Stop - stop playing the sound.

FSSound

public FSSound(int anIdentifier,
               int aMode,
               int aCount)
Constructs and FSSound object specifying how the sound is played and the number of times the sound is repeated.

Parameters:
anIdentifier - the unique identifier of the object that contains the sound data.
aMode - how the sound is synchronised when the frames are displayed: Play - do not play the sound if it is already playing and Stop - stop playing the sound.
aCount - the number of times the sound is repeated. May be set to zero if the sound will not be repeated.

FSSound

public FSSound(int anIdentifier,
               int aMode,
               int anInPoint,
               int anOutPoint)
Constructs and FSSound object specifying how the sound is played and the points at which the sound fades in and out.

Parameters:
anIdentifier - the unique identifier of the object that contains the sound data.
aMode - how the sound is synchronised when the frames are displayed: Play - do not play the sound if it is already playing and Stop - stop playing the sound.
anInPoint - the sample number which the sound fades in to. May be set to zero if the sound does not fade in.
anOutPoint - the sample number at which the sound starts to fade. May be set to zero if the sound does not fade out.

FSSound

public FSSound(int anIdentifier,
               int aMode,
               int anInPoint,
               int anOutPoint,
               int aCount)
Constructs and FSSound object specifying how the sound is played, the point at which the sound fades in and out and the number of times the sound is repeated.

Parameters:
anIdentifier - the unique identifier of the object that contains the sound data.
aMode - how the sound is synchronised when the frames are displayed: Play - do not play the sound if it is already playing and Stop - stop playing the sound.
anInPoint - the sample number which the sound fades in to. May be set to zero if the sound does not fade in.
anOutPoint - the sample number at which the sound starts to fade. May be set to zero if the sound does not fade out.
aCount - the number of times the sound is repeated. May be set to zero if the sound will not be repeated.

FSSound

public FSSound(int anIdentifier,
               int aMode,
               int anInPoint,
               int anOutPoint,
               int aCount,
               java.util.ArrayList anArray)
Constructs and FSSound object specifying how the sound is played, the point at which the sound fades in and out, the number of times the sound is repeated and the envelopes used to control how the sound is played.

Parameters:
anIdentifier - the unique identifier of the object that contains the sound data.
aMode - how the sound is synchronised when the frames are displayed: Play - do not play the sound if it is already playing and Stop - stop playing the sound.
anInPoint - the sample number which the sound fades in to. May be set to zero if the sound does not fade in.
anOutPoint - the sample number at which the sound starts to fade. May be set to zero if the sound does not fade out.
aCount - the number of times the sound is repeated. May be set to zero if the sound will not be repeated.
anArray - an array of FSEnvelope objects that define the levels at which a sound is played over the duration of the sound. May be set to NULL if no envelope is defined.

FSSound

public FSSound(FSSound obj)
Constructs an FSSound object by copying values from an existing object.

Parameters:
obj - an FSSound object.
Method Detail

add

public void add(FSEnvelope anEnvelope)
Add a FSEnvelope object to the array of envelope objects.

Parameters:
anEnvelope - an FSEnvelope object.

getIdentifier

public int getIdentifier()
Gets the identifier of the sound to the played.

Returns:
the sound identifier.

getMode

public int getMode()
Gets the synchronisation mode: SyncNoMultiple - do not play the sound if it is already playing and SyncStop - stop playing the sound.

Returns:
the synchronisation mode of the sound.

getInPoint

public int getInPoint()
Gets the sample number at which the sound reaches full volume when fading in.

Returns:
the in point

getOutPoint

public int getOutPoint()
Gets the sample number at which the sound starts to fade.

Returns:
the out point

getLoopCount

public int getLoopCount()
Gets the number of times the sound will be repeated.

Returns:
the Loop Count.

getEnvelopes

public java.util.ArrayList getEnvelopes()
Gets the array of FSEnvelope objects that control the levels the sound is played.

Returns:
an array of FSEnvelope objects.

setIdentifier

public void setIdentifier(int anIdentifier)
Sets the identifier of the sound to the played.

Parameters:
anIdentifier - the identifier for the sound to be played.

setMode

public void setMode(int aMode)
Sets how the sound is synchronised when the frames are displayed: Start - start playing the sound, Continue - do not play the sound if it is already playing and Stop - stop playing the sound.

Parameters:
aMode - how the sound is played.

setInPoint

public void setInPoint(int aNumber)
Sets the sample number at which the sound reaches full volume when fading in. May be set to zero if the sound does not fade in.

Parameters:
aNumber - the sample number which the sound fades in to.

setOutPoint

public void setOutPoint(int aNumber)
Sets the sample number at which the sound starts to fade. May be set to zero if the sound does not fade out.

Parameters:
aNumber - the sample number at which the sound starts to fade.

setLoopCount

public void setLoopCount(int aNumber)
Sets the number of times the sound is repeated. May be set to zero if the sound will not be repeated.

Parameters:
aNumber - the number of times the sound is repeated.

setEnvelopes

public void setEnvelopes(java.util.ArrayList anArray)
Sets the array of FSEnvelope objects that define the levels at which a sound is played over the duration of the sound. May be set to null if no envelope is defined.

Parameters:
anArray - an array of FSEnvelope objects.

clone

public java.lang.Object clone()
Description copied from class: FSTransformObject
Creates a deep copy of the entire object.

Overrides:
clone in class FSTransformObject
Returns:
a copy of the object.

equals

public boolean equals(java.lang.Object anObject)
Description copied from class: FSTransformObject
Returns true if anObject is equal to this one. Objects are considered equal if they would generate identical binary data when they are encoded to a Flash file.

Overrides:
equals in class FSTransformObject
Returns:
true if this object would be identical to anObject when encoded.

appendDescription

public void appendDescription(java.lang.StringBuffer buffer,
                              int depth)
Description copied from class: FSTransformObject
AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. This method provide a more controlled way of creating a string representation of an object since large objects such as font or shape definitions can contain dozens of nested objects. The representation of the object is appended to the StringBuffer, showing the name of the class and values of the attributes it contains. If the object contains any attributes that are objects then the object graph will be traversed up to the specified depth. If objects are nested at a level less than specified depth then the full string representation of the object is displayed. For objects at the specified depth only the name of the class is displayed. Any objects below this depth are not displayed.

Specified by:
appendDescription in class FSTransformObject
Parameters:
buffer - a StringBuffer to which the description of each object is appended.
depth - the maximum level of nesting up to which objects will be displayed.

length

public int length(FSCoder coder)
Specified by:
length in class FSTransformObject

encode

public void encode(FSCoder coder)
Specified by:
encode in class FSTransformObject

decode

public void decode(FSCoder coder)
Specified by:
decode in class FSTransformObject