Skip to content

Commit

Permalink
Adding DefineSound and StartSound tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Fujiwara committed Sep 11, 2013
1 parent e72f660 commit 6f6a859
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 12 deletions.
2 changes: 2 additions & 0 deletions SWFWireDecompiler/.flexLibProperties
Expand Up @@ -419,6 +419,8 @@
<classEntry path="com.swfwire.decompiler.data.swf6.records.IVideoPacketRecord"/>
<classEntry path="com.swfwire.decompiler.data.swf6.records.VP6SWFVideoPacketRecord"/>
<classEntry path="com.swfwire.decompiler.data.swf.enums.SoundType"/>
<classEntry path="com.swfwire.decompiler.data.swf.enums.SoundFormat"/>
<classEntry path="com.swfwire.decompiler.data.swf.records.SoundInfoRecord"/>
</includeClasses>
<includeResources/>
<namespaceManifests/>
Expand Down
66 changes: 60 additions & 6 deletions SWFWireDecompiler/src/com/swfwire/decompiler/SWFReader.as
Expand Up @@ -22,6 +22,8 @@ package com.swfwire.decompiler
import com.swfwire.decompiler.data.swf.records.SceneRecord;
import com.swfwire.decompiler.data.swf.records.ShapeRecord;
import com.swfwire.decompiler.data.swf.records.ShapeWithStyleRecord;
import com.swfwire.decompiler.data.swf.records.SoundEnvelopeRecord;
import com.swfwire.decompiler.data.swf.records.SoundInfoRecord;
import com.swfwire.decompiler.data.swf.records.StraightEdgeRecord;
import com.swfwire.decompiler.data.swf.records.StyleChangeRecord;
import com.swfwire.decompiler.data.swf.records.TagHeaderRecord;
Expand Down Expand Up @@ -186,12 +188,6 @@ package com.swfwire.decompiler
case 13:
tag = readDefineFontInfoTag(context, header);
break;
case 14:
tag = readDefineSoundTag(context, header);
break;
case 15:
tag = readStartSoundTag(context, header);
break;
*/
case 0:
tag = readEndTag(context, header);
Expand Down Expand Up @@ -226,6 +222,12 @@ package com.swfwire.decompiler
case 11:
tag = readDefineTextTag(context, header);
break;
case 14:
tag = readDefineSoundTag(context, header);
break;
case 15:
tag = readStartSoundTag(context, header);
break;
case 18:
tag = readSoundStreamHeadTag(context, header);
break;
Expand Down Expand Up @@ -461,12 +463,22 @@ package com.swfwire.decompiler
protected function readDefineSoundTag(context:SWFReaderContext, header:TagHeaderRecord):DefineSoundTag
{
var tag:DefineSoundTag = new DefineSoundTag();
tag.soundId = context.bytes.readUI16();
tag.soundFormat = context.bytes.readUB(4);
tag.soundRate = context.bytes.readUB(2);
tag.soundSize = context.bytes.readUB(1);
tag.soundType = context.bytes.readUB(1);
tag.soundSampleCount = context.bytes.readUI32();
var remaining:int = context.currentTagEnd - context.bytes.getBytePosition();
context.bytes.readBytes(tag.soundData, 0, remaining);
return tag;
}

protected function readStartSoundTag(context:SWFReaderContext, header:TagHeaderRecord):StartSoundTag
{
var tag:StartSoundTag = new StartSoundTag();
tag.soundId = context.bytes.readUI16();
tag.soundInfo = readSoundInfoRecord(context);
return tag;
}

Expand Down Expand Up @@ -861,6 +873,48 @@ package com.swfwire.decompiler
return record;
}

protected function readSoundInfoRecord(context:SWFReaderContext):SoundInfoRecord
{
var record:SoundInfoRecord = new SoundInfoRecord();
record.reserved = context.bytes.readUB(2);
record.syncStop = context.bytes.readFlag();
record.syncNoMultiple = context.bytes.readFlag();
record.hasEnvelope = context.bytes.readFlag();
record.hasLoops = context.bytes.readFlag();
record.hasOutPoint = context.bytes.readFlag();
record.hasInPoint = context.bytes.readFlag();
if(record.hasInPoint)
{
record.inPoint = context.bytes.readUI32();
}
if(record.hasOutPoint)
{
record.outPoint = context.bytes.readUI32();
}
if(record.hasLoops)
{
record.loopCount = context.bytes.readUI16();
}
if(record.hasEnvelope)
{
record.envPoints = context.bytes.readUI8();
for(var iter:uint = 0; iter < record.envPoints; iter++)
{
record.envPoints[iter] = readSoundEnvelopeRecord(context);
}
}
return record;
}

protected function readSoundEnvelopeRecord(context:SWFReaderContext):SoundEnvelopeRecord
{
var record:SoundEnvelopeRecord = new SoundEnvelopeRecord();
record.pos44 = context.bytes.readUI32();
record.leftLevel = context.bytes.readUI16();
record.rightLevel = context.bytes.readUI16();
return record;
}

protected function readSceneRecord(context:SWFReaderContext):SceneRecord
{
var record:SceneRecord = new SceneRecord();
Expand Down
@@ -0,0 +1,68 @@
package com.swfwire.decompiler.data.swf.enums
{
public class SoundFormat
{
public static const UNCOMPRESSED:String = 'uncompressed';
public static const ADPCM:String = 'adpcm';
public static const MP3:String = 'mp3';
public static const UNCOMPRESSED_LITTLE_ENDIAN:String = 'uncompressedLittleEndian';
public static const NELLYMOSER:String = 'nellymoser';
public static const SPEEX:String = 'speex';

public function IdFromString(string:String):int
{
var result:int = -1;
switch(string)
{
case UNCOMPRESSED:
result = 0;
break;
case ADPCM:
result = 1;
break;
case MP3:
result = 2;
break;
case UNCOMPRESSED_LITTLE_ENDIAN:
result = 3;
break;
case NELLYMOSER:
result = 4;
break;
case SPEEX:
result = 11;
break;
}
return result;
}

public function stringFromId(id:uint):String
{
var result:String = null;
switch(id)
{
case 0:
result = UNCOMPRESSED;
break;
case 1:
result = ADPCM;
break;
case 2:
result = MP3;
break;
case 3:
result = UNCOMPRESSED_LITTLE_ENDIAN;
break;
case 4:
case 5:
case 6:
result = NELLYMOSER;
break;
case 11:
result = SPEEX;
break;
}
return result;
}
}
}
Expand Up @@ -3,6 +3,6 @@ package com.swfwire.decompiler.data.swf.enums
public class SoundType
{
public static const MONO:uint = 0;
public static const STEREO:uint = 0;
public static const STEREO:uint = 1;
}
}
@@ -0,0 +1,16 @@
package com.swfwire.decompiler.data.swf.records
{
public class SoundEnvelopeRecord
{
public var pos44:uint;
public var leftLevel:uint;
public var rightLevel:uint;

public function SoundEnvelopeRecord(pos44:uint = 0, leftLevel:uint = 0, rightLevel:uint = 0)
{
this.pos44 = pos44;
this.leftLevel = leftLevel;
this.rightLevel = rightLevel;
}
}
}
@@ -0,0 +1,39 @@
package com.swfwire.decompiler.data.swf.records
{
public class SoundInfoRecord
{
public var reserved:uint;
public var syncStop:Boolean;
public var syncNoMultiple:Boolean;
public var hasEnvelope:Boolean;
public var hasLoops:Boolean;
public var hasOutPoint:Boolean;
public var hasInPoint:Boolean;
public var inPoint:uint;
public var outPoint:uint;
public var loopCount:uint;
public var envPoints:uint;
public var envelopeRecords:Vector.<SoundEnvelopeRecord>;

public function SoundInfoRecord(reserved:uint = 0, syncStop:Boolean = false, syncNoMultiple:Boolean = false, hasEnvelope:Boolean = false, hasLoops:Boolean = false, hasOutPoint:Boolean = false, hasInPoint:Boolean = false, inPoint:uint = 0, outPoint:uint = 0, loopCount:uint = 0, envPoints:uint = 0, envelopeRecords:Vector.<SoundEnvelopeRecord> = null)
{
if(envelopeRecords == null)
{
envelopeRecords = new Vector.<SoundEnvelopeRecord>;
}

this.reserved = reserved;
this.syncStop = syncStop;
this.syncNoMultiple = syncNoMultiple;
this.hasEnvelope = hasEnvelope;
this.hasLoops = hasLoops;
this.hasOutPoint = hasOutPoint;
this.hasInPoint = hasInPoint;
this.inPoint = inPoint;
this.outPoint = outPoint;
this.loopCount = loopCount;
this.envPoints = envPoints;
this.envelopeRecords = envelopeRecords;
}
}
}
@@ -1,9 +1,31 @@
package com.swfwire.decompiler.data.swf.tags
{
import com.swfwire.decompiler.data.swf.SWF;
import com.swfwire.decompiler.SWFByteArray;
import flash.utils.ByteArray;

public class DefineSoundTag extends SWFTag
{
public var soundId:uint;
public var soundFormat:uint;
public var soundRate:uint;
public var soundSize:uint;
public var soundType:uint;
public var soundSampleCount:uint;
public var soundData:ByteArray;

public function DefineSoundTag(soundId:uint = 0, soundFormat:uint = 0, soundRate:uint = 0, soundSize:uint = 0, soundType:uint = 0, soundSampleCount:uint = 0, soundData:ByteArray = null)
{
if(soundData == null)
{
soundData = new ByteArray();
}

this.soundId = soundId;
this.soundFormat = soundFormat;
this.soundRate = soundRate;
this.soundSize = soundSize;
this.soundType = soundType;
this.soundSampleCount = soundSampleCount;
this.soundData = soundData;
}
}
}
@@ -1,9 +1,16 @@
package com.swfwire.decompiler.data.swf.tags
{
import com.swfwire.decompiler.data.swf.SWF;
import com.swfwire.decompiler.SWFByteArray;

import com.swfwire.decompiler.data.swf.records.SoundInfoRecord;

public class StartSoundTag extends SWFTag
{
public var soundId:uint;
public var soundInfo:SoundInfoRecord;

public function StartSoundTag(soundId:uint = 0, soundInfo:SoundInfoRecord = null)
{
this.soundId = soundId;
this.soundInfo = soundInfo;
}
}
}

0 comments on commit 6f6a859

Please sign in to comment.