KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > api > sound > SoundStreamHead


1 /*
2  * $Id: SoundStreamHead.java,v 1.4 2002/07/18 06:02:22 skavish Exp $
3  *
4  * ===========================================================================
5  *
6  */

7
8 package org.openlaszlo.iv.flash.api.sound;
9
10 import java.io.PrintStream JavaDoc;
11 import org.openlaszlo.iv.flash.parser.*;
12 import org.openlaszlo.iv.flash.util.*;
13 import org.openlaszlo.iv.flash.api.*;
14
15 public class SoundStreamHead extends FlashObject
16 {
17     public int reserved; // 4 bits ( reserved, always 0 )
18
public int playbackRate; // 2 bits
19
public boolean isPlayback16bit; // 1 bit
20
public boolean isPlaybackStereo; // 1 bit
21

22     public int streamCompression; // 4 bits
23
public int streamRate; // 2 bits
24
public boolean isStream16bit; // 1 bit
25
public boolean isStreamStereo; // 1 bit
26

27     public int streamSampleCount; // 1 word
28

29                                        // Total: 4 bytes
30
private int tagCode = -1;
31
32     public int getTag()
33     {
34         if( tagCode != -1 ) return tagCode;
35         if ( streamCompression == Sound.COMPRESS_ADPCM
36              && streamRate == Sound.RATE_5_5
37              && isStream16bit == true )
38         {
39             return Tag.SOUNDSTREAMHEAD;
40         }
41         else
42         {
43             return Tag.SOUNDSTREAMHEAD2;
44         }
45     }
46
47     public static SoundStreamHead parse( Parser p )
48     {
49         SoundStreamHead o = new SoundStreamHead();
50
51         o.tagCode = p.getTagCode();
52         p.initBits();
53
54         //p.skipBits( 4 ); // Reserved
55
o.reserved = p.getBits(4);
56
57         o.playbackRate = p.getBits( 2 );
58         o.isPlayback16bit = p.getBool();
59         o.isPlaybackStereo = p.getBool();
60
61         o.streamCompression = p.getBits( 4 );
62
63         o.streamRate = p.getBits( 2 );
64         o.isStream16bit = p.getBool();
65         o.isStreamStereo = p.getBool();
66
67         o.streamSampleCount = p.getUWord();
68
69         return o;
70     }
71
72     public void write( FlashOutput fob )
73     {
74         fob.writeTag( getTag(), 4 );
75
76         fob.initBits(); // Prepare to write to bit buffer
77

78         //fob.writeBits( 0, 4 ); // Reserved
79
fob.writeBits(reserved, 4);
80
81         fob.writeBits( playbackRate, 2 );
82         fob.writeBool( isPlayback16bit );
83         fob.writeBool( isPlaybackStereo );
84
85         fob.flushBits(); // End of first byte
86

87         fob.writeBits( streamCompression, 4 );
88         fob.writeBits( streamRate, 2 );
89         fob.writeBool( isStream16bit );
90         fob.writeBool( isStreamStereo );
91
92         fob.flushBits(); // End of second byte
93

94         fob.writeWord( streamSampleCount );
95     }
96
97     public boolean isConstant()
98     {
99         return true;
100     }
101
102     protected FlashItem copyInto( FlashItem item, ScriptCopier copier )
103     {
104         super.copyInto( item, copier );
105
106         ( (SoundStreamHead) item ).tagCode = tagCode;
107         ( (SoundStreamHead) item ).playbackRate = playbackRate;
108         ( (SoundStreamHead) item ).isPlayback16bit = isPlayback16bit;
109         ( (SoundStreamHead) item ).isPlaybackStereo = isPlaybackStereo;
110
111         ( (SoundStreamHead) item ).streamCompression = streamCompression;
112         ( (SoundStreamHead) item ).streamRate = streamRate;
113         ( (SoundStreamHead) item ).isStream16bit = isStream16bit;
114         ( (SoundStreamHead) item ).isStreamStereo = isStreamStereo;
115
116         ( (SoundStreamHead) item ).streamSampleCount = streamSampleCount;
117
118         return item;
119     }
120     public FlashItem getCopy( ScriptCopier copier )
121     {
122         return copyInto( new SoundStreamHead(), copier );
123     }
124
125     public void printContent( PrintStream JavaDoc out, String JavaDoc indent )
126     {
127         if ( getTag() == Tag.SOUNDSTREAMHEAD2 )
128         {
129             out.println( indent + "SoundStreamHead2" );
130         }
131         else
132         {
133             out.println( indent + "SoundStreamHead" );
134         }
135
136         out.println( indent + " Playback Rate: " + Sound.rates[ playbackRate ] );
137         out.println( indent + " Playback 16 Bit: " + isPlayback16bit );
138         out.println( indent + " Playback Stereo: " + isPlaybackStereo );
139
140         out.println( indent + " Stream Compression: " + Sound.compressions [ streamCompression ] );
141         out.println( indent + " Stream Rate: " + Sound.rates[ streamRate ] );
142         out.println( indent + " Stream 16 Bit: " + isStream16bit );
143         out.println( indent + " Stream Stereo: " + isStreamStereo );
144
145         out.println( indent + " Stream Sample Count: " + streamSampleCount );
146     }
147 }
148
Popular Tags