|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.flagstone.transform.util.FSSoundConstructor
public class FSSoundConstructor
The FSSoundConstructor class is used to generate the objects used to define and control the sounds that are played in a Flash movie. The FSSoundConstructor can be used to generate definitions for:
Sample 0 1 2 +---+---+ +---+---+ +---+---+ | 1 | 2 | | 1 | 2 | | 1 | 2 | .... +---+---+ +---+---+ +---+---+NOTE: The byte order for the PCM data in WAVE sound files may vary according to the platform on which the sound file was created. The FSSoundConstructor currently only supports WAVE files with little-endian byte order. Examples The following code samples illustrate how to use the FSSoundConstructor class to add sounds to a Flash file. 1. Playing an uncompressed WAVE file.\n
int soundId = movie.newIdentifier(); // Generate an FSDefineSound object using the attributes defined in the wave file. // An FSSound object is used to instruct the Flash Player to start playing a sound. FSSoundConstructor soundGenerator = new FSSoundGenerator("sound.wav"); movie.add(soundGenerator.defineSound(soundId)); movie.add(new FSSound(soundId, FSSound.Start));2. Streaming Sounds.\n Larger sound files may be streamed to the Flash Player - splitting the sound data into a sequence of blocks which is synchronised with the frames as they are displayed. Typically block of sound data is generated for each frame displayed.
int framesPerSecond = 12; FSSoundConstructor soundGenerator = new FSSoundGenerator("soundTrack.wav"); // Calculate the number of decoded sound samples played for each frame int samplesPerBlock = soundGenerator.getSampleRate() / framesPerSecond; int numberOfBlocks = soundGenerator.getSamplesPerChannel() / samplesPerBlock; // An FSSoundStreamHeader2 object defines the attributes of the streaming sound. movie.add(soundGenerator.streamHeader(samplesPerBlock)); // Add a streaming block for each frame so the sound is played as each frame is displayed. for (int i=0; i<numberOfBlocks; i++) { movie.add(soundGenerator.streamBlock(i, samplesPerBlock)); movie.add(new FSShowFrame()); }
Constructor Summary | |
---|---|
FSSoundConstructor()
Creates a new uninitialized FSSoundConstructor object. |
|
FSSoundConstructor(java.lang.String fileName)
Creates a new FSSoundConstructor object initialised with the contents of the specified sound file. |
Method Summary | |
---|---|
FSDefineSound |
defineSound(int anIdentifier)
Generates an FSDefineSound object from the sound data. |
int |
getFormat()
Accessor method returning the format for the encoded sound data. |
int |
getNumberOfChannels()
Accessor method returning the number of channels in the sound. |
int |
getSampleRate()
Accessor method returning the rate at which the sound will be played. |
int |
getSampleSize()
Accessor method returning the number of bytes for each decoded sound sample. |
int |
getSamplesPerChannel()
Accessor method returning the number of samples in each channel. |
byte[] |
getSound()
Accessor method returning a copy of the encoded sound data. |
void |
setSound(int format,
int channelCount,
int sampleCount,
int sampleRate,
int sampleSize,
byte[] bytes)
Initialises the FSSoundConstructor with the sound data and set of parameters. |
void |
setSound(java.lang.String filename)
Initialises the FSSoundConstructor with the contents of the specified file. |
FSSoundStreamBlock |
streamBlock(int blockNumber,
int samplesPerBlock)
Generates an FSSoundStreamBlock object containing a block sound data. |
FSSoundStreamHead2 |
streamHeader(int samplesPerBlock)
Generates an FSSoundStreamHead2 object to stream the sound data to the Flash Player. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FSSoundConstructor()
public FSSoundConstructor(java.lang.String fileName) throws java.io.IOException, java.util.zip.DataFormatException
fileName
- the name of the file containing the sound.
java.io.FileNotFoundException
- - if the file does not exist, is a
directory rather than a regular file, or for some other reason cannot be
opened for reading.
java.io.IOException
- - if an I/O error occurs while reading the file.
java.util.zip.DataFormatException
- if the file contains a sound format not
supported by the FSSoundConstructor.Method Detail |
---|
public int getFormat()
public int getNumberOfChannels()
public int getSamplesPerChannel()
public int getSampleRate()
public int getSampleSize()
public byte[] getSound()
public void setSound(java.lang.String filename) throws java.io.IOException, java.util.zip.DataFormatException
filename
- the name of a file containing encoded sound data.
java.io.FileNotFoundException
- - if the file does not exist, is a directory
rather than a regular file, or for some other reason cannot be opened for
reading.
java.io.IOException
- - if an I/O error occurs while reading the file.
java.util.zip.DataFormatException
- if the file contains a sound format not
supported by the FSSoundConstructor.public void setSound(int format, int channelCount, int sampleCount, int sampleRate, int sampleSize, byte[] bytes)
format
- the format of the encoded sound either FSSound.PCM,
FSSound.ADPCM or FSSound.MP3.channelCount
- the number of sound channels, 1 = mono, 2 = stereo.sampleCount
- the number of samples in each channel.sampleRate
- the rate at which the sound is played in kiloHertz.
Flash supports 5512, 11025, 22050 or 44100.sampleSize
- the number of bytes for each uncompressed sound sample,
either 1 or 2.bytes
- an array of sound samples encoding in the specified format.public FSDefineSound defineSound(int anIdentifier)
anIdentifier
- a unique identifier for the FSDefineSound object.
public FSSoundStreamHead2 streamHeader(int samplesPerBlock)
samplesPerBlock
- the number of samples in each subsequent FSSoundStreamBlock
object.
public FSSoundStreamBlock streamBlock(int blockNumber, int samplesPerBlock)
blockNumber
- the nth block of samples.samplesPerBlock
- the number of samples to stream.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |