com.flagstone.transform.sound
Class DefineSound

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

public final class DefineSound
extends Object
implements DefineTag

DefineSound is used to define a sound that will be played when a given event occurs.

Three different types of object are used to play an event sound:

Five encoded formats for the sound data are supported: NATIVE_PCM, PCM, ADPCM, MP3 and NELLYMOSER.

See Also:
SoundInfo, StartSound

Constructor Summary
DefineSound(DefineSound object)
          Creates and initialises a DefineSound object using the values copied from another DefineSound object.
DefineSound(int uid, SoundFormat aFormat, int playbackRate, int channels, int size, int count, byte[] bytes)
          Creates a DefineSound object specifying the unique identifier and all the parameters required to describe the sound.
DefineSound(SWFDecoder coder)
          Creates and initialises a DefineSound object using values encoded in the Flash binary format.
 
Method Summary
 DefineSound copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 int getChannelCount()
          Get the number of sound channels, 1 (Mono) or 2 (Stereo).
 SoundFormat getFormat()
          Get the compression format used.
 int getIdentifier()
          Get the unique identifier assigned to this object.
 int getRate()
          Get the rate at which the sound will be played, in Hz: 5512, 11025, 22050 or 44100.
 int getSampleCount()
          Get the number of samples in the sound data.
 int getSampleSize()
          Get the size of an uncompressed sample in bytes.
 byte[] getSound()
          Get a copy of the sound data.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setChannelCount(int channels)
          Sets the number of channels defined in the sound.
 void setFormat(SoundFormat encoding)
          Sets the compression format used.
 void setIdentifier(int uid)
          Sets the unique identifier for an object within a given Movie.
 void setRate(int samplingRate)
          Sets the sampling rate in Hertz.
 void setSampleCount(int count)
          Sets the number of samples in the sound data.
 void setSampleSize(int size)
          Sets the sample size in bytes.
 void setSound(byte[] bytes)
          Sets the sound data.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefineSound

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

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

DefineSound

public DefineSound(int uid,
                   SoundFormat aFormat,
                   int playbackRate,
                   int channels,
                   int size,
                   int count,
                   byte[] bytes)
Creates a DefineSound object specifying the unique identifier and all the parameters required to describe the sound.

Parameters:
uid - the unique identifier for this sound. Must be in the range 1..65535.
aFormat - the encoding format for the sound. For Flash 1 the formats may be one of the format: NATIVE_PCM, PCM or ADPCM. For Flash 4 or later include MP3 and Flash 6 or later include NELLYMOSER.
playbackRate - the number of samples per second that the sound is played at , either 5512, 11025, 22050 or 44100.
channels - the number of channels in the sound, must be either 1 (Mono) or 2 (Stereo).
size - the size of an uncompressed sound sample in bits, must be either 8 or 16.
count - the number of samples in the sound data.
bytes - the sound data.

DefineSound

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

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

getIdentifier

public int getIdentifier()
Get the unique identifier assigned to this object.

Specified by:
getIdentifier in interface DefineTag
Returns:
the unique identifier used by the Flash Player to reference this definition.

setIdentifier

public void setIdentifier(int uid)
Sets the unique identifier for an object within a given Movie.

Specified by:
setIdentifier in interface DefineTag
Parameters:
uid - a unique identifier for the object. Must be in the range 1..65535.

getFormat

public SoundFormat getFormat()
Get the compression format used.

Returns:
the format for the sound data.

getRate

public int getRate()
Get the rate at which the sound will be played, in Hz: 5512, 11025, 22050 or 44100.

Returns:
the playback rate in Hertz.

getChannelCount

public int getChannelCount()
Get the number of sound channels, 1 (Mono) or 2 (Stereo).

Returns:
the number of channels.

getSampleSize

public int getSampleSize()
Get the size of an uncompressed sample in bytes.

Returns:
the number of bytes in each sample.

getSampleCount

public int getSampleCount()
Get the number of samples in the sound data.

Returns:
the number of sound samples.

getSound

public byte[] getSound()
Get a copy of the sound data.

Returns:
a copy of the sound.

setFormat

public void setFormat(SoundFormat encoding)
Sets the compression format used.

Parameters:
encoding - the format for the sound.

setRate

public void setRate(int samplingRate)
Sets the sampling rate in Hertz.

Parameters:
samplingRate - the rate at which the sounds is played in Hz. Must be one of: SoundRate.KHZ_5K, SoundRate.KHZ_11K, SoundRate.KHZ_22K or SoundRate.KHZ_44K.

setChannelCount

public void setChannelCount(int channels)
Sets the number of channels defined in the sound.

Parameters:
channels - the number of channels in the sound, must be either 1 (Mono) or 2 (Stereo).

setSampleSize

public void setSampleSize(int size)
Sets the sample size in bytes.

Parameters:
size - the size of sound samples in bytes. Must be either 1 or 2.

setSampleCount

public void setSampleCount(int count)
Sets the number of samples in the sound data.

Parameters:
count - the number of samples for the sound.

setSound

public void setSound(byte[] bytes)
Sets the sound data.

Parameters:
bytes - the sound data. Must not be null.

copy

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

Specified by:
copy in interface Copyable<MovieTag>
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.