View Javadoc

1   // Copyright 2001, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.io.IOException;
5   
6   /**
7    * SoundStreamHead TAG.
8    * 
9    * @author Mark Donszelmann
10   * @author Charles Loomis
11   * @version $Id: SoundStreamHead.java 8584 2006-08-10 23:06:37Z duns $
12   */
13  public class SoundStreamHead extends DefinitionTag {
14  
15      protected int playbackSoundRate;
16  
17      protected boolean playbackSoundSize16;
18  
19      protected boolean playbackSoundStereo;
20  
21      protected int streamSoundCompression;
22  
23      protected int streamSoundRate;
24  
25      protected boolean streamSoundSize16;
26  
27      protected boolean streamSoundStereo;
28  
29      protected int samples;
30  
31      protected int latencySeek;
32  
33      public SoundStreamHead(int playbackSoundRate, boolean playbackSoundStereo,
34              int streamSoundRate, boolean streamSoundStereo, int samples) {
35          this();
36          this.playbackSoundRate = playbackSoundRate;
37          this.playbackSoundSize16 = true;
38          this.playbackSoundStereo = playbackSoundStereo;
39          this.streamSoundCompression = 1;
40          this.streamSoundRate = streamSoundRate;
41          this.streamSoundSize16 = true;
42          this.streamSoundStereo = streamSoundStereo;
43          this.samples = samples;
44      }
45  
46      public SoundStreamHead() {
47          super(18, 1);
48      }
49  
50      protected SoundStreamHead(int tagID, int version) {
51          super(tagID, version);
52      }
53  
54      public SWFTag read(int tagID, SWFInputStream swf, int len)
55              throws IOException {
56          SoundStreamHead tag = new SoundStreamHead();
57          tag.read(swf, len);
58          return tag;
59      }
60  
61      protected void read(SWFInputStream swf, int len) throws IOException {
62          /* int reserved = (int) */ swf.readUBits(4);
63          playbackSoundRate = (int) swf.readUBits(2);
64          playbackSoundSize16 = swf.readBitFlag();
65          playbackSoundStereo = swf.readBitFlag();
66          streamSoundCompression = (int) swf.readUBits(4);
67          streamSoundRate = (int) swf.readUBits(2);
68          streamSoundSize16 = swf.readBitFlag();
69          streamSoundStereo = swf.readBitFlag();
70          samples = swf.readUnsignedShort();
71          if (streamSoundCompression == 2)
72              latencySeek = swf.readShort();
73      }
74  
75      public void write(int tagID, SWFOutputStream swf) throws IOException {
76          write(swf);
77      }
78  
79      protected void write(SWFOutputStream swf) throws IOException {
80          swf.writeUBits(0, 4);
81          swf.writeUBits(playbackSoundRate, 2);
82          swf.writeBitFlag(playbackSoundSize16);
83          swf.writeBitFlag(playbackSoundStereo);
84          swf.writeUBits(streamSoundCompression, 4);
85          swf.writeUBits(streamSoundRate, 2);
86          swf.writeBitFlag(streamSoundSize16);
87          swf.writeBitFlag(streamSoundStereo);
88          swf.writeUnsignedShort(samples);
89          if (streamSoundCompression == 2)
90              swf.writeShort(latencySeek);
91      }
92  
93      public String toString() {
94          StringBuffer s = new StringBuffer();
95          s.append(super.toString());
96          return s.toString();
97      }
98  
99  }