1
2 package org.freehep.graphicsio.swf;
3
4 import java.io.IOException;
5
6
7
8
9
10
11
12
13 public class DefineSound extends DefinitionTag {
14
15 public final static int NONE = 0;
16
17 public final static int ADPCM = 1;
18
19 public final static int MP3 = 2;
20
21 public final static int NELLYMOSER = 3;
22
23 public final static int RATE_5_5 = 0;
24
25 public final static int RATE_11 = 1;
26
27 public final static int RATE_22 = 2;
28
29 public final static int RATE_44 = 3;
30
31 public final static int BYTE = 0;
32
33 public final static int SHORT = 1;
34
35 public final static int MONO = 0;
36
37 public final static int STEREO = 1;
38
39 private int character;
40
41 private int format;
42
43 private int rate;
44
45 private int size;
46
47 private boolean stereo;
48
49 private long samples;
50
51 private int[] data;
52
53 public DefineSound(int id, int format, int rate, int size, boolean stereo,
54 long samples, int[] data) {
55 this();
56 character = id;
57 this.format = format;
58 this.rate = rate;
59 this.size = size;
60 this.stereo = stereo;
61 this.samples = samples;
62 this.data = data;
63 }
64
65 public DefineSound() {
66 super(14, 1);
67 }
68
69 public SWFTag read(int tagID, SWFInputStream swf, int len)
70 throws IOException {
71
72 DefineSound tag = new DefineSound();
73 tag.character = swf.readUnsignedShort();
74 swf.getDictionary().put(tag.character, tag);
75 tag.format = (int) swf.readUBits(4);
76 tag.rate = (int) swf.readUBits(2);
77 tag.size = swf.readBitFlag() ? SHORT : BYTE;
78 tag.stereo = swf.readBitFlag();
79 tag.samples = swf.readUnsignedInt();
80 tag.data = swf.readUnsignedByte(len - 7);
81 return tag;
82 }
83
84 public void write(int tagID, SWFOutputStream swf) throws IOException {
85 swf.writeUnsignedShort(character);
86 swf.writeUBits(format, 4);
87 swf.writeUBits(rate, 2);
88 swf.writeBitFlag(size == SHORT);
89 swf.writeBitFlag(stereo);
90 swf.writeUnsignedInt(samples);
91 swf.writeUnsignedByte(data);
92 }
93
94 public String toString() {
95 StringBuffer s = new StringBuffer();
96 s.append(super.toString() + "\n");
97 s.append(" character: " + character + "\n");
98 s.append(" format:" + format + "\n");
99 s.append(" rate:" + rate + "\n");
100 s.append(" size:" + size + "\n");
101 s.append(" stereo:" + stereo + "\n");
102 s.append(" samples:" + samples + "\n");
103 s.append(" length:" + data.length + "\n");
104 return s.toString();
105 }
106 }