📄 fssoundstreamhead2.java
字号:
/*
* FSSoundStreamHead2.java
* Transform
*
* Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Flagstone Software Ltd. nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.flagstone.transform;
/**
FSSoundStreamHead2 defines an sound compressed using different compression formats
that is streamed in tight synchronisation with the movie being played.
<p>The FSSoundStreamHead2 class defines how the streaming sound is played. Objects
of the FSSoundStreamBlock class contains the sound data.</P>
<p>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.</p>
<p>To define the stream sound the parameters for and sampled sound and how it will
be played back must be specified:</p>
<table class="datasheet">
<tr><th align="left" colspan="2">Attributes</th></tr>
<tr><td><a name="FSSoundStreamHead_0">type</a></td>
<td>Identifies the data structure when it is encoded. Read-only.</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_1">format</a></td>
<td>The format of the encoded sound data - FSSound.PCM (Little-Endian byte order),
FSSound.ADPCM, FSSound.NATIVE_PCM (Big-Endian or Little-Endian byte order
depending on the platform where the sound was created), FSSound.MP3 or
FSSound.NELLYMOSER</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_2">playbackRate</a></td>
<td>The recommended playback rate in Hertz - 5512, 11025, 22050 or 44100.</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_3">playbackSampleSize</a></td>
<td>The number of bytes in an uncompressed sample when the sound is played, either 1 or 2.</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_4">playbackChannels</a></td>
<td>The recommended number of playback channels: 1 = mono or 2 = stereo.</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_5">streamRate</a></td>
<td>The stream sampling rate - 5512, 11025, 22050 or 44100 Hz</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_6">streamSampleSize</a></td>
<td>The size of an uncompressed sample in the streaming sound in bytes, either 1 or 2.</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_7">streamChannels</a></td>
<td>The number of channels: 1 = mono or 2 = stereo in the streaming sound</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_8">streamSampleCount</a></td>
<td>The average number of samples in each sound stream block.</td>
</tr>
<tr>
<td><a name="FSSoundStreamHead_9">latency</a></td>
<td>Latency defines the number of samples to skip only when playing sounds encoded
with the MP3 format.</td>
</tr>
</table>
<p>FSSoundStreamHead2 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.</p>
<b>History</b>
<p>The FSSoundStreamHead2 class represents the SoundStreamHead structure from the
Flash specification. It was introduced in Flash 3. Support for the Nellymoser Asao
format was added in Flash 6.</p>
*/
public class FSSoundStreamHead2 extends FSMovieObject
{
private int format = FSSound.ADPCM;
private int playbackRate = 5512;
private int playbackChannels = 1;
private int playbackSampleSize = 16;
private int streamRate = 5512;
private int streamChannels = 1;
private int streamSampleSize = 16;
private int streamSampleCount = 0;
private int latency = 0;
/*
* The following variable is used to preserve the value of a reserved field
* when decoding then encoding an existing Flash file. Macromedia's file
* file format specification states that this field is always zero - it is
* not, so this is used to preserve the value in case it is implementing
* an undocumented feature.
*/
private int _reserved = 0;
/**
* Construct an FSSoundStreamHead2 object, initalizing it with values
* decoded from an encoded object.
*
* @param coder an FSCoder containing the binary data.
*/
public FSSoundStreamHead2(FSCoder coder)
{
super(SoundStreamHead2);
decode(coder);
}
/** Constructs an FSSoundStreamHead2 object specifying all the parameters required to define the sound.
@param encoding the compression format for the sound data, either FSSound.NATIVE_PCM, FSSound.ADPCM, FSSound.MP3, FSSound.PCM or FSSound.NELLYMOSER (Flash 6+ only).
@param playRate the recommended rate for playing the sound, either 5512, 11025, 22050 or 44100 Hz.
@param playChannels The recommended number of playback channels: 1 = mono or 2 = stereo.
@param playSize the recommended uncompressed sample size for playing the sound, either 1 or 2 bytes.
@param streamingRate the rate at which the sound was sampled, either 5512, 11025, 22050 or 44100 Hz.
@param streamingChannels the number of channels: 1 = mono or 2 = stereo.
@param streamingSize the sample size for the sound, either 1 or 2 bytes.
@param streamingCount the number of samples in each subsequent FSSoundStreamBlock object.
@param latency defines the number of samples to skip only when playing sounds encoded with the MP3 format.
*/
public FSSoundStreamHead2(int encoding, int playRate, int playChannels, int playSize, int streamingRate, int streamingChannels, int streamingSize, int streamingCount, int latency)
{
super(SoundStreamHead2);
setFormat(encoding);
setPlaybackRate(playRate);
setPlaybackChannels(playChannels);
setPlaybackSampleSize(playSize);
setStreamRate(streamingRate);
setStreamChannels(streamingChannels);
setStreamSampleSize(streamingSize);
setStreamSampleCount(streamingCount);
setLatency(latency);
}
/**
* Constructs an FSSoundStreamHead2 object by copying values from an
* existing object.
*
* @param obj an FSSoundStreamHead2 object.
*/
public FSSoundStreamHead2(FSSoundStreamHead2 obj)
{
super(obj);
format = obj.format;
playbackRate = obj.playbackRate;
playbackChannels = obj.playbackChannels;
playbackSampleSize = obj.playbackSampleSize;
streamRate = obj.streamRate;
streamChannels = obj.streamChannels;
streamSampleSize = obj.streamSampleSize;
streamSampleCount = obj.streamSampleCount;
latency = obj.latency;
_reserved = obj._reserved;
}
/**
* Gets the streaming sound format. For the FSSoundStreamHead2 class supports
* NATIVE_PCM, ADPCM, MP3, PCM or NELLYMOSER encoded sound data.
@return the format used to play the sound.
*/
public int getFormat()
{
return format;
}
/** Sets the format for the streaming sound.
@param encoding the compression format for the sound data, either
FSSound.NATIVE_PCM, FSSound.ADPCM, FSSound.MP3, FSSound.PCM or FSSound.NELLYMOSER.
*/
public void setFormat(int encoding)
{
format = encoding;
}
/** Gets the recommended playback rate: 5512, 11025, 22050 or 44100 Hertz.
@return the rate at which the sound will be played back.
*/
public int getPlaybackRate() { return playbackRate; }
/** Gets the recommended number of playback channels = 1 = mono 2 = stereo.
@return the number of channels for the sound playback.
*/
public int getPlaybackChannels() { return playbackChannels; }
/** Gets the recommended playback sample range in bytes: 1 or 2.
@return the sample size used to play back the sound.
*/
public int getPlaybackSampleSize() { return playbackSampleSize; }
/** Gets the sample rate: 5512, 11025, 22050 or 44100 Hz in the streaming sound.
@return the rate at which the sound was sampled.
*/
public float getStreamRate() { return streamRate; }
/** Gets the number of channels, 1 = mono 2 = stereo, in the streaming sound.
@return the number of channels in the sound.
*/
public int getStreamChannels() { return streamChannels; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -