com.flagstone.transform.sound
Class SoundInfo

java.lang.Object
  extended by com.flagstone.transform.sound.SoundInfo
All Implemented Interfaces:
Copyable<SoundInfo>, SWFEncodeable

public final class SoundInfo
extends Object
implements SWFEncodeable, Copyable<SoundInfo>

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

SoundInfo 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.

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.

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 may be left empty if no envelope is defined for the sound. The class provides different constructors to specify different sets of attributes.

See Also:
DefineSound

Nested Class Summary
static class SoundInfo.Mode
          Mode describes how the sound is controlled.
 
Constructor Summary
SoundInfo(int uid, SoundInfo.Mode aMode, int aCount, Envelope anEnvelope)
          Creates a Sound object specifying how the sound is played and the number of times the sound is repeated.
SoundInfo(int uid, SWFDecoder coder)
          Creates and initialises a SoundInfo object using values encoded in the Flash binary format.
SoundInfo(SoundInfo object)
          Creates and initialises a SoundInfo object using the values copied from another SoundInfo object.
 
Method Summary
 SoundInfo copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 Envelope getEnvelope()
          Get the Envelope that control the levels the sound is played.
 int getIdentifier()
          Get the identifier of the sound to the played.
 Integer getInPoint()
          Get the sample number at which the sound reaches full volume when fading in.
 Integer getLoopCount()
          Get the number of times the sound will be repeated.
 SoundInfo.Mode getMode()
          Get the synchronisation mode: START - start playing the sound, CONTINUE - do not play the sound if it is already playing and STOP - stop playing the sound.
 Integer getOutPoint()
          Get the sample number at which the sound starts to fade.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setEnvelope(Envelope anEnvelope)
          Sets the Envelope that define the levels at which a sound is played over the duration of the sound.
 void setIdentifier(int uid)
          Sets the identifier of the sound to the played.
 void setInPoint(Integer aNumber)
          Sets the sample number at which the sound reaches full volume when fading in.
 void setLoopCount(Integer aNumber)
          Sets the number of times the sound is repeated.
 void setMode(SoundInfo.Mode soundMode)
          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(Integer aNumber)
          Sets the sample number at which the sound starts to fade.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SoundInfo

public SoundInfo(int uid,
                 SWFDecoder coder)
          throws IOException
Creates and initialises a SoundInfo object using values encoded in the Flash binary format.

Parameters:
uid - the unique identifier for the sound definition - decoded by the parent object.
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

SoundInfo

public SoundInfo(int uid,
                 SoundInfo.Mode aMode,
                 int aCount,
                 Envelope anEnvelope)
Creates a Sound object specifying how the sound is played and the number of times the sound is repeated.

Parameters:
uid - 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.
anEnvelope - the Envelope that control the levels the sound is played.

SoundInfo

public SoundInfo(SoundInfo object)
Creates and initialises a SoundInfo object using the values copied from another SoundInfo object.

Parameters:
object - a SoundInfo object from which the values will be copied.
Method Detail

getIdentifier

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

Returns:
the unique identifier of the sound.

getMode

public SoundInfo.Mode getMode()
Get the synchronisation mode: START - start playing the sound, CONTINUE - do not play the sound if it is already playing and STOP - stop playing the sound.

Returns:
the sound synchronisation mode.

getInPoint

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

Returns:
the fade in point.

getOutPoint

public Integer getOutPoint()
Get the sample number at which the sound starts to fade.

Returns:
the fade out point.

getLoopCount

public Integer getLoopCount()
Get the number of times the sound will be repeated.

Returns:
the number of loops.

getEnvelope

public Envelope getEnvelope()
Get the Envelope that control the levels the sound is played.

Returns:
the sound envelope.

setIdentifier

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

Parameters:
uid - the identifier for the sound to be played. Must be in the range 1..65535.

setMode

public void setMode(SoundInfo.Mode soundMode)
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:
soundMode - how the sound is played.

setInPoint

public void setInPoint(Integer 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(Integer 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(Integer 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.

setEnvelope

public void setEnvelope(Envelope anEnvelope)
Sets the Envelope 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:
anEnvelope - an Envelope object.

copy

public SoundInfo copy()
Creates a complete copy of this object.

Specified by:
copy in interface Copyable<SoundInfo>
Returns:
a deep-copy of this object. New instances of mutable objects are copied and immutable instances are shared.

toString

public String toString()
Overrides:
toString in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.