001: /*
002: * $Id: SoundStreamHead.java,v 1.4 2002/07/18 06:02:22 skavish Exp $
003: *
004: * ===========================================================================
005: *
006: */
007:
008: package org.openlaszlo.iv.flash.api.sound;
009:
010: import java.io.PrintStream;
011: import org.openlaszlo.iv.flash.parser.*;
012: import org.openlaszlo.iv.flash.util.*;
013: import org.openlaszlo.iv.flash.api.*;
014:
015: public class SoundStreamHead extends FlashObject {
016: public int reserved; // 4 bits ( reserved, always 0 )
017: public int playbackRate; // 2 bits
018: public boolean isPlayback16bit; // 1 bit
019: public boolean isPlaybackStereo; // 1 bit
020:
021: public int streamCompression; // 4 bits
022: public int streamRate; // 2 bits
023: public boolean isStream16bit; // 1 bit
024: public boolean isStreamStereo; // 1 bit
025:
026: public int streamSampleCount; // 1 word
027:
028: // Total: 4 bytes
029: private int tagCode = -1;
030:
031: public int getTag() {
032: if (tagCode != -1)
033: return tagCode;
034: if (streamCompression == Sound.COMPRESS_ADPCM
035: && streamRate == Sound.RATE_5_5
036: && isStream16bit == true) {
037: return Tag.SOUNDSTREAMHEAD;
038: } else {
039: return Tag.SOUNDSTREAMHEAD2;
040: }
041: }
042:
043: public static SoundStreamHead parse(Parser p) {
044: SoundStreamHead o = new SoundStreamHead();
045:
046: o.tagCode = p.getTagCode();
047: p.initBits();
048:
049: //p.skipBits( 4 ); // Reserved
050: o.reserved = p.getBits(4);
051:
052: o.playbackRate = p.getBits(2);
053: o.isPlayback16bit = p.getBool();
054: o.isPlaybackStereo = p.getBool();
055:
056: o.streamCompression = p.getBits(4);
057:
058: o.streamRate = p.getBits(2);
059: o.isStream16bit = p.getBool();
060: o.isStreamStereo = p.getBool();
061:
062: o.streamSampleCount = p.getUWord();
063:
064: return o;
065: }
066:
067: public void write(FlashOutput fob) {
068: fob.writeTag(getTag(), 4);
069:
070: fob.initBits(); // Prepare to write to bit buffer
071:
072: //fob.writeBits( 0, 4 ); // Reserved
073: fob.writeBits(reserved, 4);
074:
075: fob.writeBits(playbackRate, 2);
076: fob.writeBool(isPlayback16bit);
077: fob.writeBool(isPlaybackStereo);
078:
079: fob.flushBits(); // End of first byte
080:
081: fob.writeBits(streamCompression, 4);
082: fob.writeBits(streamRate, 2);
083: fob.writeBool(isStream16bit);
084: fob.writeBool(isStreamStereo);
085:
086: fob.flushBits(); // End of second byte
087:
088: fob.writeWord(streamSampleCount);
089: }
090:
091: public boolean isConstant() {
092: return true;
093: }
094:
095: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
096: super .copyInto(item, copier);
097:
098: ((SoundStreamHead) item).tagCode = tagCode;
099: ((SoundStreamHead) item).playbackRate = playbackRate;
100: ((SoundStreamHead) item).isPlayback16bit = isPlayback16bit;
101: ((SoundStreamHead) item).isPlaybackStereo = isPlaybackStereo;
102:
103: ((SoundStreamHead) item).streamCompression = streamCompression;
104: ((SoundStreamHead) item).streamRate = streamRate;
105: ((SoundStreamHead) item).isStream16bit = isStream16bit;
106: ((SoundStreamHead) item).isStreamStereo = isStreamStereo;
107:
108: ((SoundStreamHead) item).streamSampleCount = streamSampleCount;
109:
110: return item;
111: }
112:
113: public FlashItem getCopy(ScriptCopier copier) {
114: return copyInto(new SoundStreamHead(), copier);
115: }
116:
117: public void printContent(PrintStream out, String indent) {
118: if (getTag() == Tag.SOUNDSTREAMHEAD2) {
119: out.println(indent + "SoundStreamHead2");
120: } else {
121: out.println(indent + "SoundStreamHead");
122: }
123:
124: out.println(indent + " Playback Rate: "
125: + Sound.rates[playbackRate]);
126: out.println(indent + " Playback 16 Bit: " + isPlayback16bit);
127: out
128: .println(indent + " Playback Stereo: "
129: + isPlaybackStereo);
130:
131: out.println(indent + " Stream Compression: "
132: + Sound.compressions[streamCompression]);
133: out.println(indent + " Stream Rate: "
134: + Sound.rates[streamRate]);
135: out.println(indent + " Stream 16 Bit: " + isStream16bit);
136: out.println(indent + " Stream Stereo: " + isStreamStereo);
137:
138: out.println(indent + " Stream Sample Count: "
139: + streamSampleCount);
140: }
141: }
|