View Javadoc

1   // Copyright 2001, FreeHEP.
2   package org.freehep.graphicsio.swf;
3   
4   import java.io.IOException;
5   
6   /**
7    * SWF SoundInfo
8    * 
9    * @author Mark Donszelmann
10   * @author Charles Loomis
11   * @version $Id: SoundInfo.java 8584 2006-08-10 23:06:37Z duns $
12   */
13  public class SoundInfo {
14  
15      private boolean syncStop;
16  
17      private boolean syncNoMultiple;
18  
19      private long inPoint = -1;
20  
21      private long outPoint = -1;
22  
23      private int loop = -1;
24  
25      private SoundEnvelope[] envelope;
26  
27      public SoundInfo(boolean syncStop, boolean syncNoMultiple, long inPoint,
28              long outPoint, int loop, SoundEnvelope[] envelope) {
29          this.syncStop = syncStop;
30          this.syncNoMultiple = syncNoMultiple;
31          this.inPoint = inPoint;
32          this.outPoint = outPoint;
33          this.loop = loop;
34          this.envelope = envelope;
35      }
36  
37      public SoundInfo(SWFInputStream input) throws IOException {
38          input.readUBits(2);
39          syncStop = input.readBitFlag();
40          syncNoMultiple = input.readBitFlag();
41          boolean hasEnvelope = input.readBitFlag();
42          boolean hasLoops = input.readBitFlag();
43          boolean hasOutPoint = input.readBitFlag();
44          boolean hasInPoint = input.readBitFlag();
45  
46          if (hasInPoint) {
47              inPoint = input.readUnsignedInt();
48          }
49          if (hasOutPoint) {
50              outPoint = input.readUnsignedInt();
51          }
52          if (hasLoops) {
53              loop = input.readUnsignedShort();
54          }
55  
56          if (hasEnvelope) {
57              int numPoints = input.readUnsignedByte();
58              envelope = new SoundEnvelope[numPoints];
59              for (int i = 0; i < numPoints; i++) {
60                  envelope[i] = new SoundEnvelope(input);
61              }
62          }
63      }
64  
65      public void write(SWFOutputStream swf) throws IOException {
66  
67          swf.writeUBits(0, 2);
68          swf.writeBitFlag(syncStop);
69          swf.writeBitFlag(syncNoMultiple);
70          swf.writeBitFlag(envelope != null);
71          swf.writeBitFlag(loop >= 0);
72          swf.writeBitFlag(outPoint >= 0);
73          swf.writeBitFlag(inPoint >= 0);
74  
75          if (inPoint >= 0) {
76              swf.writeUnsignedInt(inPoint);
77          }
78          if (outPoint >= 0) {
79              swf.writeUnsignedInt(outPoint);
80          }
81          if (loop >= 0) {
82              swf.writeUnsignedShort(loop);
83          }
84  
85          if (envelope != null) {
86              swf.writeUnsignedByte(envelope.length);
87              for (int i = 0; i < envelope.length; i++) {
88                  envelope[i].write(swf);
89              }
90          }
91  
92      }
93  
94      public String toString() {
95          StringBuffer s = new StringBuffer("SoundInfo ");
96          s.append("syncStop: " + syncStop);
97          s.append(", syncNoMultiple: " + syncNoMultiple);
98          s.append(", in: " + inPoint);
99          s.append(", out: " + outPoint);
100         s.append(", loop: " + loop);
101         if (envelope != null) {
102             s.append(" [");
103             for (int i = 0; i < envelope.length; i++) {
104                 s.append(envelope[i]);
105                 s.append(" ");
106             }
107             s.append("]");
108         }
109         return s.toString();
110     }
111 }