com.flagstone.transform.sound
Class SoundStreamHead

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

public final class SoundStreamHead
extends Object
implements MovieTag

SoundStreamHead defines the format of a streaming sound, identifying the encoding scheme, the rate at which the sound will be played and the size of the decoded samples.

Sounds may be either mono or stereo and encoded using either NATIVE_PCM, ADPCM, MP3 or NELLYMOSER formats and have sampling rates of 5512, 11025, 22050 or 44100 Hz.

The actual sound is streamed used the SoundStreamBlock class which contains the data for each frame in a movie.

When a stream sound is played if the Flash Player cannot render the frames fast enough to maintain synchronisation with the sound being played then frames will be skipped. Normally the player will reduce the frame rate so every frame of a movie is played. The different sets of attributes that identify how the sound will be played compared to the way it was encoded allows the Player more control over how the animation is rendered. Reducing the resolution or playback rate can improve synchronisation with the frames displayed.

SoundStreamHead2 allows way the sound is played to differ from the way it is encoded and streamed to the player. This allows the Player more control over how the animation is rendered. Reducing the resolution or playback rate can improve synchronisation with the frames displayed.

See Also:
SoundStreamBlock, SoundStreamHead2

Constructor Summary
SoundStreamHead(int playbackRate, int playbackChannels, int playSize, int streamingRate, int streamingChannels, int streamingSize, int streamingCount)
          Creates a SoundStreamHead object specifying all the parameters required to define the sound.
SoundStreamHead(SoundStreamHead object)
          Creates and initialises a SoundStreamHead object using the values copied from another SoundStreamHead object.
SoundStreamHead(SWFDecoder coder)
          Creates and initialises a SoundStreamHead object using values encoded in the Flash binary format.
 
Method Summary
 SoundStreamHead copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 SoundFormat getFormat()
          Get the compression format used.
 int getLatency()
          For MP3 encoded sounds, returns the number of samples to skip when starting to play a sound.
 int getPlayChannels()
          Get the recommended number of playback channels = 1 = mono 2 = stereo.
 int getPlayRate()
          Returns the recommended playback rate: 5512, 11025, 22050 or 44100 Hz.
 int getPlaySampleSize()
          Get the recommended playback sample range in bytes: 1 or 2.
 int getStreamChannels()
          Get the number of channels, 1 = mono 2 = stereo, in the streaming sound.
 float getStreamRate()
          Get the sample rate: 5512, 11025, 22050 or 44100 Hz in the streaming sound.
 int getStreamSampleCount()
          Get the average number of samples in each stream block following.
 int getStreamSampleSize()
          Get the sample size in bytes: 1 or 2 in the streaming sound.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setFormat(SoundFormat encoding)
          Sets the format for the streaming sound.
 void setLatency(int delay)
          Set the number of samples to skip when starting to play an MP3 encoded sound.
 void setPlayChannels(int channels)
          Sets the recommended number of playback channels = 1 = mono 2 = stereo.
 void setPlayRate(int rate)
          Sets the recommended playback rate in Hz.
 void setPlaySampleSize(int playSize)
          Sets the recommended playback sample size in bytes.
 void setStreamChannels(int channels)
          Sets the number of channels in the streaming sound: 1 = mono 2 = stereo.
 void setStreamRate(int rate)
          Sets the sample rate in Hz for the streaming sound.
 void setStreamSampleCount(int count)
          Sets the number of samples in each stream block.
 void setStreamSampleSize(int size)
          Sets the sample size in bytes for the streaming sound.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SoundStreamHead

public SoundStreamHead(SWFDecoder coder)
                throws IOException
Creates and initialises a SoundStreamHead 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.

SoundStreamHead

public SoundStreamHead(int playbackRate,
                       int playbackChannels,
                       int playSize,
                       int streamingRate,
                       int streamingChannels,
                       int streamingSize,
                       int streamingCount)
Creates a SoundStreamHead object specifying all the parameters required to define the sound.

Parameters:
playbackRate - the recommended rate for playing the sound, either 5512, 11025, 22050 or 44100 Hz.
playbackChannels - The recommended number of playback channels: 1 = mono or 2 = stereo.
playSize - the recommended uncompressed sample size for playing the sound, either 1 or 2 bytes.
streamingRate - the rate at which the sound was sampled, either 5512, 11025, 22050 or 44100 Hz.
streamingChannels - the number of channels: 1 = mono or 2 = stereo.
streamingSize - the sample size for the sound in bytes, either 1 or 2.
streamingCount - the number of samples in each subsequent SoundStreamBlock object.

SoundStreamHead

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

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

getFormat

public SoundFormat getFormat()
Get the compression format used.

Returns:
the format for the sound data.

setFormat

public void setFormat(SoundFormat encoding)
Sets the format for the streaming sound.

Parameters:
encoding - the compression format for the sound data, must be either ADPCM or MP3 from SoundFormat.

getPlayRate

public int getPlayRate()
Returns the recommended playback rate: 5512, 11025, 22050 or 44100 Hz.

Returns:
the playback rate in Hertz.

getPlayChannels

public int getPlayChannels()
Get the recommended number of playback channels = 1 = mono 2 = stereo.

Returns:
the number of channels.

getPlaySampleSize

public int getPlaySampleSize()
Get the recommended playback sample range in bytes: 1 or 2.

Returns:
the number of bytes in each sample.

getStreamRate

public float getStreamRate()
Get the sample rate: 5512, 11025, 22050 or 44100 Hz in the streaming sound.

Returns:
the stream rate in Hertz.

getStreamChannels

public int getStreamChannels()
Get the number of channels, 1 = mono 2 = stereo, in the streaming sound.

Returns:
the number of channels defined in the streaming sound.

getStreamSampleSize

public int getStreamSampleSize()
Get the sample size in bytes: 1 or 2 in the streaming sound.

Returns:
the number of bytes per sample in the streaming sound.

getStreamSampleCount

public int getStreamSampleCount()
Get the average number of samples in each stream block following.

Returns:
the number of sample in each stream block.

setPlayRate

public void setPlayRate(int rate)
Sets the recommended playback rate in Hz. Must be either: 5512, 11025, 22050 or 44100.

Parameters:
rate - the recommended rate for playing the sound.

setPlayChannels

public void setPlayChannels(int channels)
Sets the recommended number of playback channels = 1 = mono 2 = stereo.

Parameters:
channels - the recommended number of playback channels.

setPlaySampleSize

public void setPlaySampleSize(int playSize)
Sets the recommended playback sample size in bytes. Must be wither 1 or 2.

Parameters:
playSize - the recommended sample size for playing the sound.

setStreamRate

public void setStreamRate(int rate)
Sets the sample rate in Hz for the streaming sound. Must be either: 5512, 11025, 22050 or 44100.

Parameters:
rate - the rate at which the streaming sound was sampled.

setStreamChannels

public void setStreamChannels(int channels)
Sets the number of channels in the streaming sound: 1 = mono 2 = stereo.

Parameters:
channels - the number of channels in the streaming sound.

setStreamSampleSize

public void setStreamSampleSize(int size)
Sets the sample size in bytes for the streaming sound. Must be 1 or 2.

Parameters:
size - the sample size for the sound.

setStreamSampleCount

public void setStreamSampleCount(int count)
Sets the number of samples in each stream block.

Parameters:
count - the number of samples in each subsequent SoundStreamBlock object.

getLatency

public int getLatency()
For MP3 encoded sounds, returns the number of samples to skip when starting to play a sound.

Returns:
the number of samples skipped in an MP3 encoded sound Returns 0 for other sound formats.

setLatency

public void setLatency(int delay)
Set the number of samples to skip when starting to play an MP3 encoded sound.

Parameters:
delay - the number of samples to be skipped in an MP3 encoded sound should be 0 for other sound formats.

copy

public SoundStreamHead 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.