├── examples └── flashcs4 │ ├── AS3ICYTest.air │ ├── AS3ICYTest.fla │ ├── AS3ICYTest.swf │ ├── icons │ ├── aupeo16.png │ ├── aupeo32.png │ ├── aupeo48.png │ └── aupeo128.png │ ├── AS3ICYTestPlugin.fla │ ├── AS3ICYTestPlugin.swf │ ├── AS3ICYTest-app.xml │ ├── as3icy.as3proj │ └── AS3ICYTest.as ├── source └── com │ └── codeazur │ ├── as3icy │ ├── decoder │ │ ├── IFrameDecoder.as │ │ ├── HuffResult.as │ │ ├── SBI.as │ │ ├── Temporaire2.as │ │ ├── SFTable.as │ │ ├── LayerIIISideInfo.as │ │ ├── etc │ │ │ ├── VectorNumber2D.as │ │ │ ├── VectorInt2D.as │ │ │ └── VectorNumber3D.as │ │ ├── Temporaire.as │ │ ├── GRInfo.as │ │ ├── Decoder.as │ │ ├── OutputBuffer.as │ │ ├── BitReserve.as │ │ ├── HuffCodeTab.as │ │ ├── SynthesisFilter.as │ │ └── LayerIIIDecoder.as │ ├── events │ │ ├── ICYMetaDataEvent.as │ │ └── ICYFrameEvent.as │ ├── data │ │ └── MPEGFrame.as │ └── ICYSound.as │ └── utils │ ├── BitArray.as │ └── StringUtils.as └── README.markdown /examples/flashcs4/AS3ICYTest.air: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/AS3ICYTest.air -------------------------------------------------------------------------------- /examples/flashcs4/AS3ICYTest.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/AS3ICYTest.fla -------------------------------------------------------------------------------- /examples/flashcs4/AS3ICYTest.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/AS3ICYTest.swf -------------------------------------------------------------------------------- /examples/flashcs4/icons/aupeo16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/icons/aupeo16.png -------------------------------------------------------------------------------- /examples/flashcs4/icons/aupeo32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/icons/aupeo32.png -------------------------------------------------------------------------------- /examples/flashcs4/icons/aupeo48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/icons/aupeo48.png -------------------------------------------------------------------------------- /examples/flashcs4/icons/aupeo128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/icons/aupeo128.png -------------------------------------------------------------------------------- /examples/flashcs4/AS3ICYTestPlugin.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/AS3ICYTestPlugin.fla -------------------------------------------------------------------------------- /examples/flashcs4/AS3ICYTestPlugin.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/claus/as3icy/HEAD/examples/flashcs4/AS3ICYTestPlugin.swf -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/IFrameDecoder.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | import com.codeazur.as3icy.data.MPEGFrame; 4 | 5 | public interface IFrameDecoder 6 | { 7 | function decodeFrame(frame:MPEGFrame):void; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | 2 | 3 | The as3icy project is an attempt to play Shoutcast/Icecast/Limewire streams in Adobe AIR 1.5 and FP10. 4 | 5 | More info here: 6 | [http://wahlers.com.br/claus/blog/realtime-mp3-decoding-in-actionscript-3/](http://wahlers.com.br/claus/blog/realtime-mp3-decoding-in-actionscript-3/) 7 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/HuffResult.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class HuffResult 4 | { 5 | public var x:int; 6 | public var y:int; 7 | public var v:int; 8 | public var w:int; 9 | 10 | public function HuffResult() { 11 | reset(); 12 | } 13 | 14 | public function reset():void { 15 | x = 0; 16 | y = 0; 17 | v = 0; 18 | w = 0; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/SBI.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class SBI 4 | { 5 | public var l:Vector.; 6 | public var s:Vector.; 7 | 8 | public function SBI(thel:Vector. = null, thes:Vector. = null) 9 | { 10 | l = (thel != null) ? thel : new Vector.(23, true); 11 | s = (thes != null) ? thes : new Vector.(14, true); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/Temporaire2.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | import com.codeazur.as3icy.decoder.etc.VectorInt2D; 4 | 5 | public class Temporaire2 6 | { 7 | public var l:Vector.; 8 | public var s:Vector.>; 9 | 10 | public function Temporaire2() 11 | { 12 | l = new Vector.(23, true); 13 | s = (new VectorInt2D(3, 13)).v; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/SFTable.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class SFTable 4 | { 5 | public var l:Vector.; 6 | public var s:Vector.; 7 | 8 | public function SFTable(thel:Vector. = null, thes:Vector. = null) 9 | { 10 | l = (thel != null) ? thel : new Vector.(5, true); 11 | s = (thes != null) ? thes : new Vector.(3, true); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/LayerIIISideInfo.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class LayerIIISideInfo 4 | { 5 | public var main_data_begin:int = 0; 6 | public var private_bits:int = 0; 7 | public var ch:Vector.; 8 | 9 | public function LayerIIISideInfo() 10 | { 11 | ch = new Vector.(2, true); 12 | ch[0] = new Temporaire(); 13 | ch[1] = new Temporaire(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/etc/VectorNumber2D.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder.etc 2 | { 3 | public class VectorNumber2D 4 | { 5 | public var v:Vector.>; 6 | 7 | public function VectorNumber2D(level0Size:uint, level1Size:uint) 8 | { 9 | v = new Vector.>(level0Size, true); 10 | for (var i:uint = 0; i < level0Size; i++) { 11 | v[i] = new Vector.(level1Size, true); 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/Temporaire.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | import com.codeazur.as3icy.decoder.etc.VectorInt2D; 4 | 5 | public class Temporaire 6 | { 7 | public var scfsi:Vector.; 8 | public var gr:Vector.; 9 | 10 | public function Temporaire() 11 | { 12 | scfsi = new Vector.(4, true); 13 | gr = new Vector.(2, true); 14 | gr[0] = new GRInfo(); 15 | gr[1] = new GRInfo(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/etc/VectorInt2D.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder.etc 2 | { 3 | public class VectorInt2D 4 | { 5 | public var v:Vector.>; 6 | 7 | public function VectorInt2D(level0Size:uint, level1Size:int = -1) 8 | { 9 | var hasLevel1Size:Boolean = (level1Size > -1); 10 | v = new Vector.>(level0Size, true); 11 | for (var i:uint = 0; i < level0Size; i++) { 12 | v[i] = new Vector.(hasLevel1Size ? level1Size : 0, hasLevel1Size); 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/etc/VectorNumber3D.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder.etc 2 | { 3 | public class VectorNumber3D 4 | { 5 | public var v:Vector.>>; 6 | 7 | public function VectorNumber3D(level0Size:uint, level1Size:uint, level2Size:uint) 8 | { 9 | v = new Vector.>>(level0Size, true); 10 | for (var i:uint = 0; i < level0Size; i++) { 11 | v[i] = new Vector.>(level1Size, true); 12 | for (var j:uint = 0; j < level1Size; j++) { 13 | v[i][j] = new Vector.(level2Size, true); 14 | } 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/GRInfo.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class GRInfo 4 | { 5 | public var part2_3_length:int = 0; 6 | public var big_values:int = 0; 7 | public var global_gain:int = 0; 8 | public var scalefac_compress:int = 0; 9 | public var window_switching_flag:int = 0; 10 | public var block_type:int = 0; 11 | public var mixed_block_flag:int = 0; 12 | public var table_select:Vector.; 13 | public var subblock_gain:Vector.; 14 | public var region0_count:int = 0; 15 | public var region1_count:int = 0; 16 | public var preflag:int = 0; 17 | public var scalefac_scale:int = 0; 18 | public var count1table_select:int = 0; 19 | 20 | public function GRInfo() 21 | { 22 | table_select = new Vector.(3, true); 23 | subblock_gain = new Vector.(3, true); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/events/ICYMetaDataEvent.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.events 2 | { 3 | import flash.events.Event; 4 | 5 | public class ICYMetaDataEvent extends Event 6 | { 7 | public static const METADATA:String = "icyMetaData"; 8 | 9 | protected var _metaData:String; 10 | 11 | public function ICYMetaDataEvent(eventType:String, aMetaData:String = "", bubbles:Boolean = false, cancelable:Boolean = false) 12 | { 13 | super(eventType, bubbles, cancelable); 14 | _metaData = aMetaData; 15 | } 16 | 17 | public function get metaData():String { 18 | return _metaData; 19 | } 20 | 21 | override public function toString():String { 22 | return "[ICYMetaDataEvent metaData=" + metaData + "]"; 23 | } 24 | 25 | override public function clone():Event { 26 | return new ICYMetaDataEvent(type, metaData, bubbles, cancelable); 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/events/ICYFrameEvent.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.events 2 | { 3 | import flash.events.Event; 4 | import flash.utils.ByteArray; 5 | 6 | import com.codeazur.as3icy.data.MPEGFrame; 7 | 8 | public class ICYFrameEvent extends Event 9 | { 10 | public static const FRAME:String = "icyFrame"; 11 | 12 | protected var _frame:MPEGFrame; 13 | 14 | public function ICYFrameEvent(eventType:String, aFrame:MPEGFrame, bubbles:Boolean = false, cancelable:Boolean = false) 15 | { 16 | super(eventType, bubbles, cancelable); 17 | _frame = aFrame; 18 | } 19 | 20 | public function get frame():MPEGFrame { 21 | return _frame; 22 | } 23 | 24 | override public function toString():String { 25 | return "[ICYFrameEvent frame=" + frame.toString() + "]"; 26 | } 27 | 28 | override public function clone():Event { 29 | return new ICYFrameEvent(type, frame, bubbles, cancelable); 30 | } 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/Decoder.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | import com.codeazur.as3icy.data.MPEGFrame; 4 | 5 | import flash.utils.ByteArray; 6 | 7 | public class Decoder 8 | { 9 | protected var l3decoder:LayerIIIDecoder; 10 | 11 | protected var output:OutputBuffer; 12 | 13 | public function Decoder(output_buffer:OutputBuffer) { 14 | output = output_buffer; 15 | } 16 | 17 | public function get outputBuffer():OutputBuffer { 18 | return output 19 | } 20 | 21 | public function decodeFrame(frame:MPEGFrame):void { 22 | retrieveDecoder(frame).decodeFrame(frame); 23 | } 24 | 25 | protected function retrieveDecoder(frame:MPEGFrame):IFrameDecoder { 26 | var decoder:IFrameDecoder; 27 | switch(frame.layer) { 28 | case MPEGFrame.MPEG_LAYER_III: 29 | if (l3decoder == null) { 30 | l3decoder = new LayerIIIDecoder(output); 31 | } 32 | decoder = l3decoder; 33 | break; 34 | default: 35 | throw(new Error("Unsupported MPEG Layer: " + frame.layer)); 36 | } 37 | return decoder; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/OutputBuffer.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class OutputBuffer 4 | { 5 | public static const BUFFERSIZE:uint = 2 * 1152; // max. 2 * 1152 samples per frame 6 | public static const MAXCHANNELS:uint = 2; // max. number of channels 7 | 8 | protected var buffer:Vector.; 9 | protected var bufferp:Vector.; 10 | protected var channels:uint; 11 | protected var frequency:uint; 12 | 13 | public function OutputBuffer(sample_frequency:uint = 44100, number_of_channels:uint = 2) 14 | { 15 | buffer = new Vector.(BUFFERSIZE, true); 16 | bufferp = new Vector.(MAXCHANNELS, true); 17 | frequency = sample_frequency; 18 | channels = number_of_channels; 19 | clear_buffer(); 20 | } 21 | 22 | public function getChannelCount():uint { 23 | return channels; 24 | } 25 | 26 | public function getSampleFrequency():uint { 27 | return frequency; 28 | } 29 | 30 | public function getBuffer():Vector. { 31 | return buffer; 32 | } 33 | 34 | public function getBufferLength():uint { 35 | return bufferp[0]; 36 | } 37 | 38 | public function appendSamples(channel:uint, f:Vector.):void { 39 | var pos:uint = bufferp[channel]; 40 | var fs:Number; 41 | for (var i:uint = 0; i < 32; ++i) { 42 | fs = f[i]; 43 | fs = (fs > 1.0 ? 1.0 : (fs < -1.0 ? -1.0 : fs)); 44 | buffer[pos] = fs; 45 | pos += channels; 46 | } 47 | bufferp[channel] = pos; 48 | } 49 | 50 | public function clear_buffer():void { 51 | for (var i:uint = 0; (i < channels) && (i < MAXCHANNELS); i++) { 52 | bufferp[i] = i; 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/flashcs4/AS3ICYTest-app.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.codeazur.AS3ICYTest 5 | 6 | 1.0.004 7 | 8 | AS3ICYTest 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | The as3icy project 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | AS3ICYTest.swf 90 | standard 91 | false 92 | true 93 | false 94 | true 95 | false 96 | 97 | 98 | 99 | icons/aupeo128.png 100 | icons/aupeo48.png 101 | icons/aupeo32.png 102 | icons/aupeo16.png 103 | 104 | 105 | false 106 | 107 | false 108 | 109 | 110 | 111 | 112 | AUPEO 113 | 114 | AUPEO 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /examples/flashcs4/as3icy.as3proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 81 | -------------------------------------------------------------------------------- /source/com/codeazur/utils/BitArray.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.utils 2 | { 3 | import flash.utils.ByteArray; 4 | 5 | public class BitArray extends ByteArray 6 | { 7 | protected var bitsPending:uint = 0; 8 | 9 | public function readBits(bits:uint, bitBuffer:uint = 0):uint { 10 | if (bits == 0) { return bitBuffer; } 11 | var partial:uint; 12 | var bitsConsumed:uint; 13 | if (bitsPending > 0) { 14 | var byte:uint = this[position - 1] & (0xff >> (8 - bitsPending)); 15 | bitsConsumed = Math.min(bitsPending, bits); 16 | bitsPending -= bitsConsumed; 17 | partial = byte >> bitsPending; 18 | } else { 19 | bitsConsumed = Math.min(8, bits); 20 | bitsPending = 8 - bitsConsumed; 21 | partial = readUnsignedByte() >> bitsPending; 22 | } 23 | bits -= bitsConsumed; 24 | bitBuffer = (bitBuffer << bitsConsumed) | partial; 25 | return (bits > 0) ? readBits(bits, bitBuffer) : bitBuffer; 26 | } 27 | 28 | public function writeBits(bits:uint, value:uint):void { 29 | if (bits == 0) { return; } 30 | value &= (0xffffffff >>> (32 - bits)); 31 | var bitsConsumed:uint; 32 | if (bitsPending > 0) { 33 | if (bitsPending > bits) { 34 | this[position - 1] |= value << (bitsPending - bits); 35 | bitsConsumed = bits; 36 | bitsPending -= bits; 37 | } else if (bitsPending == bits) { 38 | this[position - 1] |= value; 39 | bitsConsumed = bits; 40 | bitsPending = 0; 41 | } else { 42 | this[position - 1] |= value >> (bits - bitsPending); 43 | bitsConsumed = bitsPending; 44 | bitsPending = 0; 45 | } 46 | } else { 47 | bitsConsumed = Math.min(8, bits); 48 | bitsPending = 8 - bitsConsumed; 49 | writeByte((value >> (bits - bitsConsumed)) << bitsPending); 50 | } 51 | bits -= bitsConsumed; 52 | if (bits > 0) { 53 | writeBits(bits, value); 54 | } 55 | } 56 | 57 | public function resetBitsPending():void { 58 | //if (bitsPending > 0) { 59 | // trace("### pending:" + bitsPending + " pos:" + (position - 1)); 60 | //} 61 | bitsPending = 0; 62 | } 63 | 64 | public function getMinBits(a:uint, b:uint = 0, c:uint = 0, d:uint = 0):uint { 65 | var val:uint = a | b | c | d; 66 | var bits:uint = 1; 67 | 68 | do { 69 | val >>>= 1; 70 | ++bits; 71 | } 72 | while (val != 0) 73 | 74 | return bits; 75 | } 76 | 77 | public function getMinSBits(a:int, b:int = 0, c:int = 0, d:int = 0):uint { 78 | return getMinBits(Math.abs(a), Math.abs(b), Math.abs(c), Math.abs(d)); 79 | } 80 | 81 | public function getMinFBits(a:Number, b:Number = 0, c:Number = 0, d:Number = 0):uint { 82 | return getMinSBits(a * 65536, b * 65536, c * 65536, d * 65536); 83 | } 84 | 85 | public function calculateMaxBits(signed:Boolean, ...values):uint { 86 | var b:uint = 0; 87 | var vmax:int = int.MIN_VALUE; 88 | for(var i:uint = 0; i < values.length; i++) { 89 | if(values[i] >= 0) { 90 | b |= values[i]; 91 | } else { 92 | b |= ~values[i] << 1; 93 | } 94 | if(signed && (vmax < values[i])) { 95 | vmax = values[i]; 96 | } 97 | } 98 | var bits:uint = b.toString(2).length; 99 | if(signed && vmax > 0 && vmax.toString(2).length >= bits) { 100 | bits++; 101 | } 102 | return bits; 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/BitReserve.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | /** 4 | * Implementation of Bit Reservoir for Layer III. 5 | *

6 | * The implementation stores single bits as a word in the buffer. If 7 | * a bit is set, the corresponding word in the buffer will be non-zero. 8 | * If a bit is clear, the corresponding word is zero. Although this 9 | * may seem waseful, this can be a factor of two quicker than 10 | * packing 8 bits to a byte and extracting. 11 | *

12 | */ 13 | 14 | // REVIEW: there is no range checking, so buffer underflow or overflow 15 | // can silently occur. 16 | public class BitReserve 17 | { 18 | /** 19 | * Size of the internal buffer to store the reserved bits. 20 | * Must be a power of 2. And x8, as each bit is stored as a single 21 | * entry. 22 | */ 23 | protected static const BUFSIZE:uint = 4096 * 8; 24 | 25 | /** 26 | * Mask that can be used to quickly implement the 27 | * modulus operation on BUFSIZE. 28 | */ 29 | protected static const BUFSIZE_MASK:uint = BUFSIZE - 1; 30 | 31 | protected var offset:int; 32 | protected var totbit:int; 33 | protected var buf_byte_idx:int; 34 | protected var buf:Vector.; 35 | 36 | public function BitReserve() 37 | { 38 | buf = new Vector.(BUFSIZE, true); 39 | offset = 0; 40 | totbit = 0; 41 | buf_byte_idx = 0; 42 | } 43 | 44 | /** 45 | * Return totbit Field. 46 | */ 47 | public function get hsstell():int { 48 | return totbit; 49 | } 50 | 51 | /** 52 | * Read a number of bits from the bit stream. 53 | * @param n the number of 54 | */ 55 | public function hgetbits(n:int):int { 56 | totbit += n; 57 | var val:int = 0; 58 | var pos:int = buf_byte_idx; 59 | if (pos + n < BUFSIZE) { 60 | while (n-- > 0) { 61 | val <<= 1; 62 | if (buf[pos++] != 0) { 63 | val |= 1; 64 | } 65 | } 66 | } else { 67 | while (n-- > 0) { 68 | val <<= 1; 69 | if (buf[pos] != 0) { 70 | val |= 1; 71 | } 72 | pos = (pos + 1) & BUFSIZE_MASK; 73 | } 74 | } 75 | buf_byte_idx = pos; 76 | return val; 77 | } 78 | 79 | /** 80 | * Returns next bit from reserve. 81 | * @returns 0 if next bit is reset, or 1 if next bit is set. 82 | */ 83 | public function hget1bit():int { 84 | totbit++; 85 | var val:int = buf[buf_byte_idx]; 86 | buf_byte_idx = (buf_byte_idx + 1) & BUFSIZE_MASK; 87 | return val; 88 | } 89 | 90 | /** 91 | * Write 8 bits into the bit stream. 92 | */ 93 | public function hputbuf(val:int):void { 94 | var ofs:int = offset; 95 | buf[ofs++] = val & 0x80; 96 | buf[ofs++] = val & 0x40; 97 | buf[ofs++] = val & 0x20; 98 | buf[ofs++] = val & 0x10; 99 | buf[ofs++] = val & 0x08; 100 | buf[ofs++] = val & 0x04; 101 | buf[ofs++] = val & 0x02; 102 | buf[ofs++] = val & 0x01; 103 | if (ofs == BUFSIZE) { 104 | offset = 0; 105 | } else { 106 | offset = ofs; 107 | } 108 | } 109 | 110 | /** 111 | * Rewind n bits in stream. 112 | */ 113 | public function rewindNbits(n:int):void { 114 | totbit -= n; 115 | buf_byte_idx -= n; 116 | if (buf_byte_idx < 0) { 117 | buf_byte_idx += BUFSIZE; 118 | } 119 | } 120 | 121 | /** 122 | * Rewind n bytes in stream. 123 | */ 124 | public function rewindNbytes(n:int):void { 125 | var bits:int = (n << 3); 126 | totbit -= bits; 127 | buf_byte_idx -= bits; 128 | if (buf_byte_idx < 0) { 129 | buf_byte_idx += BUFSIZE; 130 | } 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /examples/flashcs4/AS3ICYTest.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.codeazur.as3icy.data.MPEGFrame; 4 | import com.codeazur.as3icy.ICYSound; 5 | import com.codeazur.as3icy.events.ICYFrameEvent; 6 | import com.codeazur.as3icy.events.ICYMetaDataEvent; 7 | 8 | import flash.display.Sprite; 9 | import flash.net.*; 10 | import flash.events.*; 11 | 12 | public class AS3ICYTest extends Sprite 13 | { 14 | private var icySound:ICYSound; 15 | 16 | public function AS3ICYTest() 17 | { 18 | //var req:URLRequest = new URLRequest("http://stream.m945.mwn.de/m945-hq.mp3"); 19 | //var req:URLRequest = new URLRequest("http://stream.m945.mwn.de/m945-lq.mp3"); 20 | var req:URLRequest = new URLRequest("http://72.233.14.70/hype"); 21 | //var req:URLRequest = new URLRequest("http://gffstream.ic.llnwd.net/stream/gffstream_mp3_w49a"); 22 | //var req:URLRequest = new URLRequest("http://gffstream.ic.llnwd.net/stream/gffstream_stream_wdr_einslive_a"); 23 | req.requestHeaders = [ new URLRequestHeader("Icy-Metadata", "1") ]; 24 | icySound = new ICYSound(); 25 | icySound.addEventListener(ICYMetaDataEvent.METADATA, metaDataHandler); 26 | icySound.addEventListener(ICYFrameEvent.FRAME, frameHandler); 27 | CONFIG::AIR { 28 | icySound.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpResponseStatusHandler); 29 | } 30 | icySound.load(req); 31 | icySound.play(); 32 | } 33 | 34 | protected function httpResponseStatusHandler(e:HTTPStatusEvent):void { 35 | tfStationName.text = icySound.icyName.toUpperCase(); 36 | tfStationDescription.text = (icySound.icyDescription.length > 0) ? icySound.icyDescription : "No description"; 37 | tfStationUrl.htmlText = "" + icySound.icyUrl + ""; 38 | tfServer.htmlText = "Server: " + icySound.icyServer + ""; 39 | tfMetaInterval.htmlText = "Metadata interval: " + icySound.icyMetaInterval + ""; 40 | } 41 | 42 | protected function metaDataHandler(e:ICYMetaDataEvent):void { 43 | tfMetaReceived.htmlText = "Metadata received: " + icySound.metaDataLoaded + " blocks, " + icySound.metaDataBytesLoaded + " bytes"; 44 | if (e.metaData.length > 0) { 45 | tfNowPlayingHeadline.text = "Now playing:"; 46 | tfTitle.text = e.metaData.slice(13, -2).toUpperCase(); 47 | } 48 | } 49 | 50 | protected function frameHandler(e:ICYFrameEvent):void { 51 | tfFramesReceived.htmlText = "MPEG frames received: " + icySound.framesLoaded + ""; 52 | var encoding:String = "unknown"; 53 | switch(icySound.mpegFrame.version) { 54 | case MPEGFrame.MPEG_VERSION_1_0: encoding = "1.0 "; break; 55 | case MPEGFrame.MPEG_VERSION_2_0: encoding = "2.0 "; break; 56 | case MPEGFrame.MPEG_VERSION_2_5: encoding = "2.5 "; break; 57 | } 58 | switch(icySound.mpegFrame.layer) { 59 | case MPEGFrame.MPEG_LAYER_I: encoding += "Layer I"; break; 60 | case MPEGFrame.MPEG_LAYER_II: encoding += "Layer II"; break; 61 | case MPEGFrame.MPEG_LAYER_III: encoding += "Layer III"; break; 62 | } 63 | tfMPEGEncoding.htmlText = "Encoding: MPEG " + encoding + ""; 64 | tfMPEGBitrate.htmlText = "Bitrate: " + icySound.mpegFrame.bitrate + " kbit/s"; 65 | tfMPEGSamplingrate.htmlText = "Samplingrate: " + icySound.mpegFrame.samplingrate + " Hz"; 66 | var channelMode:String = "unknown"; 67 | switch(icySound.mpegFrame.channelMode) { 68 | case 0: channelMode = "Stereo"; break; 69 | case 1: channelMode = "Joint stereo"; break; 70 | case 2: channelMode = "Dual channel"; break; 71 | case 3: channelMode = "Mono"; break; 72 | } 73 | tfMPEGChannelMode.htmlText = "Channel mode: " + channelMode + ""; 74 | // 75 | e.preventDefault(); 76 | addEventListener(Event.ENTER_FRAME, enterFrameHandler); 77 | } 78 | 79 | protected function enterFrameHandler(e:Event):void { 80 | removeEventListener(Event.ENTER_FRAME, enterFrameHandler); 81 | icySound.resume(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/data/MPEGFrame.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.data 2 | { 3 | import com.codeazur.utils.BitArray; 4 | import flash.utils.ByteArray; 5 | 6 | public class MPEGFrame 7 | { 8 | public static const MPEG_VERSION_1_0:uint = 0; 9 | public static const MPEG_VERSION_2_0:uint = 1; 10 | public static const MPEG_VERSION_2_5:uint = 2; 11 | 12 | public static const MPEG_LAYER_I:uint = 0; 13 | public static const MPEG_LAYER_II:uint = 1; 14 | public static const MPEG_LAYER_III:uint = 2; 15 | 16 | public static const CHANNEL_MODE_STEREO:uint = 0; 17 | public static const CHANNEL_MODE_JOINT_STEREO:uint = 1; 18 | public static const CHANNEL_MODE_DUAL:uint = 2; 19 | public static const CHANNEL_MODE_MONO:uint = 3; 20 | 21 | protected static var mpegBitrates:Array = [ 22 | [ [0, 32, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, -1], 23 | [0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, -1], 24 | [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1] ], 25 | [ [0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, -1], 26 | [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1], 27 | [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1] ] 28 | ]; 29 | protected static var mpegSamplingRates:Array = [ 30 | [44100, 48000, 32000], 31 | [22050, 24000, 16000], 32 | [11025, 12000, 8000] 33 | ]; 34 | 35 | protected var _version:uint; 36 | protected var _layer:uint; 37 | protected var _bitrate:uint; 38 | protected var _samplingRate:uint; 39 | protected var _samplingRateIndex:uint; 40 | protected var _padding:Boolean; 41 | protected var _channelMode:uint; 42 | protected var _channelModeExt:uint; 43 | protected var _copyright:Boolean; 44 | protected var _original:Boolean; 45 | protected var _emphasis:uint; 46 | 47 | protected var _size:uint; 48 | protected var _slots:uint; 49 | 50 | protected var _header:ByteArray; 51 | protected var _crc:ByteArray; 52 | protected var _data:BitArray; 53 | 54 | protected var _hasCRC:Boolean; 55 | 56 | protected var _samples:uint = 1152; 57 | 58 | public function MPEGFrame() { 59 | init(); 60 | } 61 | 62 | public function get version():uint { return _version; } 63 | public function get layer():uint { return _layer; } 64 | public function get bitrate():uint { return _bitrate; } 65 | public function get samplingrate():uint { return _samplingRate; } 66 | public function get samplingrateIndex():uint { return _samplingRateIndex; } 67 | public function get padding():Boolean { return _padding; } 68 | public function get channelMode():uint { return _channelMode; } 69 | public function get channelModeExt():uint { return _channelModeExt; } 70 | public function get copyright():Boolean { return _copyright; } 71 | public function get original():Boolean { return _original; } 72 | public function get emphasis():uint { return _emphasis; } 73 | 74 | public function get size():uint { return _size; } 75 | public function get slots():uint { return _slots; } 76 | 77 | public function get hasCRC():Boolean { return _hasCRC; } 78 | public function get crc():uint { _crc.position = 0; return _crc.readUnsignedShort(); } 79 | 80 | public function get samples():uint { return _samples; } 81 | 82 | public function get data():BitArray { return _data; } 83 | 84 | public function setHeaderByteAt(index:uint, value:uint):void { 85 | switch(index) { 86 | case 0: 87 | if (value != 0xff) { 88 | throw(new Error("Not a MPEG header.")); 89 | } 90 | break; 91 | case 1: 92 | if ((value & 0xe0) != 0xe0) { 93 | throw(new Error("Not a MPEG header.")); 94 | } 95 | // get the mpeg version (we only support mpeg 1.0 and 2.0) 96 | var mpegVersionBits:uint = (value & 0x18) >> 3; 97 | switch(mpegVersionBits) { 98 | case 3: _version = MPEG_VERSION_1_0; break; 99 | case 2: _version = MPEG_VERSION_2_0; break; 100 | default: throw(new Error("Unsupported MPEG version.")); 101 | } 102 | // get the mpeg layer version (we only support layer III) 103 | var mpegLayerBits:uint = (value & 0x06) >> 1; 104 | switch(mpegLayerBits) { 105 | case 1: _layer = MPEG_LAYER_III; break; 106 | default: throw(new Error("Unsupported MPEG layer.")); 107 | } 108 | // is the frame secured by crc? 109 | _hasCRC = !((value & 0x01) != 0); 110 | break; 111 | case 2: 112 | var bitrateIndex:uint = ((value & 0xf0) >> 4); 113 | // get the frame's bitrate 114 | if (bitrateIndex == 0 || bitrateIndex == 0x0f) { 115 | throw(new Error("Unsupported bitrate index.")); 116 | } 117 | _bitrate = mpegBitrates[_version][_layer][bitrateIndex]; 118 | // get the frame's samplingrate 119 | _samplingRateIndex = ((value & 0x0c) >> 2); 120 | if (_samplingRateIndex == 3) { 121 | throw(new Error("Unsupported samplingrate index.")); 122 | } 123 | _samplingRate = mpegSamplingRates[_version][_samplingRateIndex]; 124 | // is the frame padded? 125 | _padding = ((value & 0x02) == 0x02); 126 | break; 127 | case 3: 128 | // get the frame's channel mode: 129 | // 0: stereo 130 | // 1: joint stereo 131 | // 2: dual channel 132 | // 3: mono 133 | _channelMode = ((value & 0xc0) >> 6); 134 | // get the frame's extended channel mode (only for joint stereo): 135 | _channelModeExt = ((value & 0x30) >> 4); 136 | // get the copyright flag 137 | _copyright = ((value & 0x08) == 0x08); 138 | // get the original flag 139 | _original = ((value & 0x04) == 0x04); 140 | // get the emphasis: 141 | // 0: none 142 | // 1: 50/15 ms 143 | // 2: reserved 144 | // 3: ccit j.17 145 | _emphasis = (value & 0x02); 146 | // calculate frame size and number of slots 147 | calculateSize(); 148 | break; 149 | default: 150 | throw(new Error("Index out of bounds.")); 151 | } 152 | // store the raw header byte for easy access 153 | _header[index] = value; 154 | } 155 | 156 | public function setCRCByteAt(index:uint, value:uint):void { 157 | if (index > 1) { 158 | throw(new Error("Index out of bounds.")); 159 | } 160 | _crc[index] = value; 161 | } 162 | 163 | protected function calculateSize():void { 164 | var headerSize:uint = 4 + (hasCRC ? 2 : 0); 165 | if (layer == MPEG_LAYER_I) { 166 | _size = Math.floor((12000.0 * bitrate) / samplingrate); 167 | if (padding) { 168 | _size++; 169 | } 170 | // one slot is 4 bytes long 171 | _size <<= 2; 172 | _slots = 0; 173 | } else { 174 | _size = Math.floor(((version == MPEG_VERSION_1_0) ? 144000.0 : 72000.0) * bitrate / samplingrate); 175 | if (padding) { 176 | _size++; 177 | } 178 | if (layer == MPEG_LAYER_III) { 179 | if (version == MPEG_VERSION_1_0) { 180 | _slots = _size - ((channelMode == CHANNEL_MODE_MONO) ? 17 : 32) - headerSize; 181 | } else { 182 | _slots = _size - ((channelMode == CHANNEL_MODE_MONO) ? 9 : 17) - headerSize; 183 | } 184 | } else { 185 | _slots = 0; 186 | } 187 | } 188 | // subtract header size 189 | _size -= headerSize; 190 | } 191 | 192 | protected function init():void { 193 | _header = new ByteArray(); 194 | _header.writeByte(0); 195 | _header.writeByte(0); 196 | _header.writeByte(0); 197 | _header.writeByte(0); 198 | _crc = new ByteArray(); 199 | _crc.writeByte(0); 200 | _crc.writeByte(0); 201 | _data = new BitArray(); 202 | } 203 | 204 | public function getFrame():ByteArray { 205 | var ba:ByteArray = new ByteArray(); 206 | ba.writeBytes(_header, 0, 4); 207 | if(hasCRC) { 208 | ba.writeBytes(_crc, 0, 2); 209 | } 210 | ba.writeBytes(_data); 211 | return ba; 212 | } 213 | 214 | public function toString():String { 215 | var encoding:String = "MPEG "; 216 | switch(version) { 217 | case MPEGFrame.MPEG_VERSION_1_0: encoding += "1.0 "; break; 218 | case MPEGFrame.MPEG_VERSION_2_0: encoding += "2.0 "; break; 219 | case MPEGFrame.MPEG_VERSION_2_5: encoding += "2.5 "; break; 220 | default: encoding += "?.? "; break; 221 | } 222 | switch(layer) { 223 | case MPEGFrame.MPEG_LAYER_I: encoding += "Layer I"; break; 224 | case MPEGFrame.MPEG_LAYER_II: encoding += "Layer II"; break; 225 | case MPEGFrame.MPEG_LAYER_III: encoding += "Layer III"; break; 226 | default: encoding += "Layer ?"; break; 227 | } 228 | var channel:String = "unknown"; 229 | switch(channelMode) { 230 | case 0: channel = "Stereo"; break; 231 | case 1: channel = "Joint stereo"; break; 232 | case 2: channel = "Dual channel"; break; 233 | case 3: channel = "Mono"; break; 234 | } 235 | return encoding + ", " + bitrate + " kbit/s, " + samplingrate + " Hz, " + channel + ", " + slots + " slots]"; 236 | } 237 | 238 | protected static var soundSWFBytes:Array = [ 239 | 0x46, 0x57, 0x53, 0x09, 0x28, 0x02, 0x00, 0x00, 0x78, 0x00, 0x04, 0xE2, 0x00, 0x00, 0x0E, 0xA6, 240 | 0x00, 0x00, 0x18, 0x01, 0x00, 0x44, 0x11, 0x09, 0x00, 0x00, 0x00, 0x44, 0x10, 0xE8, 0x03, 0x3C, 241 | 0x00, 0x43, 0x02, 0x86, 0x9C, 0xA7, 0x5A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 242 | 0x02, 0x00, 0x5C, 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1, 0x4F, 0x2D, 0x96, 0x0C, 0x01, 243 | 0x00, 0x00, 0xCE, 0x0A, 0x53, 0x6F, 0x75, 0x6E, 0x64, 0x50, 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 244 | 0x72, 0x00, 0x0A, 0x0E, 0x01, 0x00, 0x01, 0x00, 0x65, 0x6D, 0x70, 0x74, 0x79, 0x00, 0xBF, 0x14, 245 | 0xA4, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x31, 0x00, 0x10, 246 | 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x0D, 0x53, 0x6F, 0x75, 0x6E, 0x64, 0x50, 0x72, 247 | 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x0D, 0x66, 0x6C, 0x61, 0x73, 0x68, 0x2E, 0x64, 0x69, 0x73, 248 | 0x70, 0x6C, 0x61, 0x79, 0x06, 0x53, 0x70, 0x72, 0x69, 0x74, 0x65, 0x05, 0x73, 0x6F, 0x75, 0x6E, 249 | 0x64, 0x09, 0x53, 0x6F, 0x75, 0x6E, 0x64, 0x49, 0x74, 0x65, 0x6D, 0x0B, 0x66, 0x6C, 0x61, 0x73, 250 | 0x68, 0x2E, 0x6D, 0x65, 0x64, 0x69, 0x61, 0x05, 0x53, 0x6F, 0x75, 0x6E, 0x64, 0x06, 0x4F, 0x62, 251 | 0x6A, 0x65, 0x63, 0x74, 0x0C, 0x66, 0x6C, 0x61, 0x73, 0x68, 0x2E, 0x65, 0x76, 0x65, 0x6E, 0x74, 252 | 0x73, 0x0F, 0x45, 0x76, 0x65, 0x6E, 0x74, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 253 | 0x72, 0x0D, 0x44, 0x69, 0x73, 0x70, 0x6C, 0x61, 0x79, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x11, 254 | 0x49, 0x6E, 0x74, 0x65, 0x72, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x4F, 0x62, 0x6A, 0x65, 0x63, 255 | 0x74, 0x16, 0x44, 0x69, 0x73, 0x70, 0x6C, 0x61, 0x79, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x43, 256 | 0x6F, 0x6E, 0x74, 0x61, 0x69, 0x6E, 0x65, 0x72, 0x08, 0x16, 0x01, 0x16, 0x03, 0x18, 0x02, 0x05, 257 | 0x00, 0x16, 0x07, 0x18, 0x06, 0x16, 0x0A, 0x02, 0x01, 0x01, 0x0C, 0x07, 0x01, 0x02, 0x07, 0x02, 258 | 0x04, 0x07, 0x04, 0x05, 0x07, 0x01, 0x06, 0x07, 0x05, 0x08, 0x07, 0x01, 0x09, 0x07, 0x07, 0x0B, 259 | 0x07, 0x02, 0x0C, 0x07, 0x02, 0x0D, 0x07, 0x02, 0x0E, 0x09, 0x06, 0x01, 0x06, 0x00, 0x00, 0x00, 260 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 261 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x02, 0x09, 0x03, 0x00, 0x01, 0x01, 0x03, 0x00, 262 | 0x00, 0x04, 0x00, 0x04, 0x05, 0x09, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x02, 263 | 0x01, 0x01, 0x04, 0x01, 0x00, 0x05, 0x01, 0x04, 0x04, 0x00, 0x01, 0x06, 0x00, 0x01, 0x01, 0x08, 264 | 0x09, 0x03, 0xD0, 0x30, 0x47, 0x00, 0x00, 0x01, 0x01, 0x01, 0x09, 0x0A, 0x06, 0xD0, 0x30, 0xD0, 265 | 0x49, 0x00, 0x47, 0x00, 0x00, 0x02, 0x02, 0x01, 0x01, 0x08, 0x23, 0xD0, 0x30, 0x65, 0x00, 0x60, 266 | 0x06, 0x30, 0x60, 0x07, 0x30, 0x60, 0x08, 0x30, 0x60, 0x09, 0x30, 0x60, 0x0A, 0x30, 0x60, 0x02, 267 | 0x30, 0x60, 0x02, 0x58, 0x00, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x1D, 0x68, 0x01, 0x47, 0x00, 0x00, 268 | 0x03, 0x01, 0x01, 0x05, 0x06, 0x03, 0xD0, 0x30, 0x47, 0x00, 0x00, 0x04, 0x01, 0x01, 0x06, 0x07, 269 | 0x06, 0xD0, 0x30, 0xD0, 0x49, 0x00, 0x47, 0x00, 0x00, 0x05, 0x02, 0x01, 0x01, 0x05, 0x17, 0xD0, 270 | 0x30, 0x5D, 0x0B, 0x60, 0x06, 0x30, 0x60, 0x07, 0x30, 0x60, 0x05, 0x30, 0x60, 0x05, 0x58, 0x01, 271 | 0x1D, 0x1D, 0x1D, 0x68, 0x04, 0x47, 0x00, 0x00, 0x1E, 0x13, 0x02, 0x00, 0x01, 0x00, 0x53, 0x6F, 272 | 0x75, 0x6E, 0x64, 0x49, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x53, 0x6F, 0x75, 0x6E, 0x64, 0x50, 273 | 0x72, 0x6F, 0x76, 0x69, 0x64, 0x65, 0x72, 0x00 274 | ]; 275 | protected static var soundSWF:ByteArray = createSoundSWF(); 276 | protected static function createSoundSWF():ByteArray { 277 | var ba:ByteArray = new ByteArray(); 278 | for (var i:uint = 0; i < soundSWFBytes.length; i++) { 279 | ba.writeByte(soundSWFBytes[i]); 280 | } 281 | return ba; 282 | } 283 | } 284 | 285 | } -------------------------------------------------------------------------------- /source/com/codeazur/utils/StringUtils.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.utils 2 | { 3 | import flash.events.*; 4 | 5 | public class StringUtils 6 | { 7 | public static function trim(input:String):String { 8 | return StringUtils.ltrim(StringUtils.rtrim(input)); 9 | } 10 | 11 | public static function ltrim(input:String):String { 12 | if (input != null) { 13 | var size:Number = input.length; 14 | for(var i:Number = 0; i < size; i++) { 15 | if(input.charCodeAt(i) > 32) { 16 | return input.substring(i); 17 | } 18 | } 19 | } 20 | return ""; 21 | } 22 | 23 | public static function rtrim(input:String):String { 24 | if (input != null) { 25 | var size:Number = input.length; 26 | for(var i:Number = size; i > 0; i--) { 27 | if(input.charCodeAt(i - 1) > 32) { 28 | return input.substring(0, i); 29 | } 30 | } 31 | } 32 | return ""; 33 | } 34 | 35 | private static var i:int = 0; 36 | 37 | private static const SIGN_UNDEF:int = 0; 38 | private static const SIGN_POS:int = -1; 39 | private static const SIGN_NEG:int = 1; 40 | 41 | public static function printf(format:String, ...args):String { 42 | var result:String = ""; 43 | var indexValue:int = 0; 44 | var isIndexed:int = -1; 45 | var typeLookup:String = "diufFeEgGxXoscpn"; 46 | for(i = 0; i < format.length; i++) { 47 | var c:String = format.charAt(i); 48 | if(c == "%") { 49 | if(++i < format.length) { 50 | c = format.charAt(i); 51 | if(c == "%") { 52 | result += c; 53 | } else { 54 | var flagSign:Boolean = false; 55 | var flagLeftAlign:Boolean = false; 56 | var flagAlternate:Boolean = false; 57 | var flagLeftPad:Boolean = false; 58 | var flagZeroPad:Boolean = false; 59 | var width:int = -1; 60 | var precision:int = -1; 61 | var type:String = ""; 62 | var value:*; 63 | var j:int; 64 | 65 | /////////////////////////// 66 | // parse parameter 67 | /////////////////////////// 68 | var idx:int = getIndex(format); 69 | if(idx < -1 || idx == 0) { 70 | trace("ERR parsing index"); 71 | break; 72 | } else if(idx == -1) { 73 | if(isIndexed == 1) { trace("ERR: indexed placeholder expected"); break; } 74 | if(isIndexed == -1) { isIndexed = 0; } 75 | indexValue++; 76 | } else { 77 | if(isIndexed == 0) { trace("ERR: non-indexed placeholder expected"); break; } 78 | if(isIndexed == -1) { isIndexed = 1; } 79 | indexValue = idx; 80 | } 81 | 82 | /////////////////////////// 83 | // parse flags 84 | /////////////////////////// 85 | while((c = format.charAt(i)) == "+" || c == "-" || c == "#" || c == " " || c == "0") { 86 | switch(c) { 87 | case "+": flagSign = true; break; 88 | case "-": flagLeftAlign = true; break; 89 | case "#": flagAlternate = true; break; 90 | case " ": flagLeftPad = true; break; 91 | case "0": flagZeroPad = true; break; 92 | } 93 | if(++i == format.length) { break; } 94 | c = format.charAt(i); 95 | } 96 | if(i == format.length) { break; } 97 | 98 | /////////////////////////// 99 | // parse width 100 | /////////////////////////// 101 | if(c == "*") { 102 | var widthIndex:int = 0; 103 | if(++i == format.length) { break; } 104 | idx = getIndex(format); 105 | if(idx < -1 || idx == 0) { 106 | trace("ERR parsing index for width"); 107 | break; 108 | } else if(idx == -1) { 109 | if(isIndexed == 1) { trace("ERR: indexed placeholder expected for width"); break; } 110 | if(isIndexed == -1) { isIndexed = 0; } 111 | widthIndex = indexValue++; 112 | } else { 113 | if(isIndexed == 0) { trace("ERR: non-indexed placeholder expected for width"); break; } 114 | if(isIndexed == -1) { isIndexed = 1; } 115 | widthIndex = idx; 116 | } 117 | widthIndex--; 118 | if(args.length > widthIndex && widthIndex >= 0) { 119 | width = parseInt(args[widthIndex]); 120 | if(isNaN(width)) { 121 | width = -1; 122 | trace("ERR NaN while parsing width"); 123 | break; 124 | } 125 | } else { 126 | trace("ERR index out of bounds while parsing width"); 127 | break; 128 | } 129 | c = format.charAt(i); 130 | } else { 131 | var hasWidth:Boolean = false; 132 | while(c >= "0" && c <= "9") { 133 | if(width == -1) { width = 0; } 134 | width = (width * 10) + uint(c); 135 | if(++i == format.length) { break; } 136 | c = format.charAt(i); 137 | } 138 | if(width != -1 && i == format.length) { 139 | trace("ERR eof while parsing width"); 140 | break; 141 | } 142 | } 143 | 144 | /////////////////////////// 145 | // parse precision 146 | /////////////////////////// 147 | if(c == ".") { 148 | if(++i == format.length) { break; } 149 | c = format.charAt(i); 150 | if(c == "*") { 151 | var precisionIndex:int = 0; 152 | if(++i == format.length) { break; } 153 | idx = getIndex(format); 154 | if(idx < -1 || idx == 0) { 155 | trace("ERR parsing index for precision"); 156 | break; 157 | } else if(idx == -1) { 158 | if(isIndexed == 1) { trace("ERR: indexed placeholder expected for precision"); break; } 159 | if(isIndexed == -1) { isIndexed = 0; } 160 | precisionIndex = indexValue++; 161 | } else { 162 | if(isIndexed == 0) { trace("ERR: non-indexed placeholder expected for precision"); break; } 163 | if(isIndexed == -1) { isIndexed = 1; } 164 | precisionIndex = idx; 165 | } 166 | precisionIndex--; 167 | if(args.length > precisionIndex && precisionIndex >= 0) { 168 | precision = parseInt(args[precisionIndex]); 169 | if(isNaN(precision)) { 170 | precision = -1; 171 | trace("ERR NaN while parsing precision"); 172 | break; 173 | } 174 | } else { 175 | trace("ERR index out of bounds while parsing precision"); 176 | break; 177 | } 178 | c = format.charAt(i); 179 | } else { 180 | while(c >= "0" && c <= "9") { 181 | if(precision == -1) { precision = 0; } 182 | precision = (precision * 10) + uint(c); 183 | if(++i == format.length) { break; } 184 | c = format.charAt(i); 185 | } 186 | if(precision != -1 && i == format.length) { 187 | trace("ERR eof while parsing precision"); 188 | break; 189 | } 190 | } 191 | } 192 | 193 | /////////////////////////// 194 | // parse length (ignored) 195 | /////////////////////////// 196 | switch(c) { 197 | case "h": 198 | case "l": 199 | if(++i == format.length) { trace("ERR eof after length"); break; } 200 | var c1:String = format.charAt(i); 201 | if((c == "h" && c1 == "h") || (c == "l" && c1 == "l")) { 202 | if(++i == format.length) { trace("ERR eof after length"); break; } 203 | c = format.charAt(i); 204 | } else { 205 | c = c1; 206 | } 207 | break; 208 | case "L": 209 | case "z": 210 | case "j": 211 | case "t": 212 | if(++i == format.length) { trace("ERR eof after length"); break; } 213 | c = format.charAt(i); 214 | break; 215 | } 216 | 217 | /////////////////////////// 218 | // parse type 219 | /////////////////////////// 220 | if(typeLookup.indexOf(c) >= 0) { 221 | type = c; 222 | } else { 223 | trace("ERR unknown type: " + c); 224 | break; 225 | } 226 | 227 | if(args.length >= indexValue && indexValue > 0) { 228 | value = args[indexValue - 1]; 229 | } else { 230 | trace("ERR value index out of bounds (" + indexValue + ")"); 231 | break; 232 | } 233 | 234 | var valueStr:String; 235 | var valueFloat:Number; 236 | var valueInt:int; 237 | var sign:int = SIGN_UNDEF; 238 | switch(type) { 239 | case "s": 240 | valueStr = value.toString(); 241 | if(precision != -1) { valueStr = valueStr.substr(0, precision); } 242 | break; 243 | case "c": 244 | valueStr = value.toString().getAt(0); 245 | break; 246 | case "d": 247 | case "i": 248 | valueInt = ((typeof value == "number") ? int(value) : parseInt(value)); 249 | valueStr = Math.abs(valueInt).toString(); 250 | sign = (valueInt < 0) ? SIGN_NEG : SIGN_POS; 251 | break; 252 | case "u": 253 | valueStr = ((typeof value == "number") ? uint(value) : uint(parseInt(value))).toString(); 254 | break; 255 | case "f": 256 | case "F": 257 | case "e": 258 | case "E": 259 | case "g": 260 | case "G": 261 | if(precision == -1) { precision = 6; } 262 | var exp10:Number = Math.pow(10, precision); 263 | valueFloat = (typeof value == "number") ? Number(value) : parseFloat(value); 264 | valueStr = (Math.round(Math.abs(valueFloat) * exp10) / exp10).toString(); 265 | if(precision > 0) { 266 | var numZerosToAppend:int; 267 | var dotPos:int = valueStr.indexOf("."); 268 | if(dotPos == -1) { 269 | valueStr += "."; 270 | numZerosToAppend = precision; 271 | } else { 272 | numZerosToAppend = precision - (valueStr.length - dotPos - 1); 273 | } 274 | for(j = 0; j < numZerosToAppend; j++) { 275 | valueStr += "0"; 276 | } 277 | } 278 | sign = (valueFloat < 0) ? SIGN_NEG : SIGN_POS; 279 | break; 280 | case "x": 281 | case "X": 282 | case "p": 283 | valueStr = ((typeof value == "number") ? uint(value) : parseInt(value)).toString(16); 284 | if(type == "X") { valueStr = valueStr.toUpperCase(); } 285 | break; 286 | case "o": 287 | valueStr = ((typeof value == "number") ? uint(value) : parseInt(value)).toString(8); 288 | break; 289 | } 290 | 291 | var hasSign:Boolean = ((sign == SIGN_NEG) || flagSign || flagLeftPad); 292 | if(width > -1) { 293 | var numFill:int = width - valueStr.length; 294 | if(hasSign) { numFill--; } 295 | if(numFill > 0) { 296 | var fillChar:String = (flagZeroPad && !flagLeftAlign) ? "0" : " "; 297 | if(flagLeftAlign) { 298 | for(j = 0; j < numFill; j++) { 299 | valueStr += fillChar; 300 | } 301 | } else { 302 | for(j = 0; j < numFill; j++) { 303 | valueStr = fillChar + valueStr; 304 | } 305 | } 306 | } 307 | } 308 | if(hasSign) { 309 | if(sign == SIGN_POS) { 310 | valueStr = (flagLeftPad ? " " : "0") + valueStr; 311 | } else { 312 | valueStr = "-" + valueStr; 313 | } 314 | } 315 | 316 | result += valueStr; 317 | 318 | /////////////////////////// 319 | // debug 320 | /////////////////////////// 321 | /* 322 | var d:String = ""; 323 | d += "type:" + type + " "; 324 | d += "width:" + width + " "; 325 | d += "precision:" + precision + " "; 326 | d += "flags:"; 327 | var da:Array = []; 328 | if(flagSign) { da.push("sign"); } 329 | if(flagLeftAlign) { da.push("leftalign"); } 330 | if(flagAlternate) { da.push("alternate"); } 331 | if(flagLeftPad) { da.push("leftpad"); } 332 | if(flagZeroPad) { da.push("zeropad"); } 333 | d += ((da.length == 0) ? "-" : da.toString()) + " "; 334 | d += "index:" + indexValue + " "; 335 | d += "value:" + value + " "; 336 | d += "result:" + valueStr; 337 | trace(d); 338 | */ 339 | 340 | } 341 | } else { 342 | result += c; 343 | } 344 | } else { 345 | result += c; 346 | } 347 | } 348 | return result; 349 | } 350 | 351 | private static function getIndex(format:String):int { 352 | var result:int = 0; 353 | var isIndexed:Boolean = false; 354 | var c:String = ""; 355 | var iTmp:int = i; 356 | while((c = format.charAt(i)) >= "0" && c <= "9") { 357 | isIndexed = true; 358 | result = (result * 10) + uint(c); 359 | if(++i == format.length) { return -2; } 360 | } 361 | if(isIndexed) { 362 | if(c != "$") { 363 | i = iTmp; 364 | return -1; 365 | } 366 | if(++i == format.length) { return -2; } 367 | return result; 368 | } else { 369 | return -1; 370 | } 371 | } 372 | } 373 | } 374 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/ICYSound.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy { import com.codeazur.as3icy.data.MPEGFrame; import com.codeazur.as3icy.decoder.Decoder; import com.codeazur.as3icy.decoder.OutputBuffer; import com.codeazur.as3icy.events.ICYFrameEvent; import com.codeazur.as3icy.events.ICYMetaDataEvent; import com.codeazur.utils.StringUtils; import flash.display.DisplayObject; import flash.display.Sprite; import flash.display.Loader; import flash.display.LoaderInfo; import flash.events.*; import flash.media.Sound; import flash.media.SoundLoaderContext; import flash.net.URLRequest; import flash.net.URLRequestHeader; import flash.net.URLStream; import flash.system.LoaderContext; import flash.utils.ByteArray; import flash.utils.Endian; import flash.utils.Timer; public class ICYSound extends Sound { protected static const FRAME_BUFFER_MAX:uint = 20; protected static const SAMPLE_DATA_SIZE:uint = 8192; protected static const SAMPLE_DATA_BYTES:uint = (SAMPLE_DATA_SIZE << 3); protected var stream:URLStream; protected var _mpegFrame:MPEGFrame; protected var headerIndex:uint = 0; protected var crcIndex:uint = 0; protected var _meta:String = ""; protected var _framesLoaded:uint = 0; protected var _metaDataLoaded:uint = 0; protected var _metaDataBytesLoaded:uint = 0; protected var responseUrl:String = ""; protected var _icyMetaSize:uint = 0; protected var _icyMetaInterval:uint = 0; protected var _icyName:String = ""; protected var _icyDescription:String = ""; protected var _icyUrl:String = ""; protected var _icyGenre:String = ""; protected var _icyBitrate:uint = 0; protected var _icyPublish:Boolean = false; protected var _icyServer:String = ""; protected var readFunc:Function = readIdle; protected var readFuncContinue:Function; protected var icyHeader:ByteArray; protected var icyCRReceived:Boolean = false; protected var icyCRLFCount:uint = 0; protected var read:uint = 0; protected var paused:Boolean = false; protected var frameDataTmp:ByteArray; protected var sampleBuffer:ByteArray; protected var buffering:Boolean = true; protected var decoder:Decoder; protected var dobj:Sprite; public function ICYSound(request:URLRequest = null, context:SoundLoaderContext = null) { super(null, context); dobj = new Sprite(); if (request != null) { load(request, context); } } override public function load(request:URLRequest, context:SoundLoaderContext = null):void { if (request == null) { return; } sampleBuffer = new ByteArray(); decoder = new Decoder(new OutputBuffer()); _mpegFrame = new MPEGFrame(); read = 0; frameDataTmp = null; icyHeader = null; icyCRReceived = false; icyCRLFCount = 0; _framesLoaded = 0; _metaDataLoaded = 0; _metaDataBytesLoaded = 0; responseUrl = request.url; try { stream.close(); } catch (e:Error) { } stream = new URLStream(); stream.addEventListener(ProgressEvent.PROGRESS, progressHandler); stream.addEventListener(Event.COMPLETE, completeHandler); stream.addEventListener(HTTPStatusEvent.HTTP_STATUS, defaultHandler); stream.addEventListener(IOErrorEvent.IO_ERROR, defaultHandler); stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, defaultHandler); stream.addEventListener(Event.OPEN, openHandler); CONFIG::AIR { stream.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpResponseStatusHandler); } addEventListener(SampleDataEvent.SAMPLE_DATA, sampleDataHandler, false, int.MAX_VALUE); stream.load(request); } protected function sampleDataHandler(e:SampleDataEvent):void { var i:uint = 0; var bytesToServe:uint = 0; if(buffering) { if(sampleBuffer.length > SAMPLE_DATA_BYTES * 4) { writeSampleData(e.data, SAMPLE_DATA_BYTES); buffering = false; } else { for(i = 0; i < SAMPLE_DATA_SIZE; i++) { e.data.writeFloat(0); e.data.writeFloat(0); } } } else { var len:uint = writeSampleData(e.data, SAMPLE_DATA_BYTES); if(len < SAMPLE_DATA_BYTES) { var size:uint = (len >> 3); for(i = 0; i < SAMPLE_DATA_SIZE - size; i++) { e.data.writeFloat(0); e.data.writeFloat(0); } buffering = true; } } } protected function writeSampleData(soundBuffer:ByteArray, len:uint):uint { if(len > 0 && sampleBuffer.length > 0) { len = Math.min(len, sampleBuffer.length); soundBuffer.writeBytes(sampleBuffer, 0, len); if(len == sampleBuffer.length) { sampleBuffer = new ByteArray(); } else { var ba:ByteArray = new ByteArray(); ba.writeBytes(sampleBuffer, len, sampleBuffer.length - len); sampleBuffer = ba; } } else { len = 0; } return len; } override public function close():void { stream.close(); } public function resume():void { if (paused && stream.connected) { paused = false; _mpegFrame = new MPEGFrame(); readFunc = readFrameHeader; readLoop(); } } public function get connected():Boolean { return (stream != null) ? stream.connected : false; } public function get mpegFrame():MPEGFrame { return _mpegFrame; } public function get framesLoaded():uint { return _framesLoaded; } public function get metaDataLoaded():uint { return _metaDataLoaded; } public function get metaDataBytesLoaded():uint { return _metaDataBytesLoaded; } public function get icyMetaSize():uint { return _icyMetaSize; } public function get icyMetaInterval():uint { return _icyMetaInterval; } public function get icyName():String { return _icyName; } public function get icyDescription():String { return _icyDescription; } public function get icyUrl():String { return _icyUrl; } public function get icyGenre():String { return _icyGenre; } public function get icyBitrate():uint { return _icyBitrate; } public function get icyPublish():Boolean { return _icyPublish; } public function get icyServer():String { return _icyServer; } protected function set meta(value:String):void { _meta = value; } protected function get meta():String { return _meta; } CONFIG::AIR { protected function httpResponseStatusHandler(e:HTTPStatusEvent):void { if (e.responseHeaders.length > 0) { processResponseHeaders(e.responseHeaders); dispatchEvent(e.clone()); readFunc = readFrameHeader; } else { // no response headers probably mean that we're dealing with // fucked up non-http ICY responses (ICY 200 OK), so we have to // manually parse the headers. Well, ok then. responseUrl = e.responseURL; icyHeader = new ByteArray(); readFunc = readNonHttpIcyHeaderOmgWtfLol; } } } protected function openHandler(e:Event):void { dispatchEvent(e.clone()); readFunc = readFrameHeader; } protected function completeHandler(e:Event):void { dispatchEvent(e.clone()); } protected function progressHandler(e:ProgressEvent):void { dispatchEvent(e.clone()); if (!paused && readLoop()) { close(); } } protected function readLoop():Boolean { while (readFunc()); return (readFunc === readIdle); } protected function readIdle():Boolean { return false; } CONFIG::AIR { protected function readNonHttpIcyHeaderOmgWtfLol():Boolean { while (stream.bytesAvailable) { var b:uint = stream.readUnsignedByte(); if (b == 0x0d) { icyCRReceived = true; } else if (b == 0x0a) { icyHeader.writeByte(b); icyCRLFCount++; } else { icyHeader.writeByte(b); icyCRReceived = false; icyCRLFCount = 0; } if (icyCRLFCount == 2) { icyHeader.position = 0; var responseHeaders:Array = []; var header:String = icyHeader.readUTFBytes(icyHeader.length); var items:Array = header.split(String.fromCharCode(0x0a)); for (var i:uint = 0; i < items.length; i++) { var item:String = items[i]; var j:int = item.indexOf(":"); if (j > 0) { var name:String = StringUtils.trim(item.substring(0, j)); var value:String = StringUtils.trim(item.substring(j + 1)); responseHeaders.push(new URLRequestHeader(name, value)); } } processResponseHeaders(responseHeaders); var e:HTTPStatusEvent = new HTTPStatusEvent(HTTPStatusEvent.HTTP_RESPONSE_STATUS, false, false, 200); e.responseHeaders = responseHeaders; e.responseURL = responseUrl; dispatchEvent(e); readFunc = readFrameHeader; break; } } return true; } } protected function readFrameHeader():Boolean { var ret:Boolean = true; if (stream.bytesAvailable >= 1) { if (icyMetaInterval > 0 && ++read > icyMetaInterval) { readFuncContinue = readFrameHeader; readFunc = readMetaDataSize; return ret; } try { mpegFrame.setHeaderByteAt(headerIndex, stream.readUnsignedByte()); if (++headerIndex == 4) { readFunc = mpegFrame.hasCRC ? readCRC : readFrame; headerIndex = 0; } } catch (e:Error) { //trace(e.message); headerIndex = 0; } } else { ret = false; } return ret; } protected function readCRC():Boolean { var ret:Boolean = true; if (stream.bytesAvailable >= 1) { if (icyMetaInterval > 0 && ++read > icyMetaInterval) { readFuncContinue = readCRC; readFunc = readMetaDataSize; return ret; } try { mpegFrame.setCRCByteAt(crcIndex, stream.readUnsignedByte()); if (++crcIndex == 2) { readFunc = readFrame; crcIndex = 0; } } catch (e:Error) { //trace(e.message); readFunc = readFrameHeader; crcIndex = 0; } } else { ret = false; } return ret; } protected function readFrame():Boolean { var ret:Boolean = true; var readTmp:uint = read; var len:uint = mpegFrame.size; if (icyMetaInterval > 0) { if (frameDataTmp != null) { len -= frameDataTmp.length; } read += len; if (read >= icyMetaInterval) { len -= (read - icyMetaInterval); if (len == 0) { read = readTmp; frameDataTmp = frameData; readFuncContinue = readFrame; readFunc = readMetaDataSize; return ret; } } } if (stream.bytesAvailable >= len) { var frameData:ByteArray = new ByteArray(); if (icyMetaInterval > 0 && frameDataTmp != null) { stream.readBytes(frameDataTmp, frameDataTmp.length, len); frameData = frameDataTmp; } else { stream.readBytes(frameData, 0, len); } if (icyMetaInterval > 0 && read >= icyMetaInterval) { frameDataTmp = frameData; readFuncContinue = readFrame; readFunc = readMetaDataSize; } else { _framesLoaded++; frameDataTmp = null; mpegFrame.data.writeBytes(frameData); mpegFrame.data.position = 0; // decode the mpeg frame we just read decoder.decodeFrame(mpegFrame); var ob:Vector. = decoder.outputBuffer.getBuffer(); for (var i:uint = 0; i < ob.length; i++) { sampleBuffer.writeFloat(ob[i]); } decoder.outputBuffer.clear_buffer(); dispatchEvent(new ICYFrameEvent(ICYFrameEvent.FRAME, mpegFrame, false, true)); if (sampleBuffer.length > SAMPLE_DATA_BYTES * 2) { dobj.addEventListener(Event.ENTER_FRAME, enterFrameHandler); paused = true; ret = false; } else { _mpegFrame = new MPEGFrame(); readFunc = readFrameHeader; ret = true; } } } else { read = readTmp; ret = false; } return ret; } protected function readMetaDataSize():Boolean { var ret:Boolean = true; if (stream.bytesAvailable >= 1) { read = 0; _icyMetaSize = (stream.readUnsignedByte() << 4); _metaDataBytesLoaded += _icyMetaSize + 1; _metaDataLoaded++; if (_icyMetaSize > 0) { readFunc = readMetaData; } else { dispatchEvent(new ICYMetaDataEvent(ICYMetaDataEvent.METADATA)); readFunc = readFuncContinue; } } else { ret = false; } return ret; } protected function readMetaData():Boolean { var ret:Boolean = true; if (stream.bytesAvailable >= _icyMetaSize) { /* if (_icyMetaSize > 250) { trace(mpegFrame); throw(new Error("BOOM")); } */ read = 0; meta = stream.readUTFBytes(_icyMetaSize); dispatchEvent(new ICYMetaDataEvent(ICYMetaDataEvent.METADATA, meta)); readFunc = readFuncContinue; } else { ret = false; } return ret; } protected function enterFrameHandler(e:Event):void { dobj.removeEventListener(Event.ENTER_FRAME, enterFrameHandler); resume(); } CONFIG::AIR { protected function processResponseHeaders(headers:Array):void { for (var i:uint = 0; i < headers.length; i++) { var header:URLRequestHeader = headers[i] as URLRequestHeader; if (header) { switch(header.name.toLowerCase()) { case "icy-metaint": _icyMetaInterval = parseInt(header.value); break; case "icy-name": _icyName = header.value; break; case "icy-description": _icyDescription = header.value; break; case "icy-url": _icyUrl = header.value; break; case "icy-genre": _icyGenre = header.value; break; case "icy-br": _icyBitrate = parseInt(header.value); break; case "icy-pub": _icyPublish = (header.value == "1"); break; case "server": _icyServer = header.value; break; } } } } } protected function defaultHandler(e:Event):void { dispatchEvent(e.clone()); } public function hexDump(ba:ByteArray, start:uint, length:uint):String { var deb:String = ""; var debHex:String = ""; var debAscii:String = ""; for (var i:int = 0; i < length; i++) { if (i % 16 == 0) { deb += debHex + debAscii + "\n"; debHex = debAscii = ""; } var byte:uint = ba[start + i]; debHex += StringUtils.printf("%02X ", byte); debAscii += (byte >= 0x20 && byte < 128) ? String.fromCharCode(byte) : "."; } if (debHex != "") { var fill:uint = Math.floor(length % 16); if (fill > 0) { for (var j:int = 0; j < 16 - fill; j++) { debHex += " "; } } deb += debHex + debAscii; } return deb; } } } -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/HuffCodeTab.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | public class HuffCodeTab 4 | { 5 | protected static const MXOFF:uint = 250; 6 | protected static const HTN:uint = 34; 7 | 8 | protected var tablename0:String = ' '; // string, containing table_description 9 | protected var tablename1:String = ' '; // string, containing table_description 10 | protected var tablename2:String = ' '; // string, containing table_description 11 | 12 | protected var xlen:int; // max x-index+ 13 | protected var ylen:int; // max y-index+ 14 | protected var linbits:int; // number of linbits 15 | protected var linmax:int; // max number to be stored in linbits 16 | protected var ref:int; // a positive value indicates a reference 17 | protected var table:Array; // pointer to array[xlen][ylen] 18 | protected var hlen:Array; // pointer to array[xlen][ylen] 19 | protected var val:Array; // decoder tree 20 | protected var treelen:int; // length of decoder tree 21 | 22 | public function HuffCodeTab(s:String, xlen:int, ylen:int, linbits:int, linmax:int, ref:int, table:Array, hlen:Array, val:Array, treelen:int) 23 | { 24 | this.tablename0 = s.charAt(0); 25 | this.tablename1 = s.charAt(1); 26 | this.tablename2 = s.charAt(2); 27 | this.xlen = xlen; 28 | this.ylen = ylen; 29 | this.linbits = linbits; 30 | this.linmax = linmax; 31 | this.ref = ref; 32 | this.table = table; 33 | this.hlen = hlen; 34 | this.val = val; 35 | this.treelen = treelen; 36 | } 37 | 38 | /** 39 | * Do the huffman-decoding. 40 | * note! for counta,countb -the 4 bit value is returned in y, 41 | * discard x. 42 | */ 43 | public static function huffman_decoder(h:HuffCodeTab, res:HuffResult, br:BitReserve):int 44 | { 45 | // array of all huffcodtable headers 46 | // 0..31 Huffman code table 0..31 47 | // 32,33 count1-tables 48 | 49 | var dmask:int = 1 << ((4 * 8) - 1); 50 | var hs:int = 4 * 8; 51 | var level:int = dmask; 52 | var point:int = 0; 53 | var error:int = 1; 54 | 55 | if (h.val == null) { 56 | return 2; 57 | } 58 | 59 | // Table 0 needs no bits 60 | if (h.treelen == 0) { 61 | res.x = res.y = 0; 62 | return 0; 63 | } 64 | 65 | // Lookup in Huffman table. 66 | do 67 | { 68 | if (h.val[point][0] == 0) { 69 | // End of tree 70 | res.x = h.val[point][1] >>> 4; 71 | res.y = h.val[point][1] & 0xf; 72 | error = 0; 73 | break; 74 | } 75 | if (br.hget1bit() != 0) { 76 | while (h.val[point][1] >= MXOFF) { 77 | point += h.val[point][1]; 78 | } 79 | point += h.val[point][1]; 80 | } else { 81 | while (h.val[point][0] >= MXOFF) { 82 | point += h.val[point][0]; 83 | } 84 | point += h.val[point][0]; 85 | } 86 | level >>>= 1; 87 | } 88 | while ((level != 0) || (point < 0)); 89 | 90 | // Process sign encodings for quadruples tables. 91 | if (h.tablename0 == '3' && (h.tablename1 == '2' || h.tablename1 == '3')) { 92 | res.v = (res.y >> 3) & 1; 93 | res.w = (res.y >> 2) & 1; 94 | res.x = (res.y >> 1) & 1; 95 | res.y = res.y & 1; 96 | // v, w, x and y are reversed in the bitstream. 97 | // switch them around to make test bistream work. 98 | if (res.v != 0) { 99 | if (br.hget1bit() != 0) { 100 | res.v = -res.v; 101 | } 102 | } 103 | if (res.w != 0) { 104 | if (br.hget1bit() != 0) { 105 | res.w = -res.w; 106 | } 107 | } 108 | if (res.x != 0) { 109 | if (br.hget1bit() != 0) { 110 | res.x = -res.x; 111 | } 112 | } 113 | if (res.y != 0) { 114 | if (br.hget1bit() != 0) { 115 | res.y = -res.y; 116 | } 117 | } 118 | } else { 119 | // Process sign and escape encodings for dual tables. 120 | // x and y are reversed in the test bitstream. 121 | // Reverse x and y here to make test bitstream work. 122 | if (h.linbits != 0) { 123 | if (h.xlen - 1 == res.x) { 124 | res.x += br.hgetbits(h.linbits); 125 | } 126 | } 127 | if (res.x != 0) { 128 | if (br.hget1bit() != 0) { 129 | res.x = -res.x; 130 | } 131 | } 132 | if (h.linbits != 0) { 133 | if (h.ylen - 1 == res.y) { 134 | res.y += br.hgetbits(h.linbits); 135 | } 136 | } 137 | if (res.y != 0) { 138 | if (br.hget1bit() != 0) { 139 | res.y = -res.y; 140 | } 141 | } 142 | } 143 | return error; 144 | } 145 | 146 | protected static var ValTab0:Array = [ 147 | [0,0] 148 | ]; 149 | 150 | protected static var ValTab1:Array = [ 151 | [2,1], [0,0], [2,1], [0,16], [2,1], [0,1], [0,17] 152 | ]; 153 | 154 | protected static var ValTab2:Array = [ 155 | [2,1], [0,0], [4,1], [2,1], [0,16], [0,1], [2,1], [0,17], [4,1], [2,1], 156 | [0,32], [0,33], [2,1], [0,18], [2,1], [0,2], [0,34] 157 | ]; 158 | 159 | protected static var ValTab3:Array = [ 160 | [4,1], [2,1], [0,0], [0,1], [2,1], [0,17], [2,1], [0,16], [4,1], [2,1], 161 | [0,32], [0,33], [2,1], [0,18], [2,1], [0,2], [0,34] 162 | ]; 163 | 164 | protected static var ValTab4:Array = [ 165 | [0,0] 166 | ]; 167 | 168 | protected static var ValTab5:Array = [ 169 | [2,1], [0,0], [4,1], [2,1], [0,16], [0,1], [2,1], [0,17], [8,1], [4,1], 170 | [2,1], [0,32], [0,2], [2,1], [0,33], [0,18], [8,1], [4,1], [2,1], [0,34], 171 | [0,48], [2,1], [0,3], [0,19], [2,1], [0,49], [2,1], [0,50], [2,1], [0,35], 172 | [0,51] 173 | ]; 174 | 175 | protected static var ValTab6:Array = [ 176 | [6,1], [4,1], [2,1], [0,0], [0,16], [0,17], [6,1], [2,1], [0,1], [2,1], 177 | [0,32], [0,33], [6,1], [2,1], [0,18], [2,1], [0,2], [0,34], [4,1], [2,1], 178 | [0,49], [0,19], [4,1], [2,1], [0,48], [0,50], [2,1], [0,35], [2,1], [0,3], 179 | [0,51] 180 | ]; 181 | 182 | protected static var ValTab7:Array = [ 183 | [2,1], [0,0], [4,1], [2,1], [0,16], [0,1], [8,1], [2,1], [0,17], [4,1], 184 | [2,1], [0,32], [0,2], [0,33], [18,1], [6,1], [2,1], [0,18], [2,1], [0,34], 185 | [0,48], [4,1], [2,1], [0,49], [0,19], [4,1], [2,1], [0,3], [0,50], [2,1], 186 | [0,35], [0,4], [10,1], [4,1], [2,1], [0,64], [0,65], [2,1], [0,20], [2,1], 187 | [0,66], [0,36], [12,1], [6,1], [4,1], [2,1], [0,51], [0,67], [0,80], [4,1], 188 | [2,1], [0,52], [0,5], [0,81], [6,1], [2,1], [0,21], [2,1], [0,82], [0,37], 189 | [4,1], [2,1], [0,68], [0,53], [4,1], [2,1], [0,83], [0,84], [2,1], [0,69], 190 | [0,85] 191 | ]; 192 | 193 | protected static var ValTab8:Array = [ 194 | [6,1], [2,1], [0,0], [2,1], [0,16], [0,1], [2,1], [0,17], [4,1], [2,1], 195 | [0,33], [0,18], [14,1], [4,1], [2,1], [0,32], [0,2], [2,1], [0,34], [4,1], 196 | [2,1], [0,48], [0,3], [2,1], [0,49], [0,19], [14,1], [8,1], [4,1], [2,1], 197 | [0,50], [0,35], [2,1], [0,64], [0,4], [2,1], [0,65], [2,1], [0,20], [0,66], 198 | [12,1], [6,1], [2,1], [0,36], [2,1], [0,51], [0,80], [4,1], [2,1], [0,67], 199 | [0,52], [0,81], [6,1], [2,1], [0,21], [2,1], [0,5], [0,82], [6,1], [2,1], 200 | [0,37], [2,1], [0,68], [0,53], [2,1], [0,83], [2,1], [0,69], [2,1], [0,84], 201 | [0,85] 202 | ]; 203 | 204 | protected static var ValTab9:Array = [ 205 | [8,1], [4,1], [2,1], [0,0], [0,16], [2,1], [0,1], [0,17], [10,1], [4,1], 206 | [2,1], [0,32], [0,33], [2,1], [0,18], [2,1], [0,2], [0,34], [12,1], [6,1], 207 | [4,1], [2,1], [0,48], [0,3], [0,49], [2,1], [0,19], [2,1], [0,50], [0,35], 208 | [12,1], [4,1], [2,1], [0,65], [0,20], [4,1], [2,1], [0,64], [0,51], [2,1], 209 | [0,66], [0,36], [10,1], [6,1], [4,1], [2,1], [0,4], [0,80], [0,67], [2,1], 210 | [0,52], [0,81], [8,1], [4,1], [2,1], [0,21], [0,82], [2,1], [0,37], [0,68], 211 | [6,1], [4,1], [2,1], [0,5], [0,84], [0,83], [2,1], [0,53], [2,1], [0,69], 212 | [0,85] 213 | ]; 214 | 215 | protected static var ValTab10:Array = [ 216 | [2,1], [0,0], [4,1], [2,1], [0,16], [0,1], [10,1], [2,1], [0,17], [4,1], 217 | [2,1], [0,32], [0,2], [2,1], [0,33], [0,18], [28,1], [8,1], [4,1], [2,1], 218 | [0,34], [0,48], [2,1], [0,49], [0,19], [8,1], [4,1], [2,1], [0,3], [0,50], 219 | [2,1], [0,35], [0,64], [4,1], [2,1], [0,65], [0,20], [4,1], [2,1], [0,4], 220 | [0,51], [2,1], [0,66], [0,36], [28,1], [10,1], [6,1], [4,1], [2,1], [0,80], 221 | [0,5], [0,96], [2,1], [0,97], [0,22], [12,1], [6,1], [4,1], [2,1], [0,67], 222 | [0,52], [0,81], [2,1], [0,21], [2,1], [0,82], [0,37], [4,1], [2,1], [0,38], 223 | [0,54], [0,113], [20,1], [8,1], [2,1], [0,23], [4,1], [2,1], [0,68], [0,83], 224 | [0,6], [6,1], [4,1], [2,1], [0,53], [0,69], [0,98], [2,1], [0,112], [2,1], 225 | [0,7], [0,100], [14,1], [4,1], [2,1], [0,114], [0,39], [6,1], [2,1], [0,99], 226 | [2,1], [0,84], [0,85], [2,1], [0,70], [0,115], [8,1], [4,1], [2,1], [0,55], 227 | [0,101], [2,1], [0,86], [0,116], [6,1], [2,1], [0,71], [2,1], [0,102], [0,117], 228 | [4,1], [2,1], [0,87], [0,118], [2,1], [0,103], [0,119] 229 | ]; 230 | 231 | protected static var ValTab11:Array = [ 232 | [6,1], [2,1], [0,0], [2,1], [0,16], [0,1], [8,1], [2,1], [0,17], [4,1], 233 | [2,1], [0,32], [0,2], [0,18], [24,1], [8,1], [2,1], [0,33], [2,1], [0,34], 234 | [2,1], [0,48], [0,3], [4,1], [2,1], [0,49], [0,19], [4,1], [2,1], [0,50], 235 | [0,35], [4,1], [2,1], [0,64], [0,4], [2,1], [0,65], [0,20], [30,1], [16,1], 236 | [10,1], [4,1], [2,1], [0,66], [0,36], [4,1], [2,1], [0,51], [0,67], [0,80], 237 | [4,1], [2,1], [0,52], [0,81], [0,97], [6,1], [2,1], [0,22], [2,1], [0,6], 238 | [0,38], [2,1], [0,98], [2,1], [0,21], [2,1], [0,5], [0,82], [16,1], [10,1], 239 | [6,1], [4,1], [2,1], [0,37], [0,68], [0,96], [2,1], [0,99], [0,54], [4,1], 240 | [2,1], [0,112], [0,23], [0,113], [16,1], [6,1], [4,1], [2,1], [0,7], [0,100], 241 | [0,114], [2,1], [0,39], [4,1], [2,1], [0,83], [0,53], [2,1], [0,84], [0,69], 242 | [10,1], [4,1], [2,1], [0,70], [0,115], [2,1], [0,55], [2,1], [0,101], [0,86], 243 | [10,1], [6,1], [4,1], [2,1], [0,85], [0,87], [0,116], [2,1], [0,71], [0,102], 244 | [4,1], [2,1], [0,117], [0,118], [2,1], [0,103], [0,119] 245 | ]; 246 | 247 | protected static var ValTab12:Array = [ 248 | [12,1], [4,1], [2,1], [0,16], [0,1], [2,1], [0,17], [2,1], [0,0], [2,1], 249 | [0,32], [0,2], [16,1], [4,1], [2,1], [0,33], [0,18], [4,1], [2,1], [0,34], 250 | [0,49], [2,1], [0,19], [2,1], [0,48], [2,1], [0,3], [0,64], [26,1], [8,1], 251 | [4,1], [2,1], [0,50], [0,35], [2,1], [0,65], [0,51], [10,1], [4,1], [2,1], 252 | [0,20], [0,66], [2,1], [0,36], [2,1], [0,4], [0,80], [4,1], [2,1], [0,67], 253 | [0,52], [2,1], [0,81], [0,21], [28,1], [14,1], [8,1], [4,1], [2,1], [0,82], 254 | [0,37], [2,1], [0,83], [0,53], [4,1], [2,1], [0,96], [0,22], [0,97], [4,1], 255 | [2,1], [0,98], [0,38], [6,1], [4,1], [2,1], [0,5], [0,6], [0,68], [2,1], 256 | [0,84], [0,69], [18,1], [10,1], [4,1], [2,1], [0,99], [0,54], [4,1], [2,1], 257 | [0,112], [0,7], [0,113], [4,1], [2,1], [0,23], [0,100], [2,1], [0,70], [0,114], 258 | [10,1], [6,1], [2,1], [0,39], [2,1], [0,85], [0,115], [2,1], [0,55], [0,86], 259 | [8,1], [4,1], [2,1], [0,101], [0,116], [2,1], [0,71], [0,102], [4,1], [2,1], 260 | [0,117], [0,87], [2,1], [0,118], [2,1], [0,103], [0,119] 261 | ]; 262 | 263 | protected static var ValTab13:Array = [ 264 | [2,1], [0,0], [6,1], [2,1], [0,16], [2,1], [0,1], [0,17], [28,1], [8,1], 265 | [4,1], [2,1], [0,32], [0,2], [2,1], [0,33], [0,18], [8,1], [4,1], [2,1], 266 | [0,34], [0,48], [2,1], [0,3], [0,49], [6,1], [2,1], [0,19], [2,1], [0,50], 267 | [0,35], [4,1], [2,1], [0,64], [0,4], [0,65], [70,1], [28,1], [14,1], [6,1], 268 | [2,1], [0,20], [2,1], [0,51], [0,66], [4,1], [2,1], [0,36], [0,80], [2,1], 269 | [0,67], [0,52], [4,1], [2,1], [0,81], [0,21], [4,1], [2,1], [0,5], [0,82], 270 | [2,1], [0,37], [2,1], [0,68], [0,83], [14,1], [8,1], [4,1], [2,1], [0,96], 271 | [0,6], [2,1], [0,97], [0,22], [4,1], [2,1], [0,128], [0,8], [0,129], [16,1], 272 | [8,1], [4,1], [2,1], [0,53], [0,98], [2,1], [0,38], [0,84], [4,1], [2,1], 273 | [0,69], [0,99], [2,1], [0,54], [0,112], [6,1], [4,1], [2,1], [0,7], [0,85], 274 | [0,113], [2,1], [0,23], [2,1], [0,39], [0,55], [72,1], [24,1], [12,1], [4,1], 275 | [2,1], [0,24], [0,130], [2,1], [0,40], [4,1], [2,1], [0,100], [0,70], [0,114], 276 | [8,1], [4,1], [2,1], [0,132], [0,72], [2,1], [0,144], [0,9], [2,1], [0,145], 277 | [0,25], [24,1], [14,1], [8,1], [4,1], [2,1], [0,115], [0,101], [2,1], [0,86], 278 | [0,116], [4,1], [2,1], [0,71], [0,102], [0,131], [6,1], [2,1], [0,56], [2,1], 279 | [0,117], [0,87], [2,1], [0,146], [0,41], [14,1], [8,1], [4,1], [2,1], [0,103], 280 | [0,133], [2,1], [0,88], [0,57], [2,1], [0,147], [2,1], [0,73], [0,134], [6,1], 281 | [2,1], [0,160], [2,1], [0,104], [0,10], [2,1], [0,161], [0,26], [68,1], [24,1], 282 | [12,1], [4,1], [2,1], [0,162], [0,42], [4,1], [2,1], [0,149], [0,89], [2,1], 283 | [0,163], [0,58], [8,1], [4,1], [2,1], [0,74], [0,150], [2,1], [0,176], [0,11], 284 | [2,1], [0,177], [0,27], [20,1], [8,1], [2,1], [0,178], [4,1], [2,1], [0,118], 285 | [0,119], [0,148], [6,1], [4,1], [2,1], [0,135], [0,120], [0,164], [4,1], [2,1], 286 | [0,105], [0,165], [0,43], [12,1], [6,1], [4,1], [2,1], [0,90], [0,136], [0,179], 287 | [2,1], [0,59], [2,1], [0,121], [0,166], [6,1], [4,1], [2,1], [0,106], [0,180], 288 | [0,192], [4,1], [2,1], [0,12], [0,152], [0,193], [60,1], [22,1], [10,1], [6,1], 289 | [2,1], [0,28], [2,1], [0,137], [0,181], [2,1], [0,91], [0,194], [4,1], [2,1], 290 | [0,44], [0,60], [4,1], [2,1], [0,182], [0,107], [2,1], [0,196], [0,76], [16,1], 291 | [8,1], [4,1], [2,1], [0,168], [0,138], [2,1], [0,208], [0,13], [2,1], [0,209], 292 | [2,1], [0,75], [2,1], [0,151], [0,167], [12,1], [6,1], [2,1], [0,195], [2,1], 293 | [0,122], [0,153], [4,1], [2,1], [0,197], [0,92], [0,183], [4,1], [2,1], [0,29], 294 | [0,210], [2,1], [0,45], [2,1], [0,123], [0,211], [52,1], [28,1], [12,1], [4,1], 295 | [2,1], [0,61], [0,198], [4,1], [2,1], [0,108], [0,169], [2,1], [0,154], [0,212], 296 | [8,1], [4,1], [2,1], [0,184], [0,139], [2,1], [0,77], [0,199], [4,1], [2,1], 297 | [0,124], [0,213], [2,1], [0,93], [0,224], [10,1], [4,1], [2,1], [0,225], [0,30], 298 | [4,1], [2,1], [0,14], [0,46], [0,226], [8,1], [4,1], [2,1], [0,227], [0,109], 299 | [2,1], [0,140], [0,228], [4,1], [2,1], [0,229], [0,186], [0,240], [38,1], [16,1], 300 | [4,1], [2,1], [0,241], [0,31], [6,1], [4,1], [2,1], [0,170], [0,155], [0,185], 301 | [2,1], [0,62], [2,1], [0,214], [0,200], [12,1], [6,1], [2,1], [0,78], [2,1], 302 | [0,215], [0,125], [2,1], [0,171], [2,1], [0,94], [0,201], [6,1], [2,1], [0,15], 303 | [2,1], [0,156], [0,110], [2,1], [0,242], [0,47], [32,1], [16,1], [6,1], [4,1], 304 | [2,1], [0,216], [0,141], [0,63], [6,1], [2,1], [0,243], [2,1], [0,230], [0,202], 305 | [2,1], [0,244], [0,79], [8,1], [4,1], [2,1], [0,187], [0,172], [2,1], [0,231], 306 | [0,245], [4,1], [2,1], [0,217], [0,157], [2,1], [0,95], [0,232], [30,1], [12,1], 307 | [6,1], [2,1], [0,111], [2,1], [0,246], [0,203], [4,1], [2,1], [0,188], [0,173], 308 | [0,218], [8,1], [2,1], [0,247], [4,1], [2,1], [0,126], [0,127], [0,142], [6,1], 309 | [4,1], [2,1], [0,158], [0,174], [0,204], [2,1], [0,248], [0,143], [18,1], [8,1], 310 | [4,1], [2,1], [0,219], [0,189], [2,1], [0,234], [0,249], [4,1], [2,1], [0,159], 311 | [0,235], [2,1], [0,190], [2,1], [0,205], [0,250], [14,1], [4,1], [2,1], [0,221], 312 | [0,236], [6,1], [4,1], [2,1], [0,233], [0,175], [0,220], [2,1], [0,206], [0,251], 313 | [8,1], [4,1], [2,1], [0,191], [0,222], [2,1], [0,207], [0,238], [4,1], [2,1], 314 | [0,223], [0,239], [2,1], [0,255], [2,1], [0,237], [2,1], [0,253], [2,1], [0,252], 315 | [0,254] 316 | ]; 317 | 318 | protected static var ValTab14:Array = [ 319 | [0,0] 320 | ]; 321 | 322 | protected static var ValTab15:Array = [ 323 | [16,1], [6,1], [2,1], [0,0], [2,1], [0,16], [0,1], [2,1], [0,17], [4,1], 324 | [2,1], [0,32], [0,2], [2,1], [0,33], [0,18], [50,1], [16,1], [6,1], [2,1], 325 | [0,34], [2,1], [0,48], [0,49], [6,1], [2,1], [0,19], [2,1], [0,3], [0,64], 326 | [2,1], [0,50], [0,35], [14,1], [6,1], [4,1], [2,1], [0,4], [0,20], [0,65], 327 | [4,1], [2,1], [0,51], [0,66], [2,1], [0,36], [0,67], [10,1], [6,1], [2,1], 328 | [0,52], [2,1], [0,80], [0,5], [2,1], [0,81], [0,21], [4,1], [2,1], [0,82], 329 | [0,37], [4,1], [2,1], [0,68], [0,83], [0,97], [90,1], [36,1], [18,1], [10,1], 330 | [6,1], [2,1], [0,53], [2,1], [0,96], [0,6], [2,1], [0,22], [0,98], [4,1], 331 | [2,1], [0,38], [0,84], [2,1], [0,69], [0,99], [10,1], [6,1], [2,1], [0,54], 332 | [2,1], [0,112], [0,7], [2,1], [0,113], [0,85], [4,1], [2,1], [0,23], [0,100], 333 | [2,1], [0,114], [0,39], [24,1], [16,1], [8,1], [4,1], [2,1], [0,70], [0,115], 334 | [2,1], [0,55], [0,101], [4,1], [2,1], [0,86], [0,128], [2,1], [0,8], [0,116], 335 | [4,1], [2,1], [0,129], [0,24], [2,1], [0,130], [0,40], [16,1], [8,1], [4,1], 336 | [2,1], [0,71], [0,102], [2,1], [0,131], [0,56], [4,1], [2,1], [0,117], [0,87], 337 | [2,1], [0,132], [0,72], [6,1], [4,1], [2,1], [0,144], [0,25], [0,145], [4,1], 338 | [2,1], [0,146], [0,118], [2,1], [0,103], [0,41], [92,1], [36,1], [18,1], [10,1], 339 | [4,1], [2,1], [0,133], [0,88], [4,1], [2,1], [0,9], [0,119], [0,147], [4,1], 340 | [2,1], [0,57], [0,148], [2,1], [0,73], [0,134], [10,1], [6,1], [2,1], [0,104], 341 | [2,1], [0,160], [0,10], [2,1], [0,161], [0,26], [4,1], [2,1], [0,162], [0,42], 342 | [2,1], [0,149], [0,89], [26,1], [14,1], [6,1], [2,1], [0,163], [2,1], [0,58], 343 | [0,135], [4,1], [2,1], [0,120], [0,164], [2,1], [0,74], [0,150], [6,1], [4,1], 344 | [2,1], [0,105], [0,176], [0,177], [4,1], [2,1], [0,27], [0,165], [0,178], [14,1], 345 | [8,1], [4,1], [2,1], [0,90], [0,43], [2,1], [0,136], [0,151], [2,1], [0,179], 346 | [2,1], [0,121], [0,59], [8,1], [4,1], [2,1], [0,106], [0,180], [2,1], [0,75], 347 | [0,193], [4,1], [2,1], [0,152], [0,137], [2,1], [0,28], [0,181], [80,1], [34,1], 348 | [16,1], [6,1], [4,1], [2,1], [0,91], [0,44], [0,194], [6,1], [4,1], [2,1], 349 | [0,11], [0,192], [0,166], [2,1], [0,167], [0,122], [10,1], [4,1], [2,1], [0,195], 350 | [0,60], [4,1], [2,1], [0,12], [0,153], [0,182], [4,1], [2,1], [0,107], [0,196], 351 | [2,1], [0,76], [0,168], [20,1], [10,1], [4,1], [2,1], [0,138], [0,197], [4,1], 352 | [2,1], [0,208], [0,92], [0,209], [4,1], [2,1], [0,183], [0,123], [2,1], [0,29], 353 | [2,1], [0,13], [0,45], [12,1], [4,1], [2,1], [0,210], [0,211], [4,1], [2,1], 354 | [0,61], [0,198], [2,1], [0,108], [0,169], [6,1], [4,1], [2,1], [0,154], [0,184], 355 | [0,212], [4,1], [2,1], [0,139], [0,77], [2,1], [0,199], [0,124], [68,1], [34,1], 356 | [18,1], [10,1], [4,1], [2,1], [0,213], [0,93], [4,1], [2,1], [0,224], [0,14], 357 | [0,225], [4,1], [2,1], [0,30], [0,226], [2,1], [0,170], [0,46], [8,1], [4,1], 358 | [2,1], [0,185], [0,155], [2,1], [0,227], [0,214], [4,1], [2,1], [0,109], [0,62], 359 | [2,1], [0,200], [0,140], [16,1], [8,1], [4,1], [2,1], [0,228], [0,78], [2,1], 360 | [0,215], [0,125], [4,1], [2,1], [0,229], [0,186], [2,1], [0,171], [0,94], [8,1], 361 | [4,1], [2,1], [0,201], [0,156], [2,1], [0,241], [0,31], [6,1], [4,1], [2,1], 362 | [0,240], [0,110], [0,242], [2,1], [0,47], [0,230], [38,1], [18,1], [8,1], [4,1], 363 | [2,1], [0,216], [0,243], [2,1], [0,63], [0,244], [6,1], [2,1], [0,79], [2,1], 364 | [0,141], [0,217], [2,1], [0,187], [0,202], [8,1], [4,1], [2,1], [0,172], [0,231], 365 | [2,1], [0,126], [0,245], [8,1], [4,1], [2,1], [0,157], [0,95], [2,1], [0,232], 366 | [0,142], [2,1], [0,246], [0,203], [34,1], [18,1], [10,1], [6,1], [4,1], [2,1], 367 | [0,15], [0,174], [0,111], [2,1], [0,188], [0,218], [4,1], [2,1], [0,173], [0,247], 368 | [2,1], [0,127], [0,233], [8,1], [4,1], [2,1], [0,158], [0,204], [2,1], [0,248], 369 | [0,143], [4,1], [2,1], [0,219], [0,189], [2,1], [0,234], [0,249], [16,1], [8,1], 370 | [4,1], [2,1], [0,159], [0,220], [2,1], [0,205], [0,235], [4,1], [2,1], [0,190], 371 | [0,250], [2,1], [0,175], [0,221], [14,1], [6,1], [4,1], [2,1], [0,236], [0,206], 372 | [0,251], [4,1], [2,1], [0,191], [0,237], [2,1], [0,222], [0,252], [6,1], [4,1], 373 | [2,1], [0,207], [0,253], [0,238], [4,1], [2,1], [0,223], [0,254], [2,1], [0,239], 374 | [0,255] 375 | ]; 376 | 377 | protected static var ValTab16:Array = [ 378 | [2,1], [0,0], [6,1], [2,1], [0,16], [2,1], [0,1], [0,17], [42,1], [8,1], 379 | [4,1], [2,1], [0,32], [0,2], [2,1], [0,33], [0,18], [10,1], [6,1], [2,1], 380 | [0,34], [2,1], [0,48], [0,3], [2,1], [0,49], [0,19], [10,1], [4,1], [2,1], 381 | [0,50], [0,35], [4,1], [2,1], [0,64], [0,4], [0,65], [6,1], [2,1], [0,20], 382 | [2,1], [0,51], [0,66], [4,1], [2,1], [0,36], [0,80], [2,1], [0,67], [0,52], 383 | [138,1], [40,1], [16,1], [6,1], [4,1], [2,1], [0,5], [0,21], [0,81], [4,1], 384 | [2,1], [0,82], [0,37], [4,1], [2,1], [0,68], [0,53], [0,83], [10,1], [6,1], 385 | [4,1], [2,1], [0,96], [0,6], [0,97], [2,1], [0,22], [0,98], [8,1], [4,1], 386 | [2,1], [0,38], [0,84], [2,1], [0,69], [0,99], [4,1], [2,1], [0,54], [0,112], 387 | [0,113], [40,1], [18,1], [8,1], [2,1], [0,23], [2,1], [0,7], [2,1], [0,85], 388 | [0,100], [4,1], [2,1], [0,114], [0,39], [4,1], [2,1], [0,70], [0,101], [0,115], 389 | [10,1], [6,1], [2,1], [0,55], [2,1], [0,86], [0,8], [2,1], [0,128], [0,129], 390 | [6,1], [2,1], [0,24], [2,1], [0,116], [0,71], [2,1], [0,130], [2,1], [0,40], 391 | [0,102], [24,1], [14,1], [8,1], [4,1], [2,1], [0,131], [0,56], [2,1], [0,117], 392 | [0,132], [4,1], [2,1], [0,72], [0,144], [0,145], [6,1], [2,1], [0,25], [2,1], 393 | [0,9], [0,118], [2,1], [0,146], [0,41], [14,1], [8,1], [4,1], [2,1], [0,133], 394 | [0,88], [2,1], [0,147], [0,57], [4,1], [2,1], [0,160], [0,10], [0,26], [8,1], 395 | [2,1], [0,162], [2,1], [0,103], [2,1], [0,87], [0,73], [6,1], [2,1], [0,148], 396 | [2,1], [0,119], [0,134], [2,1], [0,161], [2,1], [0,104], [0,149], [220,1], [126,1], 397 | [50,1], [26,1], [12,1], [6,1], [2,1], [0,42], [2,1], [0,89], [0,58], [2,1], 398 | [0,163], [2,1], [0,135], [0,120], [8,1], [4,1], [2,1], [0,164], [0,74], [2,1], 399 | [0,150], [0,105], [4,1], [2,1], [0,176], [0,11], [0,177], [10,1], [4,1], [2,1], 400 | [0,27], [0,178], [2,1], [0,43], [2,1], [0,165], [0,90], [6,1], [2,1], [0,179], 401 | [2,1], [0,166], [0,106], [4,1], [2,1], [0,180], [0,75], [2,1], [0,12], [0,193], 402 | [30,1], [14,1], [6,1], [4,1], [2,1], [0,181], [0,194], [0,44], [4,1], [2,1], 403 | [0,167], [0,195], [2,1], [0,107], [0,196], [8,1], [2,1], [0,29], [4,1], [2,1], 404 | [0,136], [0,151], [0,59], [4,1], [2,1], [0,209], [0,210], [2,1], [0,45], [0,211], 405 | [18,1], [6,1], [4,1], [2,1], [0,30], [0,46], [0,226], [6,1], [4,1], [2,1], 406 | [0,121], [0,152], [0,192], [2,1], [0,28], [2,1], [0,137], [0,91], [14,1], [6,1], 407 | [2,1], [0,60], [2,1], [0,122], [0,182], [4,1], [2,1], [0,76], [0,153], [2,1], 408 | [0,168], [0,138], [6,1], [2,1], [0,13], [2,1], [0,197], [0,92], [4,1], [2,1], 409 | [0,61], [0,198], [2,1], [0,108], [0,154], [88,1], [86,1], [36,1], [16,1], [8,1], 410 | [4,1], [2,1], [0,139], [0,77], [2,1], [0,199], [0,124], [4,1], [2,1], [0,213], 411 | [0,93], [2,1], [0,224], [0,14], [8,1], [2,1], [0,227], [4,1], [2,1], [0,208], 412 | [0,183], [0,123], [6,1], [4,1], [2,1], [0,169], [0,184], [0,212], [2,1], [0,225], 413 | [2,1], [0,170], [0,185], [24,1], [10,1], [6,1], [4,1], [2,1], [0,155], [0,214], 414 | [0,109], [2,1], [0,62], [0,200], [6,1], [4,1], [2,1], [0,140], [0,228], [0,78], 415 | [4,1], [2,1], [0,215], [0,229], [2,1], [0,186], [0,171], [12,1], [4,1], [2,1], 416 | [0,156], [0,230], [4,1], [2,1], [0,110], [0,216], [2,1], [0,141], [0,187], [8,1], 417 | [4,1], [2,1], [0,231], [0,157], [2,1], [0,232], [0,142], [4,1], [2,1], [0,203], 418 | [0,188], [0,158], [0,241], [2,1], [0,31], [2,1], [0,15], [0,47], [66,1], [56,1], 419 | [2,1], [0,242], [52,1], [50,1], [20,1], [8,1], [2,1], [0,189], [2,1], [0,94], 420 | [2,1], [0,125], [0,201], [6,1], [2,1], [0,202], [2,1], [0,172], [0,126], [4,1], 421 | [2,1], [0,218], [0,173], [0,204], [10,1], [6,1], [2,1], [0,174], [2,1], [0,219], 422 | [0,220], [2,1], [0,205], [0,190], [6,1], [4,1], [2,1], [0,235], [0,237], [0,238], 423 | [6,1], [4,1], [2,1], [0,217], [0,234], [0,233], [2,1], [0,222], [4,1], [2,1], 424 | [0,221], [0,236], [0,206], [0,63], [0,240], [4,1], [2,1], [0,243], [0,244], [2,1], 425 | [0,79], [2,1], [0,245], [0,95], [10,1], [2,1], [0,255], [4,1], [2,1], [0,246], 426 | [0,111], [2,1], [0,247], [0,127], [12,1], [6,1], [2,1], [0,143], [2,1], [0,248], 427 | [0,249], [4,1], [2,1], [0,159], [0,250], [0,175], [8,1], [4,1], [2,1], [0,251], 428 | [0,191], [2,1], [0,252], [0,207], [4,1], [2,1], [0,253], [0,223], [2,1], [0,254], 429 | [0,239] 430 | ]; 431 | 432 | protected static var ValTab24:Array = [ 433 | [60,1], [8,1], [4,1], [2,1], [0,0], [0,16], [2,1], [0,1], [0,17], [14,1], 434 | [6,1], [4,1], [2,1], [0,32], [0,2], [0,33], [2,1], [0,18], [2,1], [0,34], 435 | [2,1], [0,48], [0,3], [14,1], [4,1], [2,1], [0,49], [0,19], [4,1], [2,1], 436 | [0,50], [0,35], [4,1], [2,1], [0,64], [0,4], [0,65], [8,1], [4,1], [2,1], 437 | [0,20], [0,51], [2,1], [0,66], [0,36], [6,1], [4,1], [2,1], [0,67], [0,52], 438 | [0,81], [6,1], [4,1], [2,1], [0,80], [0,5], [0,21], [2,1], [0,82], [0,37], 439 | [250,1], [98,1], [34,1], [18,1], [10,1], [4,1], [2,1], [0,68], [0,83], [2,1], 440 | [0,53], [2,1], [0,96], [0,6], [4,1], [2,1], [0,97], [0,22], [2,1], [0,98], 441 | [0,38], [8,1], [4,1], [2,1], [0,84], [0,69], [2,1], [0,99], [0,54], [4,1], 442 | [2,1], [0,113], [0,85], [2,1], [0,100], [0,70], [32,1], [14,1], [6,1], [2,1], 443 | [0,114], [2,1], [0,39], [0,55], [2,1], [0,115], [4,1], [2,1], [0,112], [0,7], 444 | [0,23], [10,1], [4,1], [2,1], [0,101], [0,86], [4,1], [2,1], [0,128], [0,8], 445 | [0,129], [4,1], [2,1], [0,116], [0,71], [2,1], [0,24], [0,130], [16,1], [8,1], 446 | [4,1], [2,1], [0,40], [0,102], [2,1], [0,131], [0,56], [4,1], [2,1], [0,117], 447 | [0,87], [2,1], [0,132], [0,72], [8,1], [4,1], [2,1], [0,145], [0,25], [2,1], 448 | [0,146], [0,118], [4,1], [2,1], [0,103], [0,41], [2,1], [0,133], [0,88], [92,1], 449 | [34,1], [16,1], [8,1], [4,1], [2,1], [0,147], [0,57], [2,1], [0,148], [0,73], 450 | [4,1], [2,1], [0,119], [0,134], [2,1], [0,104], [0,161], [8,1], [4,1], [2,1], 451 | [0,162], [0,42], [2,1], [0,149], [0,89], [4,1], [2,1], [0,163], [0,58], [2,1], 452 | [0,135], [2,1], [0,120], [0,74], [22,1], [12,1], [4,1], [2,1], [0,164], [0,150], 453 | [4,1], [2,1], [0,105], [0,177], [2,1], [0,27], [0,165], [6,1], [2,1], [0,178], 454 | [2,1], [0,90], [0,43], [2,1], [0,136], [0,179], [16,1], [10,1], [6,1], [2,1], 455 | [0,144], [2,1], [0,9], [0,160], [2,1], [0,151], [0,121], [4,1], [2,1], [0,166], 456 | [0,106], [0,180], [12,1], [6,1], [2,1], [0,26], [2,1], [0,10], [0,176], [2,1], 457 | [0,59], [2,1], [0,11], [0,192], [4,1], [2,1], [0,75], [0,193], [2,1], [0,152], 458 | [0,137], [67,1], [34,1], [16,1], [8,1], [4,1], [2,1], [0,28], [0,181], [2,1], 459 | [0,91], [0,194], [4,1], [2,1], [0,44], [0,167], [2,1], [0,122], [0,195], [10,1], 460 | [6,1], [2,1], [0,60], [2,1], [0,12], [0,208], [2,1], [0,182], [0,107], [4,1], 461 | [2,1], [0,196], [0,76], [2,1], [0,153], [0,168], [16,1], [8,1], [4,1], [2,1], 462 | [0,138], [0,197], [2,1], [0,92], [0,209], [4,1], [2,1], [0,183], [0,123], [2,1], 463 | [0,29], [0,210], [9,1], [4,1], [2,1], [0,45], [0,211], [2,1], [0,61], [0,198], 464 | [85,250], [4,1], [2,1], [0,108], [0,169], [2,1], [0,154], [0,212], [32,1], [16,1], 465 | [8,1], [4,1], [2,1], [0,184], [0,139], [2,1], [0,77], [0,199], [4,1], [2,1], 466 | [0,124], [0,213], [2,1], [0,93], [0,225], [8,1], [4,1], [2,1], [0,30], [0,226], 467 | [2,1], [0,170], [0,185], [4,1], [2,1], [0,155], [0,227], [2,1], [0,214], [0,109], 468 | [20,1], [10,1], [6,1], [2,1], [0,62], [2,1], [0,46], [0,78], [2,1], [0,200], 469 | [0,140], [4,1], [2,1], [0,228], [0,215], [4,1], [2,1], [0,125], [0,171], [0,229], 470 | [10,1], [4,1], [2,1], [0,186], [0,94], [2,1], [0,201], [2,1], [0,156], [0,110], 471 | [8,1], [2,1], [0,230], [2,1], [0,13], [2,1], [0,224], [0,14], [4,1], [2,1], 472 | [0,216], [0,141], [2,1], [0,187], [0,202], [74,1], [2,1], [0,255], [64,1], [58,1], 473 | [32,1], [16,1], [8,1], [4,1], [2,1], [0,172], [0,231], [2,1], [0,126], [0,217], 474 | [4,1], [2,1], [0,157], [0,232], [2,1], [0,142], [0,203], [8,1], [4,1], [2,1], 475 | [0,188], [0,218], [2,1], [0,173], [0,233], [4,1], [2,1], [0,158], [0,204], [2,1], 476 | [0,219], [0,189], [16,1], [8,1], [4,1], [2,1], [0,234], [0,174], [2,1], [0,220], 477 | [0,205], [4,1], [2,1], [0,235], [0,190], [2,1], [0,221], [0,236], [8,1], [4,1], 478 | [2,1], [0,206], [0,237], [2,1], [0,222], [0,238], [0,15], [4,1], [2,1], [0,240], 479 | [0,31], [0,241], [4,1], [2,1], [0,242], [0,47], [2,1], [0,243], [0,63], [18,1], 480 | [8,1], [4,1], [2,1], [0,244], [0,79], [2,1], [0,245], [0,95], [4,1], [2,1], 481 | [0,246], [0,111], [2,1], [0,247], [2,1], [0,127], [0,143], [10,1], [4,1], [2,1], 482 | [0,248], [0,249], [4,1], [2,1], [0,159], [0,175], [0,250], [8,1], [4,1], [2,1], 483 | [0,251], [0,191], [2,1], [0,252], [0,207], [4,1], [2,1], [0,253], [0,223], [2,1], 484 | [0,254], [0,239] 485 | ]; 486 | 487 | protected static var ValTab32:Array = [ 488 | [2,1], [0,0], [8,1], [4,1], [2,1], [0,8], [0,4], [2,1], [0,1], [0,2], 489 | [8,1], [4,1], [2,1], [0,12], [0,10], [2,1], [0,3], [0,6], [6,1], [2,1], 490 | [0,9], [2,1], [0,5], [0,7], [4,1], [2,1], [0,14], [0,13], [2,1], [0,15], 491 | [0,11] 492 | ]; 493 | 494 | protected static var ValTab33:Array = [ 495 | [16,1], [8,1], [4,1], [2,1], [0,0], [0,1], [2,1], [0,2], [0,3], [4,1], 496 | [2,1], [0,4], [0,5], [2,1], [0,6], [0,7], [8,1], [4,1], [2,1], [0,8], 497 | [0,9], [2,1], [0,10], [0,11], [4,1], [2,1], [0,12], [0,13], [2,1], [0,14], 498 | [0,15] 499 | ]; 500 | 501 | public static var ht:Vector. = Vector.([ 502 | new HuffCodeTab("0 ", 0, 0, 0, 0, -1, null, null, ValTab0, 0), 503 | new HuffCodeTab("1 ", 2, 2, 0, 0, -1, null, null, ValTab1, 7), 504 | new HuffCodeTab("2 ", 3, 3, 0, 0, -1, null, null, ValTab2, 17), 505 | new HuffCodeTab("3 ", 3, 3, 0, 0, -1, null, null, ValTab3, 17), 506 | new HuffCodeTab("4 ", 0, 0, 0, 0, -1, null, null, ValTab4, 0), 507 | new HuffCodeTab("5 ", 4, 4, 0, 0, -1, null, null, ValTab5, 31), 508 | new HuffCodeTab("6 ", 4, 4, 0, 0, -1, null, null, ValTab6, 31), 509 | new HuffCodeTab("7 ", 6, 6, 0, 0, -1, null, null, ValTab7, 71), 510 | new HuffCodeTab("8 ", 6, 6, 0, 0, -1, null, null, ValTab8, 71), 511 | new HuffCodeTab("9 ", 6, 6, 0, 0, -1, null, null, ValTab9, 71), 512 | new HuffCodeTab("10 ", 8, 8, 0, 0, -1, null, null, ValTab10, 127), 513 | new HuffCodeTab("11 ", 8, 8, 0, 0, -1, null, null, ValTab11, 127), 514 | new HuffCodeTab("12 ", 8, 8, 0, 0, -1, null, null, ValTab12, 127), 515 | new HuffCodeTab("13 ", 16, 16, 0, 0, -1, null, null, ValTab13, 511), 516 | new HuffCodeTab("14 ", 0, 0, 0, 0, -1, null, null, ValTab14, 0), 517 | new HuffCodeTab("15 ", 16, 16, 0, 0, -1, null, null, ValTab15, 511), 518 | new HuffCodeTab("16 ", 16, 16, 1, 1, -1, null, null, ValTab16, 511), 519 | new HuffCodeTab("17 ", 16, 16, 2, 3, 16, null, null, ValTab16, 511), 520 | new HuffCodeTab("18 ", 16, 16, 3, 7, 16, null, null, ValTab16, 511), 521 | new HuffCodeTab("19 ", 16, 16, 4, 15, 16, null, null, ValTab16, 511), 522 | new HuffCodeTab("20 ", 16, 16, 6, 63, 16, null, null, ValTab16, 511), 523 | new HuffCodeTab("21 ", 16, 16, 8, 255, 16, null, null, ValTab16, 511), 524 | new HuffCodeTab("22 ", 16, 16, 10, 1023, 16, null, null, ValTab16, 511), 525 | new HuffCodeTab("23 ", 16, 16, 13, 8191, 16, null, null, ValTab16, 511), 526 | new HuffCodeTab("24 ", 16, 16, 4, 15, -1, null, null, ValTab24, 512), 527 | new HuffCodeTab("25 ", 16, 16, 5, 31, 24, null, null, ValTab24, 512), 528 | new HuffCodeTab("26 ", 16, 16, 6, 63, 24, null, null, ValTab24, 512), 529 | new HuffCodeTab("27 ", 16, 16, 7, 127, 24, null, null, ValTab24, 512), 530 | new HuffCodeTab("28 ", 16, 16, 8, 255, 24, null, null, ValTab24, 512), 531 | new HuffCodeTab("29 ", 16, 16, 9, 511, 24, null, null, ValTab24, 512), 532 | new HuffCodeTab("30 ", 16, 16, 11, 2047, 24, null, null, ValTab24, 512), 533 | new HuffCodeTab("31 ", 16, 16, 13, 8191, 24, null, null, ValTab24, 512), 534 | new HuffCodeTab("32 ", 1, 16, 0, 0, -1, null, null, ValTab32, 31), 535 | new HuffCodeTab("33 ", 1, 16, 0, 0, -1, null, null, ValTab33, 31) 536 | ]); 537 | } 538 | } 539 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/SynthesisFilter.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | import flash.utils.ByteArray; 4 | 5 | public class SynthesisFilter 6 | { 7 | protected var v1:Vector.; 8 | protected var v2:Vector.; 9 | protected var actual_v:Vector.; 10 | protected var actual_write_pos:int; 11 | protected var samples:Vector.; 12 | protected var channel:int; 13 | protected var _tmpOut:Vector.; 14 | //private float[] eq; 15 | 16 | public function SynthesisFilter(channelnumber:int /*, eq0:Vector.*/) 17 | { 18 | v1 = new Vector.(512, true); 19 | v2 = new Vector.(512, true); 20 | samples = new Vector.(32); 21 | _tmpOut = new Vector.(32); 22 | channel = channelnumber; 23 | reset(); 24 | } 25 | 26 | public function reset():void { 27 | var i:int; 28 | for (i = 0; i < 512; i++) { 29 | v1[i] = v2[i] = 0.0; 30 | } 31 | for (i = 0; i < 32; i++) { 32 | samples[i] = 0.0; 33 | } 34 | actual_v = v1; 35 | actual_write_pos = 15; 36 | } 37 | 38 | public function input_samples(s:Vector.):void { 39 | var i:int; 40 | for (i = 31; i >= 0; i--) { 41 | samples[i] = s[i]; /* * eq[i]*/ 42 | } 43 | } 44 | 45 | public function calculate_pcm_samples(buffer:OutputBuffer):void { 46 | compute_new_v(); 47 | compute_pcm_samples(buffer); 48 | actual_write_pos = (actual_write_pos + 1) & 0xf; 49 | actual_v = (actual_v == v1) ? v2 : v1; 50 | // MDM: this may not be necessary. The Layer III decoder always 51 | // outputs 32 subband samples, but I haven't checked layer I & II. 52 | var i:int; 53 | for (i = 0; i < 32; ++i) { 54 | samples[i] = 0.0; 55 | } 56 | } 57 | 58 | protected function compute_new_v():void 59 | { 60 | var new_v0:Number, new_v1:Number, new_v2:Number, new_v3:Number; 61 | var new_v4:Number, new_v5:Number, new_v6:Number, new_v7:Number; 62 | var new_v8:Number, new_v9:Number, new_v10:Number, new_v11:Number; 63 | var new_v12:Number, new_v13:Number, new_v14:Number, new_v15:Number; 64 | var new_v16:Number, new_v17:Number, new_v18:Number, new_v19:Number; 65 | var new_v20:Number, new_v21:Number, new_v22:Number, new_v23:Number; 66 | var new_v24:Number, new_v25:Number, new_v26:Number, new_v27:Number; 67 | var new_v28:Number, new_v29:Number, new_v30:Number, new_v31:Number; 68 | 69 | new_v0 = new_v1 = new_v2 = new_v3 = new_v4 = new_v5 = new_v6 = new_v7 = new_v8 = new_v9 = 70 | new_v10 = new_v11 = new_v12 = new_v13 = new_v14 = new_v15 = new_v16 = new_v17 = new_v18 = new_v19 = 71 | new_v20 = new_v21 = new_v22 = new_v23 = new_v24 = new_v25 = new_v26 = new_v27 = new_v28 = new_v29 = 72 | new_v30 = new_v31 = 0.0; 73 | 74 | var s0:Number = samples[0]; 75 | var s1:Number = samples[1]; 76 | var s2:Number = samples[2]; 77 | var s3:Number = samples[3]; 78 | var s4:Number = samples[4]; 79 | var s5:Number = samples[5]; 80 | var s6:Number = samples[6]; 81 | var s7:Number = samples[7]; 82 | var s8:Number = samples[8]; 83 | var s9:Number = samples[9]; 84 | var s10:Number = samples[10]; 85 | var s11:Number = samples[11]; 86 | var s12:Number = samples[12]; 87 | var s13:Number = samples[13]; 88 | var s14:Number = samples[14]; 89 | var s15:Number = samples[15]; 90 | var s16:Number = samples[16]; 91 | var s17:Number = samples[17]; 92 | var s18:Number = samples[18]; 93 | var s19:Number = samples[19]; 94 | var s20:Number = samples[20]; 95 | var s21:Number = samples[21]; 96 | var s22:Number = samples[22]; 97 | var s23:Number = samples[23]; 98 | var s24:Number = samples[24]; 99 | var s25:Number = samples[25]; 100 | var s26:Number = samples[26]; 101 | var s27:Number = samples[27]; 102 | var s28:Number = samples[28]; 103 | var s29:Number = samples[29]; 104 | var s30:Number = samples[30]; 105 | var s31:Number = samples[31]; 106 | 107 | var p0:Number = s0 + s31; 108 | var p1:Number = s1 + s30; 109 | var p2:Number = s2 + s29; 110 | var p3:Number = s3 + s28; 111 | var p4:Number = s4 + s27; 112 | var p5:Number = s5 + s26; 113 | var p6:Number = s6 + s25; 114 | var p7:Number = s7 + s24; 115 | var p8:Number = s8 + s23; 116 | var p9:Number = s9 + s22; 117 | var p10:Number = s10 + s21; 118 | var p11:Number = s11 + s20; 119 | var p12:Number = s12 + s19; 120 | var p13:Number = s13 + s18; 121 | var p14:Number = s14 + s17; 122 | var p15:Number = s15 + s16; 123 | 124 | var pp0:Number = p0 + p15; 125 | var pp1:Number = p1 + p14; 126 | var pp2:Number = p2 + p13; 127 | var pp3:Number = p3 + p12; 128 | var pp4:Number = p4 + p11; 129 | var pp5:Number = p5 + p10; 130 | var pp6:Number = p6 + p9; 131 | var pp7:Number = p7 + p8; 132 | var pp8:Number = (p0 - p15) * cos1_32; 133 | var pp9:Number = (p1 - p14) * cos3_32; 134 | var pp10:Number = (p2 - p13) * cos5_32; 135 | var pp11:Number = (p3 - p12) * cos7_32; 136 | var pp12:Number = (p4 - p11) * cos9_32; 137 | var pp13:Number = (p5 - p10) * cos11_32; 138 | var pp14:Number = (p6 - p9) * cos13_32; 139 | var pp15:Number = (p7 - p8) * cos15_32; 140 | 141 | p0 = pp0 + pp7; 142 | p1 = pp1 + pp6; 143 | p2 = pp2 + pp5; 144 | p3 = pp3 + pp4; 145 | p4 = (pp0 - pp7) * cos1_16; 146 | p5 = (pp1 - pp6) * cos3_16; 147 | p6 = (pp2 - pp5) * cos5_16; 148 | p7 = (pp3 - pp4) * cos7_16; 149 | p8 = pp8 + pp15; 150 | p9 = pp9 + pp14; 151 | p10 = pp10 + pp13; 152 | p11 = pp11 + pp12; 153 | p12 = (pp8 - pp15) * cos1_16; 154 | p13 = (pp9 - pp14) * cos3_16; 155 | p14 = (pp10 - pp13) * cos5_16; 156 | p15 = (pp11 - pp12) * cos7_16; 157 | 158 | pp0 = p0 + p3; 159 | pp1 = p1 + p2; 160 | pp2 = (p0 - p3) * cos1_8; 161 | pp3 = (p1 - p2) * cos3_8; 162 | pp4 = p4 + p7; 163 | pp5 = p5 + p6; 164 | pp6 = (p4 - p7) * cos1_8; 165 | pp7 = (p5 - p6) * cos3_8; 166 | pp8 = p8 + p11; 167 | pp9 = p9 + p10; 168 | pp10 = (p8 - p11) * cos1_8; 169 | pp11 = (p9 - p10) * cos3_8; 170 | pp12 = p12 + p15; 171 | pp13 = p13 + p14; 172 | pp14 = (p12 - p15) * cos1_8; 173 | pp15 = (p13 - p14) * cos3_8; 174 | 175 | p0 = pp0 + pp1; 176 | p1 = (pp0 - pp1) * cos1_4; 177 | p2 = pp2 + pp3; 178 | p3 = (pp2 - pp3) * cos1_4; 179 | p4 = pp4 + pp5; 180 | p5 = (pp4 - pp5) * cos1_4; 181 | p6 = pp6 + pp7; 182 | p7 = (pp6 - pp7) * cos1_4; 183 | p8 = pp8 + pp9; 184 | p9 = (pp8 - pp9) * cos1_4; 185 | p10 = pp10 + pp11; 186 | p11 = (pp10 - pp11) * cos1_4; 187 | p12 = pp12 + pp13; 188 | p13 = (pp12 - pp13) * cos1_4; 189 | p14 = pp14 + pp15; 190 | p15 = (pp14 - pp15) * cos1_4; 191 | 192 | // this is pretty insane coding 193 | var tmp1:Number; 194 | new_v19/*36-17*/ = -(new_v4 = (new_v12 = p7) + p5) - p6; 195 | new_v27/*44-17*/ = -p6 - p7 - p4; 196 | new_v6 = (new_v10 = (new_v14 = p15) + p11) + p13; 197 | new_v17/*34-17*/ = -(new_v2 = p15 + p13 + p9) - p14; 198 | new_v21/*38-17*/ = (tmp1 = -p14 - p15 - p10 - p11) - p13; 199 | new_v29/*46-17*/ = -p14 - p15 - p12 - p8; 200 | new_v25/*42-17*/ = tmp1 - p12; 201 | new_v31/*48-17*/ = -p0; 202 | new_v0 = p1; 203 | new_v23/*40-17*/ = -(new_v8 = p3) - p2; 204 | 205 | p0 = (s0 - s31) * cos1_64; 206 | p1 = (s1 - s30) * cos3_64; 207 | p2 = (s2 - s29) * cos5_64; 208 | p3 = (s3 - s28) * cos7_64; 209 | p4 = (s4 - s27) * cos9_64; 210 | p5 = (s5 - s26) * cos11_64; 211 | p6 = (s6 - s25) * cos13_64; 212 | p7 = (s7 - s24) * cos15_64; 213 | p8 = (s8 - s23) * cos17_64; 214 | p9 = (s9 - s22) * cos19_64; 215 | p10 = (s10 - s21) * cos21_64; 216 | p11 = (s11 - s20) * cos23_64; 217 | p12 = (s12 - s19) * cos25_64; 218 | p13 = (s13 - s18) * cos27_64; 219 | p14 = (s14 - s17) * cos29_64; 220 | p15 = (s15 - s16) * cos31_64; 221 | 222 | pp0 = p0 + p15; 223 | pp1 = p1 + p14; 224 | pp2 = p2 + p13; 225 | pp3 = p3 + p12; 226 | pp4 = p4 + p11; 227 | pp5 = p5 + p10; 228 | pp6 = p6 + p9; 229 | pp7 = p7 + p8; 230 | pp8 = (p0 - p15) * cos1_32; 231 | pp9 = (p1 - p14) * cos3_32; 232 | pp10 = (p2 - p13) * cos5_32; 233 | pp11 = (p3 - p12) * cos7_32; 234 | pp12 = (p4 - p11) * cos9_32; 235 | pp13 = (p5 - p10) * cos11_32; 236 | pp14 = (p6 - p9) * cos13_32; 237 | pp15 = (p7 - p8) * cos15_32; 238 | 239 | p0 = pp0 + pp7; 240 | p1 = pp1 + pp6; 241 | p2 = pp2 + pp5; 242 | p3 = pp3 + pp4; 243 | p4 = (pp0 - pp7) * cos1_16; 244 | p5 = (pp1 - pp6) * cos3_16; 245 | p6 = (pp2 - pp5) * cos5_16; 246 | p7 = (pp3 - pp4) * cos7_16; 247 | p8 = pp8 + pp15; 248 | p9 = pp9 + pp14; 249 | p10 = pp10 + pp13; 250 | p11 = pp11 + pp12; 251 | p12 = (pp8 - pp15) * cos1_16; 252 | p13 = (pp9 - pp14) * cos3_16; 253 | p14 = (pp10 - pp13) * cos5_16; 254 | p15 = (pp11 - pp12) * cos7_16; 255 | 256 | pp0 = p0 + p3; 257 | pp1 = p1 + p2; 258 | pp2 = (p0 - p3) * cos1_8; 259 | pp3 = (p1 - p2) * cos3_8; 260 | pp4 = p4 + p7; 261 | pp5 = p5 + p6; 262 | pp6 = (p4 - p7) * cos1_8; 263 | pp7 = (p5 - p6) * cos3_8; 264 | pp8 = p8 + p11; 265 | pp9 = p9 + p10; 266 | pp10 = (p8 - p11) * cos1_8; 267 | pp11 = (p9 - p10) * cos3_8; 268 | pp12 = p12 + p15; 269 | pp13 = p13 + p14; 270 | pp14 = (p12 - p15) * cos1_8; 271 | pp15 = (p13 - p14) * cos3_8; 272 | 273 | p0 = pp0 + pp1; 274 | p1 = (pp0 - pp1) * cos1_4; 275 | p2 = pp2 + pp3; 276 | p3 = (pp2 - pp3) * cos1_4; 277 | p4 = pp4 + pp5; 278 | p5 = (pp4 - pp5) * cos1_4; 279 | p6 = pp6 + pp7; 280 | p7 = (pp6 - pp7) * cos1_4; 281 | p8 = pp8 + pp9; 282 | p9 = (pp8 - pp9) * cos1_4; 283 | p10 = pp10 + pp11; 284 | p11 = (pp10 - pp11) * cos1_4; 285 | p12 = pp12 + pp13; 286 | p13 = (pp12 - pp13) * cos1_4; 287 | p14 = pp14 + pp15; 288 | p15 = (pp14 - pp15) * cos1_4; 289 | 290 | // manually doing something that a compiler should handle sucks 291 | // coding like this is hard to read 292 | var tmp2:Number; 293 | new_v5 = (new_v11 = (new_v13 = (new_v15 = p15) + p7) + p11) + p5 + p13; 294 | new_v7 = (new_v9 = p15 + p11 + p3) + p13; 295 | new_v16/*33-17*/ = -(new_v1 = (tmp1 = p13 + p15 + p9) + p1) - p14; 296 | new_v18/*35-17*/ = -(new_v3 = tmp1 + p5 + p7) - p6 - p14; 297 | 298 | new_v22/*39-17*/ = (tmp1 = -p10 - p11 - p14 - p15) - p13 - p2 - p3; 299 | new_v20/*37-17*/ = tmp1 - p13 - p5 - p6 - p7; 300 | new_v24/*41-17*/ = tmp1 - p12 - p2 - p3; 301 | new_v26/*43-17*/ = tmp1 - p12 - (tmp2 = p4 + p6 + p7); 302 | new_v30/*47-17*/ = (tmp1 = -p8 - p12 - p14 - p15) - p0; 303 | new_v28/*45-17*/ = tmp1 - tmp2; 304 | 305 | var dest:Vector. = actual_v; 306 | var pos:int = actual_write_pos; 307 | 308 | // insert V[0-15] (== new_v[0-15]) into actual v: 309 | dest[0 + pos] = new_v0; 310 | dest[16 + pos] = new_v1; 311 | dest[32 + pos] = new_v2; 312 | dest[48 + pos] = new_v3; 313 | dest[64 + pos] = new_v4; 314 | dest[80 + pos] = new_v5; 315 | dest[96 + pos] = new_v6; 316 | dest[112 + pos] = new_v7; 317 | dest[128 + pos] = new_v8; 318 | dest[144 + pos] = new_v9; 319 | dest[160 + pos] = new_v10; 320 | dest[176 + pos] = new_v11; 321 | dest[192 + pos] = new_v12; 322 | dest[208 + pos] = new_v13; 323 | dest[224 + pos] = new_v14; 324 | dest[240 + pos] = new_v15; 325 | 326 | // V[16] is always 0.0: 327 | dest[256 + pos] = 0.0; 328 | 329 | // insert V[17-31] (== -new_v[15-1]) into actual v: 330 | dest[272 + pos] = -new_v15; 331 | dest[288 + pos] = -new_v14; 332 | dest[304 + pos] = -new_v13; 333 | dest[320 + pos] = -new_v12; 334 | dest[336 + pos] = -new_v11; 335 | dest[352 + pos] = -new_v10; 336 | dest[368 + pos] = -new_v9; 337 | dest[384 + pos] = -new_v8; 338 | dest[400 + pos] = -new_v7; 339 | dest[416 + pos] = -new_v6; 340 | dest[432 + pos] = -new_v5; 341 | dest[448 + pos] = -new_v4; 342 | dest[464 + pos] = -new_v3; 343 | dest[480 + pos] = -new_v2; 344 | dest[496 + pos] = -new_v1; 345 | 346 | dest = (actual_v == v1) ? v2 : v1; 347 | 348 | // insert V[32] (== -new_v[0]) into other v: 349 | dest[0 + pos] = -new_v0; 350 | 351 | // insert V[33-48] (== new_v[16-31]) into other v: 352 | dest[16 + pos] = new_v16; 353 | dest[32 + pos] = new_v17; 354 | dest[48 + pos] = new_v18; 355 | dest[64 + pos] = new_v19; 356 | dest[80 + pos] = new_v20; 357 | dest[96 + pos] = new_v21; 358 | dest[112 + pos] = new_v22; 359 | dest[128 + pos] = new_v23; 360 | dest[144 + pos] = new_v24; 361 | dest[160 + pos] = new_v25; 362 | dest[176 + pos] = new_v26; 363 | dest[192 + pos] = new_v27; 364 | dest[208 + pos] = new_v28; 365 | dest[224 + pos] = new_v29; 366 | dest[240 + pos] = new_v30; 367 | dest[256 + pos] = new_v31; 368 | 369 | // insert V[49-63] (== new_v[30-16]) into other v: 370 | dest[272 + pos] = new_v30; 371 | dest[288 + pos] = new_v29; 372 | dest[304 + pos] = new_v28; 373 | dest[320 + pos] = new_v27; 374 | dest[336 + pos] = new_v26; 375 | dest[352 + pos] = new_v25; 376 | dest[368 + pos] = new_v24; 377 | dest[384 + pos] = new_v23; 378 | dest[400 + pos] = new_v22; 379 | dest[416 + pos] = new_v21; 380 | dest[432 + pos] = new_v20; 381 | dest[448 + pos] = new_v19; 382 | dest[464 + pos] = new_v18; 383 | dest[480 + pos] = new_v17; 384 | dest[496 + pos] = new_v16; 385 | } 386 | 387 | protected function compute_pcm_samples(buffer:OutputBuffer):void { 388 | switch (actual_write_pos) { 389 | case 0: compute_pcm_samples0(); break; 390 | case 1: compute_pcm_samples1(); break; 391 | case 2: compute_pcm_samples2(); break; 392 | case 3: compute_pcm_samples3(); break; 393 | case 4: compute_pcm_samples4(); break; 394 | case 5: compute_pcm_samples5(); break; 395 | case 6: compute_pcm_samples6(); break; 396 | case 7: compute_pcm_samples7(); break; 397 | case 8: compute_pcm_samples8(); break; 398 | case 9: compute_pcm_samples9(); break; 399 | case 10: compute_pcm_samples10(); break; 400 | case 11: compute_pcm_samples11(); break; 401 | case 12: compute_pcm_samples12(); break; 402 | case 13: compute_pcm_samples13(); break; 403 | case 14: compute_pcm_samples14(); break; 404 | case 15: compute_pcm_samples15(); break; 405 | } 406 | if (buffer != null) { 407 | buffer.appendSamples(channel, _tmpOut); 408 | } 409 | } 410 | 411 | protected function compute_pcm_samples0():void { 412 | var vp:Vector. = actual_v; 413 | var dvp:int = 0; 414 | var i:int; 415 | for(i = 0; i < 32; ++i) { 416 | var dp:Vector. = d16[i]; 417 | _tmpOut[i] = ( 418 | vp[0 + dvp] * dp[0] + 419 | vp[15 + dvp] * dp[1] + 420 | vp[14 + dvp] * dp[2] + 421 | vp[13 + dvp] * dp[3] + 422 | vp[12 + dvp] * dp[4] + 423 | vp[11 + dvp] * dp[5] + 424 | vp[10 + dvp] * dp[6] + 425 | vp[9 + dvp] * dp[7] + 426 | vp[8 + dvp] * dp[8] + 427 | vp[7 + dvp] * dp[9] + 428 | vp[6 + dvp] * dp[10] + 429 | vp[5 + dvp] * dp[11] + 430 | vp[4 + dvp] * dp[12] + 431 | vp[3 + dvp] * dp[13] + 432 | vp[2 + dvp] * dp[14] + 433 | vp[1 + dvp] * dp[15] 434 | ); 435 | dvp += 16; 436 | } 437 | } 438 | 439 | protected function compute_pcm_samples1():void { 440 | var vp:Vector. = actual_v; 441 | var dvp:int = 0; 442 | var i:int; 443 | for(i = 0; i < 32; i++) { 444 | var dp:Vector. = d16[i]; 445 | _tmpOut[i] = ( 446 | vp[1 + dvp] * dp[0] + 447 | vp[0 + dvp] * dp[1] + 448 | vp[15 + dvp] * dp[2] + 449 | vp[14 + dvp] * dp[3] + 450 | vp[13 + dvp] * dp[4] + 451 | vp[12 + dvp] * dp[5] + 452 | vp[11 + dvp] * dp[6] + 453 | vp[10 + dvp] * dp[7] + 454 | vp[9 + dvp] * dp[8] + 455 | vp[8 + dvp] * dp[9] + 456 | vp[7 + dvp] * dp[10] + 457 | vp[6 + dvp] * dp[11] + 458 | vp[5 + dvp] * dp[12] + 459 | vp[4 + dvp] * dp[13] + 460 | vp[3 + dvp] * dp[14] + 461 | vp[2 + dvp] * dp[15] 462 | ); 463 | dvp += 16; 464 | } 465 | } 466 | 467 | protected function compute_pcm_samples2():void { 468 | var vp:Vector. = actual_v; 469 | var dvp:int = 0; 470 | var i:int; 471 | for(i = 0; i < 32; i++) { 472 | var dp:Vector. = d16[i]; 473 | _tmpOut[i] = ( 474 | vp[2 + dvp] * dp[0] + 475 | vp[1 + dvp] * dp[1] + 476 | vp[0 + dvp] * dp[2] + 477 | vp[15 + dvp] * dp[3] + 478 | vp[14 + dvp] * dp[4] + 479 | vp[13 + dvp] * dp[5] + 480 | vp[12 + dvp] * dp[6] + 481 | vp[11 + dvp] * dp[7] + 482 | vp[10 + dvp] * dp[8] + 483 | vp[9 + dvp] * dp[9] + 484 | vp[8 + dvp] * dp[10] + 485 | vp[7 + dvp] * dp[11] + 486 | vp[6 + dvp] * dp[12] + 487 | vp[5 + dvp] * dp[13] + 488 | vp[4 + dvp] * dp[14] + 489 | vp[3 + dvp] * dp[15] 490 | ); 491 | dvp += 16; 492 | } 493 | } 494 | 495 | protected function compute_pcm_samples3():void { 496 | var vp:Vector. = actual_v; 497 | var dvp:int = 0; 498 | var i:int; 499 | for(i = 0; i < 32; i++) { 500 | var dp:Vector. = d16[i]; 501 | _tmpOut[i] = ( 502 | vp[3 + dvp] * dp[0] + 503 | vp[2 + dvp] * dp[1] + 504 | vp[1 + dvp] * dp[2] + 505 | vp[0 + dvp] * dp[3] + 506 | vp[15 + dvp] * dp[4] + 507 | vp[14 + dvp] * dp[5] + 508 | vp[13 + dvp] * dp[6] + 509 | vp[12 + dvp] * dp[7] + 510 | vp[11 + dvp] * dp[8] + 511 | vp[10 + dvp] * dp[9] + 512 | vp[9 + dvp] * dp[10] + 513 | vp[8 + dvp] * dp[11] + 514 | vp[7 + dvp] * dp[12] + 515 | vp[6 + dvp] * dp[13] + 516 | vp[5 + dvp] * dp[14] + 517 | vp[4 + dvp] * dp[15] 518 | ); 519 | dvp += 16; 520 | } 521 | } 522 | 523 | protected function compute_pcm_samples4():void { 524 | var vp:Vector. = actual_v; 525 | var dvp:int = 0; 526 | var i:int; 527 | for(i = 0; i < 32; i++) { 528 | var dp:Vector. = d16[i]; 529 | _tmpOut[i] = ( 530 | vp[4 + dvp] * dp[0] + 531 | vp[3 + dvp] * dp[1] + 532 | vp[2 + dvp] * dp[2] + 533 | vp[1 + dvp] * dp[3] + 534 | vp[0 + dvp] * dp[4] + 535 | vp[15 + dvp] * dp[5] + 536 | vp[14 + dvp] * dp[6] + 537 | vp[13 + dvp] * dp[7] + 538 | vp[12 + dvp] * dp[8] + 539 | vp[11 + dvp] * dp[9] + 540 | vp[10 + dvp] * dp[10] + 541 | vp[9 + dvp] * dp[11] + 542 | vp[8 + dvp] * dp[12] + 543 | vp[7 + dvp] * dp[13] + 544 | vp[6 + dvp] * dp[14] + 545 | vp[5 + dvp] * dp[15] 546 | ); 547 | dvp += 16; 548 | } 549 | } 550 | 551 | protected function compute_pcm_samples5():void { 552 | var vp:Vector. = actual_v; 553 | var dvp:int = 0; 554 | var i:int; 555 | for(i = 0; i < 32; i++) { 556 | var dp:Vector. = d16[i]; 557 | _tmpOut[i] = ( 558 | vp[5 + dvp] * dp[0] + 559 | vp[4 + dvp] * dp[1] + 560 | vp[3 + dvp] * dp[2] + 561 | vp[2 + dvp] * dp[3] + 562 | vp[1 + dvp] * dp[4] + 563 | vp[0 + dvp] * dp[5] + 564 | vp[15 + dvp] * dp[6] + 565 | vp[14 + dvp] * dp[7] + 566 | vp[13 + dvp] * dp[8] + 567 | vp[12 + dvp] * dp[9] + 568 | vp[11 + dvp] * dp[10] + 569 | vp[10 + dvp] * dp[11] + 570 | vp[9 + dvp] * dp[12] + 571 | vp[8 + dvp] * dp[13] + 572 | vp[7 + dvp] * dp[14] + 573 | vp[6 + dvp] * dp[15] 574 | ); 575 | dvp += 16; 576 | } 577 | } 578 | 579 | protected function compute_pcm_samples6():void { 580 | var vp:Vector. = actual_v; 581 | var dvp:int = 0; 582 | var i:int; 583 | for(i = 0; i < 32; i++) { 584 | var dp:Vector. = d16[i]; 585 | _tmpOut[i] = ( 586 | vp[6 + dvp] * dp[0] + 587 | vp[5 + dvp] * dp[1] + 588 | vp[4 + dvp] * dp[2] + 589 | vp[3 + dvp] * dp[3] + 590 | vp[2 + dvp] * dp[4] + 591 | vp[1 + dvp] * dp[5] + 592 | vp[0 + dvp] * dp[6] + 593 | vp[15 + dvp] * dp[7] + 594 | vp[14 + dvp] * dp[8] + 595 | vp[13 + dvp] * dp[9] + 596 | vp[12 + dvp] * dp[10] + 597 | vp[11 + dvp] * dp[11] + 598 | vp[10 + dvp] * dp[12] + 599 | vp[9 + dvp] * dp[13] + 600 | vp[8 + dvp] * dp[14] + 601 | vp[7 + dvp] * dp[15] 602 | ); 603 | dvp += 16; 604 | } 605 | } 606 | 607 | protected function compute_pcm_samples7():void { 608 | var vp:Vector. = actual_v; 609 | var dvp:int = 0; 610 | var i:int; 611 | for(i = 0; i < 32; i++) { 612 | var dp:Vector. = d16[i]; 613 | _tmpOut[i] = ( 614 | vp[7 + dvp] * dp[0] + 615 | vp[6 + dvp] * dp[1] + 616 | vp[5 + dvp] * dp[2] + 617 | vp[4 + dvp] * dp[3] + 618 | vp[3 + dvp] * dp[4] + 619 | vp[2 + dvp] * dp[5] + 620 | vp[1 + dvp] * dp[6] + 621 | vp[0 + dvp] * dp[7] + 622 | vp[15 + dvp] * dp[8] + 623 | vp[14 + dvp] * dp[9] + 624 | vp[13 + dvp] * dp[10] + 625 | vp[12 + dvp] * dp[11] + 626 | vp[11 + dvp] * dp[12] + 627 | vp[10 + dvp] * dp[13] + 628 | vp[9 + dvp] * dp[14] + 629 | vp[8 + dvp] * dp[15] 630 | ); 631 | dvp += 16; 632 | } 633 | } 634 | 635 | protected function compute_pcm_samples8():void { 636 | var vp:Vector. = actual_v; 637 | var dvp:int = 0; 638 | var i:int; 639 | for(i = 0; i < 32; i++) { 640 | var dp:Vector. = d16[i]; 641 | _tmpOut[i] = ( 642 | vp[8 + dvp] * dp[0] + 643 | vp[7 + dvp] * dp[1] + 644 | vp[6 + dvp] * dp[2] + 645 | vp[5 + dvp] * dp[3] + 646 | vp[4 + dvp] * dp[4] + 647 | vp[3 + dvp] * dp[5] + 648 | vp[2 + dvp] * dp[6] + 649 | vp[1 + dvp] * dp[7] + 650 | vp[0 + dvp] * dp[8] + 651 | vp[15 + dvp] * dp[9] + 652 | vp[14 + dvp] * dp[10] + 653 | vp[13 + dvp] * dp[11] + 654 | vp[12 + dvp] * dp[12] + 655 | vp[11 + dvp] * dp[13] + 656 | vp[10 + dvp] * dp[14] + 657 | vp[9 + dvp] * dp[15] 658 | ); 659 | dvp += 16; 660 | } 661 | } 662 | 663 | protected function compute_pcm_samples9():void { 664 | var vp:Vector. = actual_v; 665 | var dvp:int = 0; 666 | var i:int; 667 | for(i = 0; i < 32; i++) { 668 | var dp:Vector. = d16[i]; 669 | _tmpOut[i] = ( 670 | vp[9 + dvp] * dp[0] + 671 | vp[8 + dvp] * dp[1] + 672 | vp[7 + dvp] * dp[2] + 673 | vp[6 + dvp] * dp[3] + 674 | vp[5 + dvp] * dp[4] + 675 | vp[4 + dvp] * dp[5] + 676 | vp[3 + dvp] * dp[6] + 677 | vp[2 + dvp] * dp[7] + 678 | vp[1 + dvp] * dp[8] + 679 | vp[0 + dvp] * dp[9] + 680 | vp[15 + dvp] * dp[10] + 681 | vp[14 + dvp] * dp[11] + 682 | vp[13 + dvp] * dp[12] + 683 | vp[12 + dvp] * dp[13] + 684 | vp[11 + dvp] * dp[14] + 685 | vp[10 + dvp] * dp[15] 686 | ); 687 | dvp += 16; 688 | } 689 | } 690 | 691 | protected function compute_pcm_samples10():void { 692 | var vp:Vector. = actual_v; 693 | var dvp:int = 0; 694 | var i:int; 695 | for(i = 0; i < 32; i++) { 696 | var dp:Vector. = d16[i]; 697 | _tmpOut[i] = ( 698 | vp[10 + dvp] * dp[0] + 699 | vp[9 + dvp] * dp[1] + 700 | vp[8 + dvp] * dp[2] + 701 | vp[7 + dvp] * dp[3] + 702 | vp[6 + dvp] * dp[4] + 703 | vp[5 + dvp] * dp[5] + 704 | vp[4 + dvp] * dp[6] + 705 | vp[3 + dvp] * dp[7] + 706 | vp[2 + dvp] * dp[8] + 707 | vp[1 + dvp] * dp[9] + 708 | vp[0 + dvp] * dp[10] + 709 | vp[15 + dvp] * dp[11] + 710 | vp[14 + dvp] * dp[12] + 711 | vp[13 + dvp] * dp[13] + 712 | vp[12 + dvp] * dp[14] + 713 | vp[11 + dvp] * dp[15] 714 | ); 715 | dvp += 16; 716 | } 717 | } 718 | 719 | protected function compute_pcm_samples11():void { 720 | var vp:Vector. = actual_v; 721 | var dvp:int = 0; 722 | var i:int; 723 | for(i = 0; i < 32; i++) { 724 | var dp:Vector. = d16[i]; 725 | _tmpOut[i] = ( 726 | vp[11 + dvp] * dp[0] + 727 | vp[10 + dvp] * dp[1] + 728 | vp[9 + dvp] * dp[2] + 729 | vp[8 + dvp] * dp[3] + 730 | vp[7 + dvp] * dp[4] + 731 | vp[6 + dvp] * dp[5] + 732 | vp[5 + dvp] * dp[6] + 733 | vp[4 + dvp] * dp[7] + 734 | vp[3 + dvp] * dp[8] + 735 | vp[2 + dvp] * dp[9] + 736 | vp[1 + dvp] * dp[10] + 737 | vp[0 + dvp] * dp[11] + 738 | vp[15 + dvp] * dp[12] + 739 | vp[14 + dvp] * dp[13] + 740 | vp[13 + dvp] * dp[14] + 741 | vp[12 + dvp] * dp[15] 742 | ); 743 | dvp += 16; 744 | } 745 | } 746 | 747 | protected function compute_pcm_samples12():void { 748 | var vp:Vector. = actual_v; 749 | var dvp:int = 0; 750 | var i:int; 751 | for(i = 0; i < 32; i++) { 752 | var dp:Vector. = d16[i]; 753 | _tmpOut[i] = ( 754 | vp[12 + dvp] * dp[0] + 755 | vp[11 + dvp] * dp[1] + 756 | vp[10 + dvp] * dp[2] + 757 | vp[9 + dvp] * dp[3] + 758 | vp[8 + dvp] * dp[4] + 759 | vp[7 + dvp] * dp[5] + 760 | vp[6 + dvp] * dp[6] + 761 | vp[5 + dvp] * dp[7] + 762 | vp[4 + dvp] * dp[8] + 763 | vp[3 + dvp] * dp[9] + 764 | vp[2 + dvp] * dp[10] + 765 | vp[1 + dvp] * dp[11] + 766 | vp[0 + dvp] * dp[12] + 767 | vp[15 + dvp] * dp[13] + 768 | vp[14 + dvp] * dp[14] + 769 | vp[13 + dvp] * dp[15] 770 | ); 771 | dvp += 16; 772 | } 773 | } 774 | 775 | protected function compute_pcm_samples13():void { 776 | var vp:Vector. = actual_v; 777 | var dvp:int = 0; 778 | var i:int; 779 | for(i = 0; i < 32; i++) { 780 | var dp:Vector. = d16[i]; 781 | _tmpOut[i] = ( 782 | vp[13 + dvp] * dp[0] + 783 | vp[12 + dvp] * dp[1] + 784 | vp[11 + dvp] * dp[2] + 785 | vp[10 + dvp] * dp[3] + 786 | vp[9 + dvp] * dp[4] + 787 | vp[8 + dvp] * dp[5] + 788 | vp[7 + dvp] * dp[6] + 789 | vp[6 + dvp] * dp[7] + 790 | vp[5 + dvp] * dp[8] + 791 | vp[4 + dvp] * dp[9] + 792 | vp[3 + dvp] * dp[10] + 793 | vp[2 + dvp] * dp[11] + 794 | vp[1 + dvp] * dp[12] + 795 | vp[0 + dvp] * dp[13] + 796 | vp[15 + dvp] * dp[14] + 797 | vp[14 + dvp] * dp[15] 798 | ); 799 | dvp += 16; 800 | } 801 | } 802 | 803 | protected function compute_pcm_samples14():void { 804 | var vp:Vector. = actual_v; 805 | var dvp:int = 0; 806 | var i:int; 807 | for(i = 0; i < 32; i++) { 808 | var dp:Vector. = d16[i]; 809 | _tmpOut[i] = ( 810 | vp[14 + dvp] * dp[0] + 811 | vp[13 + dvp] * dp[1] + 812 | vp[12 + dvp] * dp[2] + 813 | vp[11 + dvp] * dp[3] + 814 | vp[10 + dvp] * dp[4] + 815 | vp[9 + dvp] * dp[5] + 816 | vp[8 + dvp] * dp[6] + 817 | vp[7 + dvp] * dp[7] + 818 | vp[6 + dvp] * dp[8] + 819 | vp[5 + dvp] * dp[9] + 820 | vp[4 + dvp] * dp[10] + 821 | vp[3 + dvp] * dp[11] + 822 | vp[2 + dvp] * dp[12] + 823 | vp[1 + dvp] * dp[13] + 824 | vp[0 + dvp] * dp[14] + 825 | vp[15 + dvp] * dp[15] 826 | ); 827 | dvp += 16; 828 | } 829 | } 830 | 831 | protected function compute_pcm_samples15():void { 832 | var vp:Vector. = actual_v; 833 | var dvp:int = 0; 834 | var i:int; 835 | for(i = 0; i < 32; i++) { 836 | var dp:Vector. = d16[i]; 837 | _tmpOut[i] = ( 838 | vp[15 + dvp] * dp[0] + 839 | vp[14 + dvp] * dp[1] + 840 | vp[13 + dvp] * dp[2] + 841 | vp[12 + dvp] * dp[3] + 842 | vp[11 + dvp] * dp[4] + 843 | vp[10 + dvp] * dp[5] + 844 | vp[9 + dvp] * dp[6] + 845 | vp[8 + dvp] * dp[7] + 846 | vp[7 + dvp] * dp[8] + 847 | vp[6 + dvp] * dp[9] + 848 | vp[5 + dvp] * dp[10] + 849 | vp[4 + dvp] * dp[11] + 850 | vp[3 + dvp] * dp[12] + 851 | vp[2 + dvp] * dp[13] + 852 | vp[1 + dvp] * dp[14] + 853 | vp[0 + dvp] * dp[15] 854 | ); 855 | dvp += 16; 856 | } 857 | } 858 | 859 | protected static const cos1_64 = 1.0 / (2.0 * Math.cos(Math.PI / 64.0)); 860 | protected static const cos3_64 = 1.0 / (2.0 * Math.cos(Math.PI * 3.0 / 64.0)); 861 | protected static const cos5_64 = 1.0 / (2.0 * Math.cos(Math.PI * 5.0 / 64.0)); 862 | protected static const cos7_64 = 1.0 / (2.0 * Math.cos(Math.PI * 7.0 / 64.0)); 863 | protected static const cos9_64 = 1.0 / (2.0 * Math.cos(Math.PI * 9.0 / 64.0)); 864 | protected static const cos11_64 = 1.0 / (2.0 * Math.cos(Math.PI * 11.0 / 64.0)); 865 | protected static const cos13_64 = 1.0 / (2.0 * Math.cos(Math.PI * 13.0 / 64.0)); 866 | protected static const cos15_64 = 1.0 / (2.0 * Math.cos(Math.PI * 15.0 / 64.0)); 867 | protected static const cos17_64 = 1.0 / (2.0 * Math.cos(Math.PI * 17.0 / 64.0)); 868 | protected static const cos19_64 = 1.0 / (2.0 * Math.cos(Math.PI * 19.0 / 64.0)); 869 | protected static const cos21_64 = 1.0 / (2.0 * Math.cos(Math.PI * 21.0 / 64.0)); 870 | protected static const cos23_64 = 1.0 / (2.0 * Math.cos(Math.PI * 23.0 / 64.0)); 871 | protected static const cos25_64 = 1.0 / (2.0 * Math.cos(Math.PI * 25.0 / 64.0)); 872 | protected static const cos27_64 = 1.0 / (2.0 * Math.cos(Math.PI * 27.0 / 64.0)); 873 | protected static const cos29_64 = 1.0 / (2.0 * Math.cos(Math.PI * 29.0 / 64.0)); 874 | protected static const cos31_64 = 1.0 / (2.0 * Math.cos(Math.PI * 31.0 / 64.0)); 875 | protected static const cos1_32 = 1.0 / (2.0 * Math.cos(Math.PI / 32.0)); 876 | protected static const cos3_32 = 1.0 / (2.0 * Math.cos(Math.PI * 3.0 / 32.0)); 877 | protected static const cos5_32 = 1.0 / (2.0 * Math.cos(Math.PI * 5.0 / 32.0)); 878 | protected static const cos7_32 = 1.0 / (2.0 * Math.cos(Math.PI * 7.0 / 32.0)); 879 | protected static const cos9_32 = 1.0 / (2.0 * Math.cos(Math.PI * 9.0 / 32.0)); 880 | protected static const cos11_32 = 1.0 / (2.0 * Math.cos(Math.PI * 11.0 / 32.0)); 881 | protected static const cos13_32 = 1.0 / (2.0 * Math.cos(Math.PI * 13.0 / 32.0)); 882 | protected static const cos15_32 = 1.0 / (2.0 * Math.cos(Math.PI * 15.0 / 32.0)); 883 | protected static const cos1_16 = 1.0 / (2.0 * Math.cos(Math.PI / 16.0)); 884 | protected static const cos3_16 = 1.0 / (2.0 * Math.cos(Math.PI * 3.0 / 16.0)); 885 | protected static const cos5_16 = 1.0 / (2.0 * Math.cos(Math.PI * 5.0 / 16.0)); 886 | protected static const cos7_16 = 1.0 / (2.0 * Math.cos(Math.PI * 7.0 / 16.0)); 887 | protected static const cos1_8 = 1.0 / (2.0 * Math.cos(Math.PI / 8.0)); 888 | protected static const cos3_8 = 1.0 / (2.0 * Math.cos(Math.PI * 3.0 / 8.0)); 889 | protected static const cos1_4 = 1.0 / (2.0 * Math.cos(Math.PI / 4.0)); 890 | 891 | protected static var d:Vector. = 892 | Vector.([ 893 | 0.000000000, -0.000442505, 0.003250122, -0.007003784, 894 | 0.031082153, -0.078628540, 0.100311279, -0.572036743, 895 | 1.144989014, 0.572036743, 0.100311279, 0.078628540, 896 | 0.031082153, 0.007003784, 0.003250122, 0.000442505, 897 | -0.000015259, -0.000473022, 0.003326416, -0.007919312, 898 | 0.030517578, -0.084182739, 0.090927124, -0.600219727, 899 | 1.144287109, 0.543823242, 0.108856201, 0.073059082, 900 | 0.031478882, 0.006118774, 0.003173828, 0.000396729, 901 | -0.000015259, -0.000534058, 0.003387451, -0.008865356, 902 | 0.029785156, -0.089706421, 0.080688477, -0.628295898, 903 | 1.142211914, 0.515609741, 0.116577148, 0.067520142, 904 | 0.031738281, 0.005294800, 0.003082275, 0.000366211, 905 | -0.000015259, -0.000579834, 0.003433228, -0.009841919, 906 | 0.028884888, -0.095169067, 0.069595337, -0.656219482, 907 | 1.138763428, 0.487472534, 0.123474121, 0.061996460, 908 | 0.031845093, 0.004486084, 0.002990723, 0.000320435, 909 | -0.000015259, -0.000625610, 0.003463745, -0.010848999, 910 | 0.027801514, -0.100540161, 0.057617188, -0.683914185, 911 | 1.133926392, 0.459472656, 0.129577637, 0.056533813, 912 | 0.031814575, 0.003723145, 0.002899170, 0.000289917, 913 | -0.000015259, -0.000686646, 0.003479004, -0.011886597, 914 | 0.026535034, -0.105819702, 0.044784546, -0.711318970, 915 | 1.127746582, 0.431655884, 0.134887695, 0.051132202, 916 | 0.031661987, 0.003005981, 0.002792358, 0.000259399, 917 | -0.000015259, -0.000747681, 0.003479004, -0.012939453, 918 | 0.025085449, -0.110946655, 0.031082153, -0.738372803, 919 | 1.120223999, 0.404083252, 0.139450073, 0.045837402, 920 | 0.031387329, 0.002334595, 0.002685547, 0.000244141, 921 | -0.000030518, -0.000808716, 0.003463745, -0.014022827, 922 | 0.023422241, -0.115921021, 0.016510010, -0.765029907, 923 | 1.111373901, 0.376800537, 0.143264771, 0.040634155, 924 | 0.031005859, 0.001693726, 0.002578735, 0.000213623, 925 | -0.000030518, -0.000885010, 0.003417969, -0.015121460, 926 | 0.021575928, -0.120697021, 0.001068115, -0.791213989, 927 | 1.101211548, 0.349868774, 0.146362305, 0.035552979, 928 | 0.030532837, 0.001098633, 0.002456665, 0.000198364, 929 | -0.000030518, -0.000961304, 0.003372192, -0.016235352, 930 | 0.019531250, -0.125259399, -0.015228271, -0.816864014, 931 | 1.089782715, 0.323318481, 0.148773193, 0.030609131, 932 | 0.029937744, 0.000549316, 0.002349854, 0.000167847, 933 | -0.000030518, -0.001037598, 0.003280640, -0.017349243, 934 | 0.017257690, -0.129562378, -0.032379150, -0.841949463, 935 | 1.077117920, 0.297210693, 0.150497437, 0.025817871, 936 | 0.029281616, 0.000030518, 0.002243042, 0.000152588, 937 | -0.000045776, -0.001113892, 0.003173828, -0.018463135, 938 | 0.014801025, -0.133590698, -0.050354004, -0.866363525, 939 | 1.063217163, 0.271591187, 0.151596069, 0.021179199, 940 | 0.028533936, -0.000442505, 0.002120972, 0.000137329, 941 | -0.000045776, -0.001205444, 0.003051758, -0.019577026, 942 | 0.012115479, -0.137298584, -0.069168091, -0.890090942, 943 | 1.048156738, 0.246505737, 0.152069092, 0.016708374, 944 | 0.027725220, -0.000869751, 0.002014160, 0.000122070, 945 | -0.000061035, -0.001296997, 0.002883911, -0.020690918, 946 | 0.009231567, -0.140670776, -0.088775635, -0.913055420, 947 | 1.031936646, 0.221984863, 0.151962280, 0.012420654, 948 | 0.026840210, -0.001266479, 0.001907349, 0.000106812, 949 | -0.000061035, -0.001388550, 0.002700806, -0.021789551, 950 | 0.006134033, -0.143676758, -0.109161377, -0.935195923, 951 | 1.014617920, 0.198059082, 0.151306152, 0.008316040, 952 | 0.025909424, -0.001617432, 0.001785278, 0.000106812, 953 | -0.000076294, -0.001480103, 0.002487183, -0.022857666, 954 | 0.002822876, -0.146255493, -0.130310059, -0.956481934, 955 | 0.996246338, 0.174789429, 0.150115967, 0.004394531, 956 | 0.024932861, -0.001937866, 0.001693726, 0.000091553, 957 | -0.000076294, -0.001586914, 0.002227783, -0.023910522, 958 | -0.000686646, -0.148422241, -0.152206421, -0.976852417, 959 | 0.976852417, 0.152206421, 0.148422241, 0.000686646, 960 | 0.023910522, -0.002227783, 0.001586914, 0.000076294, 961 | -0.000091553, -0.001693726, 0.001937866, -0.024932861, 962 | -0.004394531, -0.150115967, -0.174789429, -0.996246338, 963 | 0.956481934, 0.130310059, 0.146255493, -0.002822876, 964 | 0.022857666, -0.002487183, 0.001480103, 0.000076294, 965 | -0.000106812, -0.001785278, 0.001617432, -0.025909424, 966 | -0.008316040, -0.151306152, -0.198059082, -1.014617920, 967 | 0.935195923, 0.109161377, 0.143676758, -0.006134033, 968 | 0.021789551, -0.002700806, 0.001388550, 0.000061035, 969 | -0.000106812, -0.001907349, 0.001266479, -0.026840210, 970 | -0.012420654, -0.151962280, -0.221984863, -1.031936646, 971 | 0.913055420, 0.088775635, 0.140670776, -0.009231567, 972 | 0.020690918, -0.002883911, 0.001296997, 0.000061035, 973 | -0.000122070, -0.002014160, 0.000869751, -0.027725220, 974 | -0.016708374, -0.152069092, -0.246505737, -1.048156738, 975 | 0.890090942, 0.069168091, 0.137298584, -0.012115479, 976 | 0.019577026, -0.003051758, 0.001205444, 0.000045776, 977 | -0.000137329, -0.002120972, 0.000442505, -0.028533936, 978 | -0.021179199, -0.151596069, -0.271591187, -1.063217163, 979 | 0.866363525, 0.050354004, 0.133590698, -0.014801025, 980 | 0.018463135, -0.003173828, 0.001113892, 0.000045776, 981 | -0.000152588, -0.002243042, -0.000030518, -0.029281616, 982 | -0.025817871, -0.150497437, -0.297210693, -1.077117920, 983 | 0.841949463, 0.032379150, 0.129562378, -0.017257690, 984 | 0.017349243, -0.003280640, 0.001037598, 0.000030518, 985 | -0.000167847, -0.002349854, -0.000549316, -0.029937744, 986 | -0.030609131, -0.148773193, -0.323318481, -1.089782715, 987 | 0.816864014, 0.015228271, 0.125259399, -0.019531250, 988 | 0.016235352, -0.003372192, 0.000961304, 0.000030518, 989 | -0.000198364, -0.002456665, -0.001098633, -0.030532837, 990 | -0.035552979, -0.146362305, -0.349868774, -1.101211548, 991 | 0.791213989, -0.001068115, 0.120697021, -0.021575928, 992 | 0.015121460, -0.003417969, 0.000885010, 0.000030518, 993 | -0.000213623, -0.002578735, -0.001693726, -0.031005859, 994 | -0.040634155, -0.143264771, -0.376800537, -1.111373901, 995 | 0.765029907, -0.016510010, 0.115921021, -0.023422241, 996 | 0.014022827, -0.003463745, 0.000808716, 0.000030518, 997 | -0.000244141, -0.002685547, -0.002334595, -0.031387329, 998 | -0.045837402, -0.139450073, -0.404083252, -1.120223999, 999 | 0.738372803, -0.031082153, 0.110946655, -0.025085449, 1000 | 0.012939453, -0.003479004, 0.000747681, 0.000015259, 1001 | -0.000259399, -0.002792358, -0.003005981, -0.031661987, 1002 | -0.051132202, -0.134887695, -0.431655884, -1.127746582, 1003 | 0.711318970, -0.044784546, 0.105819702, -0.026535034, 1004 | 0.011886597, -0.003479004, 0.000686646, 0.000015259, 1005 | -0.000289917, -0.002899170, -0.003723145, -0.031814575, 1006 | -0.056533813, -0.129577637, -0.459472656, -1.133926392, 1007 | 0.683914185, -0.057617188, 0.100540161, -0.027801514, 1008 | 0.010848999, -0.003463745, 0.000625610, 0.000015259, 1009 | -0.000320435, -0.002990723, -0.004486084, -0.031845093, 1010 | -0.061996460, -0.123474121, -0.487472534, -1.138763428, 1011 | 0.656219482, -0.069595337, 0.095169067, -0.028884888, 1012 | 0.009841919, -0.003433228, 0.000579834, 0.000015259, 1013 | -0.000366211, -0.003082275, -0.005294800, -0.031738281, 1014 | -0.067520142, -0.116577148, -0.515609741, -1.142211914, 1015 | 0.628295898, -0.080688477, 0.089706421, -0.029785156, 1016 | 0.008865356, -0.003387451, 0.000534058, 0.000015259, 1017 | -0.000396729, -0.003173828, -0.006118774, -0.031478882, 1018 | -0.073059082, -0.108856201, -0.543823242, -1.144287109, 1019 | 0.600219727, -0.090927124, 0.084182739, -0.030517578, 1020 | 0.007919312, -0.003326416, 0.000473022, 0.000015259 1021 | ]); 1022 | 1023 | protected static var d16:Vector.> = dSplit(); 1024 | protected static function dSplit():Vector.> { 1025 | var dRes:Vector.> = new Vector.>(32, true); 1026 | var dTmp:Vector.; 1027 | var i:int, j:int; 1028 | for (i = 0; i < 32; i++) { 1029 | var start:uint = i << 4; 1030 | dRes[i] = Vector.([ 1031 | d[start + 0], 1032 | d[start + 1], 1033 | d[start + 2], 1034 | d[start + 3], 1035 | d[start + 4], 1036 | d[start + 5], 1037 | d[start + 6], 1038 | d[start + 7], 1039 | d[start + 8], 1040 | d[start + 9], 1041 | d[start + 10], 1042 | d[start + 11], 1043 | d[start + 12], 1044 | d[start + 13], 1045 | d[start + 14], 1046 | d[start + 15] 1047 | ]); 1048 | } 1049 | return dRes; 1050 | } 1051 | } 1052 | } 1053 | -------------------------------------------------------------------------------- /source/com/codeazur/as3icy/decoder/LayerIIIDecoder.as: -------------------------------------------------------------------------------- 1 | package com.codeazur.as3icy.decoder 2 | { 3 | import com.codeazur.as3icy.data.MPEGFrame; 4 | import com.codeazur.as3icy.decoder.etc.VectorInt2D; 5 | import com.codeazur.as3icy.decoder.etc.VectorNumber2D; 6 | import com.codeazur.as3icy.decoder.etc.VectorNumber3D; 7 | import com.codeazur.utils.BitArray; 8 | 9 | import flash.utils.ByteArray; 10 | import flash.utils.getTimer; 11 | 12 | public class LayerIIIDecoder implements IFrameDecoder 13 | { 14 | protected var __c:uint = 0; 15 | 16 | protected static const SBLIMIT:uint = 32; 17 | protected static const SSLIMIT:uint = 18; 18 | 19 | public var scalefac_buffer:Vector.; 20 | public var sftable:SFTable; 21 | 22 | protected var output:OutputBuffer; 23 | 24 | protected var checkSumHuff:int = 0; 25 | protected var is_1d:Vector.; 26 | protected var ro:Vector.>>; 27 | protected var lr:Vector.>>; 28 | protected var out_1d:Vector.; 29 | protected var prevblck:Vector.>; 30 | protected var k:Vector.>; 31 | protected var nonzero:Vector.; 32 | 33 | protected var br:BitReserve; 34 | protected var si:LayerIIISideInfo; 35 | 36 | protected var scalefac:Vector.; 37 | 38 | protected var max_gr:int; 39 | protected var frame_start:int; 40 | protected var part2_start:int; 41 | protected var channels:int; 42 | protected var first_channel:int; 43 | protected var last_channel:int; 44 | protected var sfreq:int; 45 | 46 | protected var sfBandIndex:Vector.; 47 | protected var sfBandIndexCurrent:SBI; 48 | protected var reorder_table:Vector.>; 49 | 50 | protected var initialized:Boolean = false; 51 | 52 | protected var currentFrame:MPEGFrame; 53 | protected var currentFrameData:BitArray; 54 | protected var filter1:SynthesisFilter; 55 | protected var filter2:SynthesisFilter; 56 | 57 | protected var new_slen:Vector.; 58 | protected var is_pos:Vector.; 59 | protected var is_ratio:Vector.; 60 | protected var tsOutCopy:Vector.; 61 | protected var rawout:Vector.; 62 | protected var samples1:Vector.; 63 | protected var samples2:Vector.; 64 | protected var huffRes:HuffResult; 65 | 66 | 67 | public function LayerIIIDecoder(outputBuffer:OutputBuffer) 68 | { 69 | output = outputBuffer; 70 | new_slen = new Vector.(4, true); 71 | is_pos = new Vector.(576, true); 72 | is_ratio = new Vector.(576, true); 73 | tsOutCopy = new Vector.(18, true); 74 | rawout = new Vector.(36, true); 75 | samples1 = new Vector.(32, true); 76 | samples2 = new Vector.(32, true); 77 | huffRes = new HuffResult(); 78 | filter1 = new SynthesisFilter(0); 79 | filter2 = new SynthesisFilter(1); 80 | } 81 | 82 | 83 | public function decodeFrame(frame:MPEGFrame):void 84 | { 85 | currentFrame = frame; 86 | currentFrameData = frame.data; 87 | 88 | if (!initialized) { 89 | initialize(); 90 | } 91 | 92 | var t:int = getTimer(); 93 | 94 | var nSlots:uint = frame.slots; 95 | var flush_main:int; 96 | var gr:int; 97 | var ch:int; 98 | var ss:int; 99 | var sb:int; 100 | var sb18:int; 101 | var main_data_end:int; 102 | var bytes_to_discard:int; 103 | var i:int; 104 | 105 | get_side_info(); 106 | 107 | for (i = 0; i < nSlots; i++) { 108 | br.hputbuf(currentFrameData.readBits(8)); 109 | } 110 | main_data_end = br.hsstell >>> 3; // of previous frame 111 | if ((flush_main = (br.hsstell & 7)) != 0) { 112 | br.hgetbits(8 - flush_main); 113 | main_data_end++; 114 | } 115 | bytes_to_discard = frame_start - main_data_end - si.main_data_begin; 116 | frame_start += nSlots; 117 | if (bytes_to_discard < 0) { 118 | return; 119 | } 120 | if (main_data_end > 4096) { 121 | frame_start -= 4096; 122 | br.rewindNbytes(4096); 123 | } 124 | for (; bytes_to_discard > 0; bytes_to_discard--) { 125 | br.hgetbits(8); 126 | } 127 | for (gr = 0; gr < max_gr; gr++) 128 | { 129 | for (ch = 0; ch < channels; ch++) { 130 | part2_start = br.hsstell; 131 | if (frame.version == MPEGFrame.MPEG_VERSION_1_0) { 132 | get_scale_factors(ch, gr); 133 | } else { 134 | get_lsf_scale_factors(ch, gr); 135 | } 136 | huffman_decode(ch, gr); 137 | dequantize_sample(ro[ch], ch, gr); 138 | } 139 | stereo(gr); 140 | //if ((which_channels == OutputChannels.DOWNMIX_CHANNELS) && (channels > 1)) { 141 | // do_downmix(); 142 | //} 143 | for (ch = first_channel; ch <= last_channel; ch++) 144 | { 145 | reorder(lr[ch], ch, gr); 146 | antialias(ch, gr); 147 | hybrid(ch, gr); 148 | for (sb18 = 18; sb18 < 576; sb18 += 36) { 149 | // Frequency inversion 150 | for (ss = 1; ss < SSLIMIT; ss += 2) { 151 | out_1d[sb18 + ss] = -out_1d[sb18 + ss]; 152 | } 153 | } 154 | if (ch == 0) { 155 | for (ss = 0; ss < SSLIMIT; ss++) { 156 | // Polyphase synthesis 157 | sb = 0; 158 | for (sb18 = 0; sb18 < 576; sb18 += 18) { 159 | samples1[sb++] = out_1d[sb18 + ss]; 160 | } 161 | filter1.input_samples(samples1); 162 | filter1.calculate_pcm_samples(output); 163 | } 164 | } else { 165 | for (ss = 0; ss < SSLIMIT; ss++) { 166 | // Polyphase synthesis 167 | sb = 0; 168 | for (sb18 = 0; sb18 < 576; sb18 += 18) { 169 | samples2[sb++] = out_1d[sb18 + ss]; 170 | } 171 | filter2.input_samples(samples2); 172 | filter2.calculate_pcm_samples(output); 173 | } 174 | } 175 | } 176 | } 177 | //trace((getTimer() - t) + "ms"); 178 | } 179 | 180 | protected function get_side_info():Boolean 181 | { 182 | var ch:int; 183 | var gr:int; 184 | var gr_info:GRInfo; 185 | if (currentFrame.version == MPEGFrame.MPEG_VERSION_1_0) { 186 | si.main_data_begin = currentFrameData.readBits(9); 187 | if (channels == 1) { 188 | si.private_bits = currentFrameData.readBits(5); 189 | } else { 190 | si.private_bits = currentFrameData.readBits(3); 191 | } 192 | for (ch = 0; ch < channels; ch++) { 193 | si.ch[ch].scfsi[0] = currentFrameData.readBits(1); 194 | si.ch[ch].scfsi[1] = currentFrameData.readBits(1); 195 | si.ch[ch].scfsi[2] = currentFrameData.readBits(1); 196 | si.ch[ch].scfsi[3] = currentFrameData.readBits(1); 197 | } 198 | for (gr = 0; gr < 2; gr++) { 199 | for (ch = 0; ch < channels; ch++) { 200 | gr_info = si.ch[ch].gr[gr]; 201 | gr_info.part2_3_length = currentFrameData.readBits(12); 202 | gr_info.big_values = currentFrameData.readBits(9); 203 | gr_info.global_gain = currentFrameData.readBits(8); 204 | gr_info.scalefac_compress = currentFrameData.readBits(4); 205 | gr_info.window_switching_flag = currentFrameData.readBits(1); 206 | if ((gr_info.window_switching_flag) != 0) { 207 | gr_info.block_type = currentFrameData.readBits(2); 208 | gr_info.mixed_block_flag = currentFrameData.readBits(1); 209 | gr_info.table_select[0] = currentFrameData.readBits(5); 210 | gr_info.table_select[1] = currentFrameData.readBits(5); 211 | gr_info.subblock_gain[0] = currentFrameData.readBits(3); 212 | gr_info.subblock_gain[1] = currentFrameData.readBits(3); 213 | gr_info.subblock_gain[2] = currentFrameData.readBits(3); 214 | // Set region_count parameters since they are implicit in this case. 215 | if (gr_info.block_type == 0) { 216 | // Side info bad: block_type == 0 in split block 217 | return false; 218 | } else if (gr_info.block_type == 2 && gr_info.mixed_block_flag == 0) { 219 | gr_info.region0_count = 8; 220 | } else { 221 | gr_info.region0_count = 7; 222 | } 223 | gr_info.region1_count = 20 - gr_info.region0_count; 224 | } else { 225 | gr_info.table_select[0] = currentFrameData.readBits(5); 226 | gr_info.table_select[1] = currentFrameData.readBits(5); 227 | gr_info.table_select[2] = currentFrameData.readBits(5); 228 | gr_info.region0_count = currentFrameData.readBits(4); 229 | gr_info.region1_count = currentFrameData.readBits(3); 230 | gr_info.block_type = 0; 231 | } 232 | gr_info.preflag = currentFrameData.readBits(1); 233 | gr_info.scalefac_scale = currentFrameData.readBits(1); 234 | gr_info.count1table_select = currentFrameData.readBits(1); 235 | } 236 | } 237 | } else { 238 | // MPEG-2 LSF, MPEG-2.5 LSF 239 | si.main_data_begin = currentFrameData.readBits(8); 240 | if (channels == 1) { 241 | si.private_bits = currentFrameData.readBits(1); 242 | } else { 243 | si.private_bits = currentFrameData.readBits(2); 244 | } 245 | for (ch = 0; ch < channels; ch++) { 246 | gr_info = si.ch[ch].gr[0]; 247 | gr_info.part2_3_length = currentFrameData.readBits(12); 248 | gr_info.big_values = currentFrameData.readBits(9); 249 | gr_info.global_gain = currentFrameData.readBits(8); 250 | gr_info.scalefac_compress = currentFrameData.readBits(9); 251 | gr_info.window_switching_flag = currentFrameData.readBits(1); 252 | if ((gr_info.window_switching_flag) != 0) { 253 | gr_info.block_type = currentFrameData.readBits(2); 254 | gr_info.mixed_block_flag = currentFrameData.readBits(1); 255 | gr_info.table_select[0] = currentFrameData.readBits(5); 256 | gr_info.table_select[1] = currentFrameData.readBits(5); 257 | gr_info.subblock_gain[0] = currentFrameData.readBits(3); 258 | gr_info.subblock_gain[1] = currentFrameData.readBits(3); 259 | gr_info.subblock_gain[2] = currentFrameData.readBits(3); 260 | // Set region_count parameters since they are implicit in this case. 261 | if (gr_info.block_type == 0) { 262 | // Side info bad: block_type == 0 in split block 263 | return false; 264 | } else if (gr_info.block_type == 2 && gr_info.mixed_block_flag == 0) { 265 | gr_info.region0_count = 8; 266 | } else { 267 | gr_info.region0_count = 7; 268 | gr_info.region1_count = 20 - gr_info.region0_count; 269 | } 270 | } else { 271 | gr_info.table_select[0] = currentFrameData.readBits(5); 272 | gr_info.table_select[1] = currentFrameData.readBits(5); 273 | gr_info.table_select[2] = currentFrameData.readBits(5); 274 | gr_info.region0_count = currentFrameData.readBits(4); 275 | gr_info.region1_count = currentFrameData.readBits(3); 276 | gr_info.block_type = 0; 277 | } 278 | gr_info.scalefac_scale = currentFrameData.readBits(1); 279 | gr_info.count1table_select = currentFrameData.readBits(1); 280 | } 281 | } 282 | return true; 283 | } 284 | 285 | protected function get_scale_factors(ch:int, gr:int):void 286 | { 287 | var sfb:uint; 288 | var window:uint; 289 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 290 | var s:Vector.> = scalefac[ch].s; 291 | var scale_comp:int = gr_info.scalefac_compress; 292 | var length0:int = slen[0][scale_comp]; 293 | var length1:int = slen[1][scale_comp]; 294 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) { 295 | if ((gr_info.mixed_block_flag) != 0) { 296 | // MIXED 297 | for (sfb = 0; sfb < 8; sfb++) { 298 | scalefac[ch].l[sfb] = br.hgetbits(slen[0][gr_info.scalefac_compress]); 299 | } 300 | for (sfb = 3; sfb < 6; sfb++) { 301 | for (window = 0; window < 3; window++) { 302 | s[window][sfb] = br.hgetbits(slen[0][gr_info.scalefac_compress]); 303 | } 304 | } 305 | for (sfb = 6; sfb < 12; sfb++) { 306 | for (window=0; window<3; window++) { 307 | s[window][sfb] = br.hgetbits(slen[1][gr_info.scalefac_compress]); 308 | } 309 | } 310 | for (sfb = 12, window = 0; window < 3; window++) { 311 | s[window][sfb] = 0; 312 | } 313 | } else { 314 | // SHORT 315 | s[0][0] = br.hgetbits(length0); 316 | s[1][0] = br.hgetbits(length0); 317 | s[2][0] = br.hgetbits(length0); 318 | s[0][1] = br.hgetbits(length0); 319 | s[1][1] = br.hgetbits(length0); 320 | s[2][1] = br.hgetbits(length0); 321 | s[0][2] = br.hgetbits(length0); 322 | s[1][2] = br.hgetbits(length0); 323 | s[2][2] = br.hgetbits(length0); 324 | s[0][3] = br.hgetbits(length0); 325 | s[1][3] = br.hgetbits(length0); 326 | s[2][3] = br.hgetbits(length0); 327 | s[0][4] = br.hgetbits(length0); 328 | s[1][4] = br.hgetbits(length0); 329 | s[2][4] = br.hgetbits(length0); 330 | s[0][5] = br.hgetbits(length0); 331 | s[1][5] = br.hgetbits(length0); 332 | s[2][5] = br.hgetbits(length0); 333 | s[0][6] = br.hgetbits(length1); 334 | s[1][6] = br.hgetbits(length1); 335 | s[2][6] = br.hgetbits(length1); 336 | s[0][7] = br.hgetbits(length1); 337 | s[1][7] = br.hgetbits(length1); 338 | s[2][7] = br.hgetbits(length1); 339 | s[0][8] = br.hgetbits(length1); 340 | s[1][8] = br.hgetbits(length1); 341 | s[2][8] = br.hgetbits(length1); 342 | s[0][9] = br.hgetbits(length1); 343 | s[1][9] = br.hgetbits(length1); 344 | s[2][9] = br.hgetbits(length1); 345 | s[0][10] = br.hgetbits(length1); 346 | s[1][10] = br.hgetbits(length1); 347 | s[2][10] = br.hgetbits(length1); 348 | s[0][11] = br.hgetbits(length1); 349 | s[1][11] = br.hgetbits(length1); 350 | s[2][11] = br.hgetbits(length1); 351 | s[0][12] = 0; 352 | s[1][12] = 0; 353 | s[2][12] = 0; 354 | } 355 | } else { 356 | // LONG types 0,1,3 357 | if ((si.ch[ch].scfsi[0] == 0) || (gr == 0)) { 358 | scalefac[ch].l[0] = br.hgetbits(length0); 359 | scalefac[ch].l[1] = br.hgetbits(length0); 360 | scalefac[ch].l[2] = br.hgetbits(length0); 361 | scalefac[ch].l[3] = br.hgetbits(length0); 362 | scalefac[ch].l[4] = br.hgetbits(length0); 363 | scalefac[ch].l[5] = br.hgetbits(length0); 364 | } 365 | if ((si.ch[ch].scfsi[1] == 0) || (gr == 0)) { 366 | scalefac[ch].l[6] = br.hgetbits(length0); 367 | scalefac[ch].l[7] = br.hgetbits(length0); 368 | scalefac[ch].l[8] = br.hgetbits(length0); 369 | scalefac[ch].l[9] = br.hgetbits(length0); 370 | scalefac[ch].l[10] = br.hgetbits(length0); 371 | } 372 | if ((si.ch[ch].scfsi[2] == 0) || (gr == 0)) { 373 | scalefac[ch].l[11] = br.hgetbits(length1); 374 | scalefac[ch].l[12] = br.hgetbits(length1); 375 | scalefac[ch].l[13] = br.hgetbits(length1); 376 | scalefac[ch].l[14] = br.hgetbits(length1); 377 | scalefac[ch].l[15] = br.hgetbits(length1); 378 | } 379 | if ((si.ch[ch].scfsi[3] == 0) || (gr == 0)) { 380 | scalefac[ch].l[16] = br.hgetbits(length1); 381 | scalefac[ch].l[17] = br.hgetbits(length1); 382 | scalefac[ch].l[18] = br.hgetbits(length1); 383 | scalefac[ch].l[19] = br.hgetbits(length1); 384 | scalefac[ch].l[20] = br.hgetbits(length1); 385 | } 386 | scalefac[ch].l[21] = 0; 387 | scalefac[ch].l[22] = 0; 388 | } 389 | } 390 | 391 | protected function get_lsf_scale_data(ch:int, gr:int):void 392 | { 393 | var scalefac_comp:int; 394 | var int_scalefac_comp:int; 395 | var mode_ext:int = currentFrame.channelModeExt; 396 | var m:int; 397 | var blocktypenumber:int; 398 | var blocknumber:int = 0; 399 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 400 | scalefac_comp = gr_info.scalefac_compress; 401 | if (gr_info.block_type == 2) { 402 | if (gr_info.mixed_block_flag == 0) { 403 | blocktypenumber = 1; 404 | } else if (gr_info.mixed_block_flag == 1) { 405 | blocktypenumber = 2; 406 | } else { 407 | blocktypenumber = 0; 408 | } 409 | } else { 410 | blocktypenumber = 0; 411 | } 412 | if (!(((mode_ext == 1) || (mode_ext == 3)) && (ch == 1))) { 413 | if (scalefac_comp < 400) { 414 | new_slen[0] = (scalefac_comp >>> 4) / 5; 415 | new_slen[1] = (scalefac_comp >>> 4) % 5; 416 | new_slen[2] = (scalefac_comp & 0xF) >>> 2; 417 | new_slen[3] = (scalefac_comp & 3); 418 | si.ch[ch].gr[gr].preflag = 0; 419 | blocknumber = 0; 420 | } else if (scalefac_comp < 500) { 421 | new_slen[0] = ((scalefac_comp - 400) >>> 2) / 5; 422 | new_slen[1] = ((scalefac_comp - 400) >>> 2) % 5; 423 | new_slen[2] = (scalefac_comp - 400 ) & 3; 424 | new_slen[3] = 0; 425 | si.ch[ch].gr[gr].preflag = 0; 426 | blocknumber = 1; 427 | } else if (scalefac_comp < 512) { 428 | new_slen[0] = (scalefac_comp - 500 ) / 3; 429 | new_slen[1] = (scalefac_comp - 500) % 3; 430 | new_slen[2] = 0; 431 | new_slen[3] = 0; 432 | si.ch[ch].gr[gr].preflag = 1; 433 | blocknumber = 2; 434 | } 435 | } 436 | if ((((mode_ext == 1) || (mode_ext == 3)) && (ch == 1))) { 437 | int_scalefac_comp = scalefac_comp >>> 1; 438 | if (int_scalefac_comp < 180) { 439 | new_slen[0] = int_scalefac_comp / 36; 440 | new_slen[1] = (int_scalefac_comp % 36 ) / 6; 441 | new_slen[2] = (int_scalefac_comp % 36) % 6; 442 | new_slen[3] = 0; 443 | si.ch[ch].gr[gr].preflag = 0; 444 | blocknumber = 3; 445 | } else if (int_scalefac_comp < 244) { 446 | new_slen[0] = ((int_scalefac_comp - 180 ) & 0x3F) >>> 4; 447 | new_slen[1] = ((int_scalefac_comp - 180) & 0xF) >>> 2; 448 | new_slen[2] = (int_scalefac_comp - 180 ) & 3; 449 | new_slen[3] = 0; 450 | si.ch[ch].gr[gr].preflag = 0; 451 | blocknumber = 4; 452 | } else if (int_scalefac_comp < 255) { 453 | new_slen[0] = (int_scalefac_comp - 244 ) / 3; 454 | new_slen[1] = (int_scalefac_comp - 244 ) % 3; 455 | new_slen[2] = 0; 456 | new_slen[3] = 0; 457 | si.ch[ch].gr[gr].preflag = 0; 458 | blocknumber = 5; 459 | } 460 | } 461 | for (var x:int = 0; x < 45; x++) { 462 | // why 45, not 54? 463 | scalefac_buffer[x] = 0; 464 | } 465 | m = 0; 466 | for (var i:int = 0; i < 4; i++) { 467 | for (var j:int = 0; j < nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++) { 468 | scalefac_buffer[m++] = (new_slen[i] == 0) ? 0 : br.hgetbits(new_slen[i]); 469 | } 470 | } 471 | } 472 | 473 | protected function get_lsf_scale_factors(ch:int, gr:int):void 474 | { 475 | var m:int = 0; 476 | var sfb:int; 477 | var window:int; 478 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 479 | get_lsf_scale_data(ch, gr); 480 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) { 481 | if (gr_info.mixed_block_flag != 0) { 482 | // MIXED 483 | for (sfb = 0; sfb < 8; sfb++) { 484 | scalefac[ch].l[sfb] = scalefac_buffer[m++]; 485 | } 486 | for (sfb = 3; sfb < 12; sfb++) { 487 | for (window = 0; window < 3; window++) { 488 | scalefac[ch].s[window][sfb] = scalefac_buffer[m++]; 489 | } 490 | } 491 | for (window = 0; window < 3; window++) { 492 | scalefac[ch].s[window][12] = 0; 493 | } 494 | } else { 495 | // SHORT 496 | for (sfb = 0; sfb < 12; sfb++) { 497 | for (window = 0; window < 3; window++) { 498 | scalefac[ch].s[window][sfb] = scalefac_buffer[m++]; 499 | } 500 | } 501 | for (window = 0; window < 3; window++) { 502 | scalefac[ch].s[window][12] = 0; 503 | } 504 | } 505 | } else { 506 | // LONG types 0,1,3 507 | for (sfb = 0; sfb < 21; sfb++) { 508 | scalefac[ch].l[sfb] = scalefac_buffer[m++]; 509 | } 510 | scalefac[ch].l[21] = 0; // Jeff 511 | scalefac[ch].l[22] = 0; 512 | } 513 | } 514 | 515 | protected function huffman_decode(ch:int, gr:int):void 516 | { 517 | var part2_3_end:int = part2_start + si.ch[ch].gr[gr].part2_3_length; 518 | var num_bits:int; 519 | var region1Start:int; 520 | var region2Start:int; 521 | var index:int; 522 | var buf:int; 523 | var buf1:int; 524 | var h:HuffCodeTab; 525 | 526 | huffRes.reset(); 527 | 528 | // Find region boundary for short block case 529 | if (((si.ch[ch].gr[gr].window_switching_flag) != 0) && (si.ch[ch].gr[gr].block_type == 2)) { 530 | // Region2. 531 | // MS: Extrahandling for 8KHZ 532 | region1Start = (sfreq == 8) ? 72 : 36; // sfb[9 / 3] * 3 = 36 or in case 8KHZ = 72 533 | region2Start = 576; // No Region2 for short block case 534 | } else { 535 | // Find region boundary for long block case 536 | buf = si.ch[ch].gr[gr].region0_count + 1; 537 | buf1 = buf + si.ch[ch].gr[gr].region1_count + 1; 538 | if (buf1 > sfBandIndexCurrent.l.length - 1) { 539 | buf1 = sfBandIndexCurrent.l.length - 1; 540 | } 541 | region1Start = sfBandIndexCurrent.l[buf]; 542 | region2Start = sfBandIndexCurrent.l[buf1]; /* MI */ 543 | } 544 | 545 | index = 0; 546 | 547 | // Read bigvalues area 548 | var num:int = Math.min((si.ch[ch].gr[gr].big_values << 1), is_1d.length); 549 | for (var i:int = 0; i < num; i += 2) { 550 | if (i < region1Start) { 551 | h = HuffCodeTab.ht[si.ch[ch].gr[gr].table_select[0]]; 552 | } else if (i < region2Start) { 553 | h = HuffCodeTab.ht[si.ch[ch].gr[gr].table_select[1]]; 554 | } else { 555 | h = HuffCodeTab.ht[si.ch[ch].gr[gr].table_select[2]]; 556 | } 557 | HuffCodeTab.huffman_decoder(h, huffRes, br); 558 | is_1d[index++] = huffRes.x; 559 | is_1d[index++] = huffRes.y; 560 | checkSumHuff = checkSumHuff + huffRes.x + huffRes.y; 561 | } 562 | 563 | // Read count1 area 564 | h = HuffCodeTab.ht[si.ch[ch].gr[gr].count1table_select + 32]; 565 | num_bits = br.hsstell; 566 | while ((num_bits < part2_3_end) && (index < 576)) { 567 | HuffCodeTab.huffman_decoder(h, huffRes, br); 568 | is_1d[index++] = huffRes.v; 569 | is_1d[index++] = huffRes.w; 570 | is_1d[index++] = huffRes.x; 571 | is_1d[index++] = huffRes.y; 572 | checkSumHuff = checkSumHuff + huffRes.v + huffRes.w + huffRes.x + huffRes.y; 573 | num_bits = br.hsstell; 574 | } 575 | if (num_bits > part2_3_end) { 576 | br.rewindNbits(num_bits - part2_3_end); 577 | index -= 4; 578 | } 579 | num_bits = br.hsstell; 580 | 581 | // Dismiss stuffing bits 582 | if (num_bits < part2_3_end) { 583 | br.hgetbits(part2_3_end - num_bits); 584 | } 585 | 586 | // Zero out rest 587 | nonzero[ch] = (index < 576) ? index : 576; 588 | if (index < 0) { 589 | index = 0; 590 | } 591 | 592 | // may not be necessary 593 | for (; index < 576; index++) { 594 | is_1d[index] = 0; 595 | } 596 | } 597 | 598 | protected function i_stereo_k_values(is_pos:int, io_type:int, i:int):void 599 | { 600 | if (is_pos == 0) { 601 | k[0][i] = 1.0; 602 | k[1][i] = 1.0; 603 | } else if ((is_pos & 1) != 0) { 604 | k[0][i] = io[io_type][(is_pos + 1) >>> 1]; 605 | k[1][i] = 1.0; 606 | } else { 607 | k[0][i] = 1.0; 608 | k[1][i] = io[io_type][is_pos >>> 1]; 609 | } 610 | } 611 | 612 | protected function dequantize_sample(xr:Vector.>, ch:int, gr:int):void 613 | { 614 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 615 | var cb:int = 0; 616 | var next_cb_boundary:int; 617 | var cb_begin:int = 0; 618 | var cb_width:int = 0; 619 | var index:int = 0; 620 | var t_index:int; 621 | var j:int; 622 | var g_gain:Number; 623 | var xr_1d:Vector.> = xr; 624 | 625 | var reste:int; 626 | var quotien:int; 627 | var idx:int; 628 | 629 | // Choose correct scalefactor band per block type, initalize boundary 630 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) { 631 | if (gr_info.mixed_block_flag != 0) { 632 | next_cb_boundary = sfBandIndexCurrent.l[1]; // LONG blocks: 0,1,3 633 | } else { 634 | cb_width = sfBandIndexCurrent.s[1]; 635 | next_cb_boundary = (cb_width << 2) - cb_width; 636 | cb_begin = 0; 637 | } 638 | } else { 639 | next_cb_boundary = sfBandIndexCurrent.l[1]; // LONG blocks: 0,1,3 640 | } 641 | 642 | // Compute overall (global) scaling. 643 | g_gain = Math.pow(2.0, (0.25 * (gr_info.global_gain - 210.0))); 644 | for (j = 0; j < nonzero[ch]; j++) { 645 | reste = j % SSLIMIT; 646 | quotien = int((j - reste) / SSLIMIT); 647 | if (is_1d[j] == 0) { 648 | xr_1d[quotien][reste] = 0.0; 649 | } else { 650 | var abv:int = is_1d[j]; 651 | // Pow Array fix (11/17/04) 652 | if (abv < t_43.length) { 653 | if (is_1d[j] > 0) { 654 | xr_1d[quotien][reste] = g_gain * t_43[abv]; 655 | } else { 656 | if (-abv < t_43.length) { 657 | xr_1d[quotien][reste] = -g_gain * t_43[-abv]; 658 | } else { 659 | xr_1d[quotien][reste] = -g_gain * Math.pow(-abv, d43); 660 | } 661 | } 662 | } else { 663 | if (is_1d[j] > 0) { 664 | xr_1d[quotien][reste] = g_gain * Math.pow(abv, d43); 665 | } else { 666 | xr_1d[quotien][reste] = -g_gain * Math.pow(-abv, d43); 667 | } 668 | } 669 | } 670 | } 671 | 672 | // Apply formula per block type 673 | for (j = 0; j < nonzero[ch]; j++) { 674 | reste = j % SSLIMIT; 675 | quotien = int((j - reste) / SSLIMIT); 676 | if (index == next_cb_boundary) { /* Adjust critical band boundary */ 677 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) { 678 | if (gr_info.mixed_block_flag != 0) { 679 | if (index == sfBandIndexCurrent.l[8]) { 680 | next_cb_boundary = sfBandIndexCurrent.s[4]; 681 | next_cb_boundary = (next_cb_boundary << 2) - 682 | next_cb_boundary; 683 | cb = 3; 684 | cb_width = sfBandIndexCurrent.s[4] - sfBandIndexCurrent.s[3]; 685 | cb_begin = sfBandIndexCurrent.s[3]; 686 | cb_begin = (cb_begin << 2) - cb_begin; 687 | } else if (index < sfBandIndexCurrent.l[8]) { 688 | next_cb_boundary = sfBandIndexCurrent.l[(++cb) + 1]; 689 | } else { 690 | next_cb_boundary = sfBandIndexCurrent.s[(++cb) + 1]; 691 | next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary; 692 | cb_begin = sfBandIndexCurrent.s[cb]; 693 | cb_width = sfBandIndexCurrent.s[cb + 1] - cb_begin; 694 | cb_begin = (cb_begin << 2) - cb_begin; 695 | } 696 | } else { 697 | next_cb_boundary = sfBandIndexCurrent.s[(++cb) + 1]; 698 | next_cb_boundary = (next_cb_boundary << 2) - next_cb_boundary; 699 | cb_begin = sfBandIndexCurrent.s[cb]; 700 | cb_width = sfBandIndexCurrent.s[cb + 1] - cb_begin; 701 | cb_begin = (cb_begin << 2) - cb_begin; 702 | } 703 | } else { // long blocks 704 | next_cb_boundary = sfBandIndexCurrent.l[(++cb) + 1]; 705 | } 706 | } 707 | 708 | // Do long/short dependent scaling operations 709 | if ((gr_info.window_switching_flag != 0) && 710 | (((gr_info.block_type == 2) && (gr_info.mixed_block_flag == 0)) || 711 | ((gr_info.block_type == 2) && (gr_info.mixed_block_flag != 0) && (j >= 36)))) 712 | { 713 | t_index = (index - cb_begin) / cb_width; 714 | idx = scalefac[ch].s[t_index][cb] << gr_info.scalefac_scale; 715 | idx += (gr_info.subblock_gain[t_index] << 2); 716 | xr_1d[quotien][reste] *= two_to_negative_half_pow[idx]; 717 | } else { 718 | // LONG block types 0,1,3 & 1st 2 subbands of switched blocks 719 | idx = scalefac[ch].l[cb]; 720 | if (gr_info.preflag != 0) { 721 | idx += pretab[cb]; 722 | } 723 | idx = (idx << gr_info.scalefac_scale); 724 | xr_1d[quotien][reste] *= two_to_negative_half_pow[idx]; 725 | } 726 | index++; 727 | } 728 | 729 | for (j = nonzero[ch]; j < 576; j++) { 730 | reste = j % SSLIMIT; 731 | quotien = int((j - reste) / SSLIMIT); 732 | if (reste < 0) { reste = 0; } 733 | if(quotien < 0) { quotien = 0; } 734 | xr_1d[quotien][reste] = 0.0; 735 | } 736 | } 737 | 738 | protected function reorder(xr:Vector.>, ch:int, gr:int):void 739 | { 740 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 741 | var freq:int; 742 | var freq3:int; 743 | var index:int; 744 | var sfb:int; 745 | var sfb_start:int; 746 | var sfb_lines:int; 747 | var src_line:int; 748 | var des_line:int; 749 | var reste:int; 750 | var quotien:int; 751 | var xr_1d:Vector.> = xr; 752 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) { 753 | for (index = 0; index < 576; index++) { 754 | out_1d[index] = 0.0; 755 | } 756 | if (gr_info.mixed_block_flag != 0) { 757 | // NO REORDER FOR LOW 2 SUBBANDS 758 | for (index = 0; index < 36; index++) { 759 | reste = index % SSLIMIT; 760 | quotien = int((index - reste) / SSLIMIT); 761 | out_1d[index] = xr_1d[quotien][reste]; 762 | } 763 | // REORDERING FOR REST SWITCHED SHORT 764 | for (sfb = 3; sfb < 13; sfb++) { 765 | sfb_start = sfBandIndexCurrent.s[sfb]; 766 | sfb_lines = sfBandIndexCurrent.s[sfb + 1] - sfb_start; 767 | var sfb_start3:int = (sfb_start << 2) - sfb_start; 768 | for (freq = 0, freq3 = 0; freq < sfb_lines; freq++, freq3 += 3) { 769 | src_line = sfb_start3 + freq; 770 | des_line = sfb_start3 + freq3; 771 | reste = src_line % SSLIMIT; 772 | quotien = int((src_line - reste) / SSLIMIT); 773 | out_1d[des_line] = xr_1d[quotien][reste]; 774 | src_line += sfb_lines; 775 | des_line++; 776 | reste = src_line % SSLIMIT; 777 | quotien = int((src_line - reste) / SSLIMIT); 778 | out_1d[des_line] = xr_1d[quotien][reste]; 779 | src_line += sfb_lines; 780 | des_line++; 781 | reste = src_line % SSLIMIT; 782 | quotien = int((src_line - reste) / SSLIMIT); 783 | out_1d[des_line] = xr_1d[quotien][reste]; 784 | } 785 | } 786 | } else { 787 | // pure short 788 | for (index = 0; index < 576; index++) { 789 | var j:int = reorder_table[sfreq][index]; 790 | reste = j % SSLIMIT; 791 | quotien = int((j - reste) / SSLIMIT); 792 | out_1d[index] = xr_1d[quotien][reste]; 793 | } 794 | } 795 | } else { 796 | // long blocks 797 | for (index = 0; index < 576; index++) { 798 | reste = index % SSLIMIT; 799 | quotien = int((index - reste) / SSLIMIT); 800 | out_1d[index] = xr_1d[quotien][reste]; 801 | } 802 | } 803 | } 804 | 805 | protected function stereo(gr:int):void 806 | { 807 | var sb:int; 808 | var ss:int; 809 | if (channels == 1) { 810 | // mono, bypass xr[0][][] to lr[0][][] 811 | for (sb = 0; sb < SBLIMIT; sb++) { 812 | for (ss = 0; ss < SSLIMIT; ss += 3) { 813 | lr[0][sb][ss] = ro[0][sb][ss]; 814 | lr[0][sb][ss + 1] = ro[0][sb][ss + 1]; 815 | lr[0][sb][ss + 2] = ro[0][sb][ss + 2]; 816 | } 817 | } 818 | } else { 819 | var gr_info:GRInfo = si.ch[0].gr[gr]; 820 | var mode_ext:uint = currentFrame.channelModeExt; 821 | var sfb:int; 822 | var i:int; 823 | var j:uint; 824 | var sfbcnt:int; 825 | var lines:int; 826 | var temp:int; 827 | var temp2:int; 828 | var ms_stereo:Boolean = ((currentFrame.channelMode == MPEGFrame.CHANNEL_MODE_JOINT_STEREO) && ((mode_ext & 0x2) != 0)); 829 | var i_stereo:Boolean = ((currentFrame.channelMode == MPEGFrame.CHANNEL_MODE_JOINT_STEREO) && ((mode_ext & 0x1) != 0)); 830 | var lsf:Boolean = ((currentFrame.version == MPEGFrame.MPEG_VERSION_2_0) || (currentFrame.version == MPEGFrame.MPEG_VERSION_2_5)); 831 | var io_type:int = (gr_info.scalefac_compress & 1); 832 | 833 | // Initialization 834 | for (i = 0; i < 576; i++) { 835 | is_pos[i] = 7; 836 | is_ratio[i] = 0.0; 837 | } 838 | if (i_stereo) { 839 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2)) { 840 | if (gr_info.mixed_block_flag != 0) { 841 | var max_sfb:int = 0; 842 | for (j = 0; j < 3; j++) { 843 | sfbcnt = 2; 844 | for (sfb = 12; sfb >= 3; sfb--) { 845 | i = sfBandIndexCurrent.s[sfb]; 846 | lines = sfBandIndexCurrent.s[sfb + 1] - i; 847 | i = (i << 2) - i + (j + 1) * lines - 1; 848 | while (lines > 0) { 849 | if (ro[1][i / 18][i % 18] != 0.0) { 850 | sfbcnt = sfb; 851 | sfb = -10; 852 | lines = -10; 853 | } 854 | lines--; 855 | i--; 856 | } 857 | } 858 | sfb = sfbcnt + 1; 859 | if (sfb > max_sfb) { 860 | max_sfb = sfb; 861 | } 862 | while (sfb < 12) { 863 | temp = sfBandIndexCurrent.s[sfb]; 864 | sb = sfBandIndexCurrent.s[sfb + 1] - temp; 865 | i = (temp << 2) - temp + j * sb; 866 | for (; sb > 0; sb--) { 867 | is_pos[i] = scalefac[1].s[j][sfb]; 868 | if (is_pos[i] != 7) { 869 | if (lsf) { 870 | i_stereo_k_values(is_pos[i], io_type, i); 871 | } else { 872 | is_ratio[i] = TAN12[is_pos[i]]; 873 | } 874 | } 875 | i++; 876 | } 877 | sfb++; 878 | } 879 | sfb = sfBandIndexCurrent.s[10]; 880 | sb = sfBandIndexCurrent.s[11] - sfb; 881 | sfb = (sfb << 2) - sfb + j * sb; 882 | temp = sfBandIndexCurrent.s[11]; 883 | sb = sfBandIndexCurrent.s[12] - temp; 884 | i = (temp << 2) - temp + j * sb; 885 | for (; sb > 0; sb--) { 886 | is_pos[i] = is_pos[sfb]; 887 | if (lsf) { 888 | k[0][i] = k[0][sfb]; 889 | k[1][i] = k[1][sfb]; 890 | } else { 891 | is_ratio[i] = is_ratio[sfb]; 892 | } 893 | i++; 894 | } 895 | } 896 | if (max_sfb <= 3) { 897 | i = 2; 898 | ss = 17; 899 | sb = -1; 900 | while (i >= 0) { 901 | if (ro[1][i][ss] != 0.0) { 902 | sb = (i << 4) + (i << 1) + ss; 903 | i = -1; 904 | } else { 905 | ss--; 906 | if (ss < 0) { 907 | i--; 908 | ss = 17; 909 | } 910 | } 911 | } 912 | i = 0; 913 | while (sfBandIndexCurrent.l[i] <= sb) { 914 | i++; 915 | } 916 | sfb = i; 917 | i = sfBandIndexCurrent.l[i]; 918 | for (; sfb < 8; sfb++) { 919 | sb = sfBandIndexCurrent.l[sfb + 1]-sfBandIndexCurrent.l[sfb]; 920 | for (; sb > 0; sb--) { 921 | is_pos[i] = scalefac[1].l[sfb]; 922 | if (is_pos[i] != 7) { 923 | if (lsf) { 924 | i_stereo_k_values(is_pos[i], io_type, i); 925 | } else { 926 | is_ratio[i] = TAN12[is_pos[i]]; 927 | } 928 | } 929 | i++; 930 | } 931 | } 932 | } // for (j=0 ... 933 | } else { // if (gr_info.mixed_block_flag) 934 | for (j = 0; j < 3; j++) { 935 | sfbcnt = -1; 936 | for (sfb = 12; sfb >= 0; sfb--) { 937 | temp = sfBandIndexCurrent.s[sfb]; 938 | lines = sfBandIndexCurrent.s[sfb + 1] - temp; 939 | i = (temp << 2) - temp + (j+1) * lines - 1; 940 | while (lines > 0) { 941 | if (ro[1][i / 18][i % 18] != 0.0) { 942 | sfbcnt = sfb; 943 | sfb = -10; 944 | lines = -10; 945 | } 946 | lines--; 947 | i--; 948 | } 949 | } 950 | sfb = sfbcnt + 1; 951 | while (sfb < 12) { 952 | temp = sfBandIndexCurrent.s[sfb]; 953 | sb = sfBandIndexCurrent.s[sfb + 1] - temp; 954 | i = (temp << 2) - temp + j * sb; 955 | for (; sb > 0; sb--) { 956 | is_pos[i] = scalefac[1].s[j][sfb]; 957 | if (is_pos[i] != 7) { 958 | if (lsf) { 959 | i_stereo_k_values(is_pos[i], io_type, i); 960 | } else { 961 | is_ratio[i] = TAN12[is_pos[i]]; 962 | } 963 | } 964 | i++; 965 | } 966 | sfb++; 967 | } 968 | temp = sfBandIndexCurrent.s[10]; 969 | temp2= sfBandIndexCurrent.s[11]; 970 | sb = temp2 - temp; 971 | sfb = (temp << 2) - temp + j * sb; 972 | sb = sfBandIndexCurrent.s[12] - temp2; 973 | i = (temp2 << 2) - temp2 + j * sb; 974 | for (; sb > 0; sb--) { 975 | is_pos[i] = is_pos[sfb]; 976 | if (lsf) { 977 | k[0][i] = k[0][sfb]; 978 | k[1][i] = k[1][sfb]; 979 | } else { 980 | is_ratio[i] = is_ratio[sfb]; 981 | } 982 | i++; 983 | } 984 | } // for (sfb=12 985 | } // for (j=0 ... 986 | } else { // if (gr_info.window_switching_flag ... 987 | i = 31; 988 | ss = 17; 989 | sb = 0; 990 | while (i >= 0) { 991 | if (ro[1][i][ss] != 0.0) { 992 | sb = (i << 4) + (i << 1) + ss; 993 | i = -1; 994 | } else { 995 | ss--; 996 | if (ss < 0) { 997 | i--; 998 | ss = 17; 999 | } 1000 | } 1001 | } 1002 | i = 0; 1003 | while (sfBandIndexCurrent.l[i] <= sb) { 1004 | i++; 1005 | } 1006 | sfb = i; 1007 | i = sfBandIndexCurrent.l[i]; 1008 | for (; sfb < 21; sfb++) { 1009 | sb = sfBandIndexCurrent.l[sfb + 1] - sfBandIndexCurrent.l[sfb]; 1010 | for (; sb > 0; sb--) { 1011 | is_pos[i] = scalefac[1].l[sfb]; 1012 | if (is_pos[i] != 7) { 1013 | if (lsf) { 1014 | i_stereo_k_values(is_pos[i], io_type, i); 1015 | } else { 1016 | is_ratio[i] = TAN12[is_pos[i]]; 1017 | } 1018 | } 1019 | i++; 1020 | } 1021 | } 1022 | sfb = sfBandIndexCurrent.l[20]; 1023 | for (sb = 576 - sfBandIndexCurrent.l[21]; (sb > 0) && (i < 576); sb--) { 1024 | is_pos[i] = is_pos[sfb]; // error here : i >= 576 1025 | if (lsf) { 1026 | k[0][i] = k[0][sfb]; 1027 | k[1][i] = k[1][sfb]; 1028 | } else { 1029 | is_ratio[i] = is_ratio[sfb]; 1030 | } 1031 | i++; 1032 | } // if (gr_info.mixed_block_flag) 1033 | } // if (gr_info.window_switching_flag ... 1034 | } // if (i_stereo) 1035 | i = 0; 1036 | for (sb = 0; sb < SBLIMIT; sb++) { 1037 | for (ss = 0; ss < SSLIMIT; ss++) { 1038 | if (is_pos[i] == 7) { 1039 | if (ms_stereo) { 1040 | lr[0][sb][ss] = (ro[0][sb][ss] + ro[1][sb][ss]) * 0.707106781; 1041 | lr[1][sb][ss] = (ro[0][sb][ss] - ro[1][sb][ss]) * 0.707106781; 1042 | } else { 1043 | lr[0][sb][ss] = ro[0][sb][ss]; 1044 | lr[1][sb][ss] = ro[1][sb][ss]; 1045 | } 1046 | } else if (i_stereo) { 1047 | if (lsf) { 1048 | lr[0][sb][ss] = ro[0][sb][ss] * k[0][i]; 1049 | lr[1][sb][ss] = ro[0][sb][ss] * k[1][i]; 1050 | } else { 1051 | lr[1][sb][ss] = ro[0][sb][ss] / (1 + is_ratio[i]); 1052 | lr[0][sb][ss] = lr[1][sb][ss] * is_ratio[i]; 1053 | } 1054 | } 1055 | i++; 1056 | } 1057 | } 1058 | } 1059 | } 1060 | 1061 | protected function antialias(ch:int, gr:int):void 1062 | { 1063 | var sb18:int; 1064 | var ss:int; 1065 | var sb18lim:int; 1066 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 1067 | // 31 alias-reduction operations between each pair of sub-bands 1068 | // with 8 butterflies between each pair 1069 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2) && !(gr_info.mixed_block_flag != 0)) { 1070 | return; 1071 | } 1072 | if ((gr_info.window_switching_flag != 0) && (gr_info.block_type == 2) && (gr_info.mixed_block_flag != 0)) { 1073 | sb18lim = 18; 1074 | } else { 1075 | sb18lim = 558; 1076 | } 1077 | for (sb18 = 0; sb18 < sb18lim; sb18 += 18) { 1078 | for (ss = 0; ss < 8; ss++) { 1079 | var src_idx1:int = sb18 + 17 - ss; 1080 | var src_idx2:int = sb18 + 18 + ss; 1081 | var bu:Number = out_1d[src_idx1]; 1082 | var bd:Number = out_1d[src_idx2]; 1083 | out_1d[src_idx1] = (bu * cs[ss]) - (bd * ca[ss]); 1084 | out_1d[src_idx2] = (bd * cs[ss]) + (bu * ca[ss]); 1085 | } 1086 | } 1087 | } 1088 | 1089 | protected function hybrid(ch:int, gr:int):void 1090 | { 1091 | var bt:int; 1092 | var sb18:int; 1093 | var cc:int; 1094 | var gr_info:GRInfo = si.ch[ch].gr[gr]; 1095 | var prvblk_ch:Vector. = prevblck[ch]; 1096 | var tsOut:Vector.; 1097 | for (sb18 = 0; sb18 < 576; sb18 += 18) { 1098 | bt = ((gr_info.window_switching_flag != 0) && (gr_info.mixed_block_flag != 0) && (sb18 < 36)) ? 0 : gr_info.block_type; 1099 | tsOut = out_1d; 1100 | for (cc = 0; cc < 18; cc++) { 1101 | tsOutCopy[cc] = tsOut[cc + sb18]; 1102 | } 1103 | inv_mdct(tsOutCopy, rawout, bt); 1104 | for (cc = 0; cc < 18; cc++) { 1105 | tsOut[cc + sb18] = tsOutCopy[cc]; 1106 | } 1107 | // overlap addition 1108 | tsOut[sb18] = rawout[0] + prvblk_ch[sb18 + 0]; 1109 | prvblk_ch[sb18] = rawout[18]; 1110 | tsOut[1 + sb18] = rawout[1] + prvblk_ch[sb18 + 1]; 1111 | prvblk_ch[sb18 + 1] = rawout[19]; 1112 | tsOut[2 + sb18] = rawout[2] + prvblk_ch[sb18 + 2]; 1113 | prvblk_ch[sb18 + 2] = rawout[20]; 1114 | tsOut[3 + sb18] = rawout[3] + prvblk_ch[sb18 + 3]; 1115 | prvblk_ch[sb18 + 3] = rawout[21]; 1116 | tsOut[4 + sb18] = rawout[4] + prvblk_ch[sb18 + 4]; 1117 | prvblk_ch[sb18 + 4] = rawout[22]; 1118 | tsOut[5 + sb18] = rawout[5] + prvblk_ch[sb18 + 5]; 1119 | prvblk_ch[sb18 + 5] = rawout[23]; 1120 | tsOut[6 + sb18] = rawout[6] + prvblk_ch[sb18 + 6]; 1121 | prvblk_ch[sb18 + 6] = rawout[24]; 1122 | tsOut[7 + sb18] = rawout[7] + prvblk_ch[sb18 + 7]; 1123 | prvblk_ch[sb18 + 7] = rawout[25]; 1124 | tsOut[8 + sb18] = rawout[8] + prvblk_ch[sb18 + 8]; 1125 | prvblk_ch[sb18 + 8] = rawout[26]; 1126 | tsOut[9 + sb18] = rawout[9] + prvblk_ch[sb18 + 9]; 1127 | prvblk_ch[sb18 + 9] = rawout[27]; 1128 | tsOut[10 + sb18] = rawout[10] + prvblk_ch[sb18 + 10]; 1129 | prvblk_ch[sb18 + 10] = rawout[28]; 1130 | tsOut[11 + sb18] = rawout[11] + prvblk_ch[sb18 + 11]; 1131 | prvblk_ch[sb18 + 11] = rawout[29]; 1132 | tsOut[12 + sb18] = rawout[12] + prvblk_ch[sb18 + 12]; 1133 | prvblk_ch[sb18 + 12] = rawout[30]; 1134 | tsOut[13 + sb18] = rawout[13] + prvblk_ch[sb18 + 13]; 1135 | prvblk_ch[sb18 + 13] = rawout[31]; 1136 | tsOut[14 + sb18] = rawout[14] + prvblk_ch[sb18 + 14]; 1137 | prvblk_ch[sb18 + 14] = rawout[32]; 1138 | tsOut[15 + sb18] = rawout[15] + prvblk_ch[sb18 + 15]; 1139 | prvblk_ch[sb18 + 15] = rawout[33]; 1140 | tsOut[16 + sb18] = rawout[16] + prvblk_ch[sb18 + 16]; 1141 | prvblk_ch[sb18 + 16] = rawout[34]; 1142 | tsOut[17 + sb18] = rawout[17] + prvblk_ch[sb18 + 17]; 1143 | prvblk_ch[sb18 + 17] = rawout[35]; 1144 | } 1145 | } 1146 | 1147 | public function inv_mdct(inp:Vector., outp:Vector., block_type:int):void 1148 | { 1149 | var win_bt:Vector.; 1150 | var i:int; 1151 | var tmpf_0:Number, tmpf_1:Number, tmpf_2:Number, tmpf_3:Number, tmpf_4:Number 1152 | var tmpf_5:Number, tmpf_6:Number, tmpf_7:Number, tmpf_8:Number, tmpf_9:Number; 1153 | var tmpf_10:Number, tmpf_11:Number, tmpf_12:Number, tmpf_13:Number, tmpf_14:Number 1154 | var tmpf_15:Number, tmpf_16:Number, tmpf_17:Number; 1155 | tmpf_0 = tmpf_1 = tmpf_2 = tmpf_3 = tmpf_4 = tmpf_5 = tmpf_6 = tmpf_7 = tmpf_8 = tmpf_9 = 1156 | tmpf_10 = tmpf_11 = tmpf_12 = tmpf_13 = tmpf_14 = tmpf_15 = tmpf_16 = tmpf_17 = 0.0; 1157 | if(block_type == 2) { 1158 | outp[0] = 0.0; 1159 | outp[1] = 0.0; 1160 | outp[2] = 0.0; 1161 | outp[3] = 0.0; 1162 | outp[4] = 0.0; 1163 | outp[5] = 0.0; 1164 | outp[6] = 0.0; 1165 | outp[7] = 0.0; 1166 | outp[8] = 0.0; 1167 | outp[9] = 0.0; 1168 | outp[10] = 0.0; 1169 | outp[11] = 0.0; 1170 | outp[12] = 0.0; 1171 | outp[13] = 0.0; 1172 | outp[14] = 0.0; 1173 | outp[15] = 0.0; 1174 | outp[16] = 0.0; 1175 | outp[17] = 0.0; 1176 | outp[18] = 0.0; 1177 | outp[19] = 0.0; 1178 | outp[20] = 0.0; 1179 | outp[21] = 0.0; 1180 | outp[22] = 0.0; 1181 | outp[23] = 0.0; 1182 | outp[24] = 0.0; 1183 | outp[25] = 0.0; 1184 | outp[26] = 0.0; 1185 | outp[27] = 0.0; 1186 | outp[28] = 0.0; 1187 | outp[29] = 0.0; 1188 | outp[30] = 0.0; 1189 | outp[31] = 0.0; 1190 | outp[32] = 0.0; 1191 | outp[33] = 0.0; 1192 | outp[34] = 0.0; 1193 | outp[35] = 0.0; 1194 | var six_i:int = 0; 1195 | for (i = 0; i < 3; i++) 1196 | { 1197 | // 12 point IMDCT 1198 | // Begin 12 point IDCT 1199 | // Input aliasing for 12 pt IDCT 1200 | inp[15 + i] += inp[12 + i]; 1201 | inp[12 + i] += inp[9 + i]; 1202 | inp[9 + i] += inp[6 + i]; 1203 | inp[6 + i] += inp[3 + i]; 1204 | inp[3 + i] += inp[0 + i]; 1205 | 1206 | // Input aliasing on odd indices (for 6 point IDCT) 1207 | inp[15 + i] += inp[9 + i]; 1208 | inp[9 + i] += inp[3 + i]; 1209 | 1210 | // 3 point IDCT on even indices 1211 | var pp1:Number = inp[6 + i] * 0.866025403; 1212 | var pp2:Number = inp[12 + i] * 0.5; 1213 | var sum:Number = inp[i] + pp2; 1214 | tmpf_1 = inp[i] - inp[12 + i]; 1215 | tmpf_0 = sum + pp1; 1216 | tmpf_2 = sum - pp1; 1217 | 1218 | // End 3 point IDCT on even indices 1219 | // 3 point IDCT on odd indices (for 6 point IDCT) 1220 | pp2 = inp[15 + i] * 0.5; 1221 | pp1 = inp[9 + i] * 0.866025403; 1222 | sum = inp[3 + i] + pp2; 1223 | tmpf_4 = inp[3 + i] - inp[15 + i]; 1224 | tmpf_5 = sum + pp1; 1225 | tmpf_3 = sum - pp1; 1226 | 1227 | // End 3 point IDCT on odd indices 1228 | // Twiddle factors on odd indices (for 6 point IDCT) 1229 | tmpf_3 *= 1.931851653; 1230 | tmpf_4 *= 0.707106781; 1231 | tmpf_5 *= 0.517638090; 1232 | 1233 | // Output butterflies on 2 3 point IDCT's (for 6 point IDCT) 1234 | var save:Number = tmpf_0; 1235 | tmpf_0 += tmpf_5; 1236 | tmpf_5 = save - tmpf_5; 1237 | save = tmpf_1; 1238 | tmpf_1 += tmpf_4; 1239 | tmpf_4 = save - tmpf_4; 1240 | save = tmpf_2; 1241 | tmpf_2 += tmpf_3; 1242 | tmpf_3 = save - tmpf_3; 1243 | 1244 | // End 6 point IDCT 1245 | // Twiddle factors on indices (for 12 point IDCT) 1246 | tmpf_0 *= 0.504314480; 1247 | tmpf_1 *= 0.541196100; 1248 | tmpf_2 *= 0.630236207; 1249 | tmpf_3 *= 0.821339815; 1250 | tmpf_4 *= 1.306562965; 1251 | tmpf_5 *= 3.830648788; 1252 | 1253 | // End 12 point IDCT 1254 | // Shift to 12 point modified IDCT, multiply by window type 2 1255 | tmpf_8 = -tmpf_0 * 0.793353340; 1256 | tmpf_9 = -tmpf_0 * 0.608761429; 1257 | tmpf_7 = -tmpf_1 * 0.923879532; 1258 | tmpf_10 = -tmpf_1 * 0.382683432; 1259 | tmpf_6 = -tmpf_2 * 0.991444861; 1260 | tmpf_11 = -tmpf_2 * 0.130526192; 1261 | tmpf_0 = tmpf_3; 1262 | tmpf_1 = tmpf_4 * 0.382683432; 1263 | tmpf_2 = tmpf_5 * 0.608761429; 1264 | tmpf_3 = -tmpf_5 * 0.793353340; 1265 | tmpf_4 = -tmpf_4 * 0.923879532; 1266 | tmpf_5 = -tmpf_0 * 0.991444861; 1267 | tmpf_0 *= 0.130526192; 1268 | 1269 | outp[six_i + 6] += tmpf_0; 1270 | outp[six_i + 7] += tmpf_1; 1271 | outp[six_i + 8] += tmpf_2; 1272 | outp[six_i + 9] += tmpf_3; 1273 | outp[six_i + 10] += tmpf_4; 1274 | outp[six_i + 11] += tmpf_5; 1275 | outp[six_i + 12] += tmpf_6; 1276 | outp[six_i + 13] += tmpf_7; 1277 | outp[six_i + 14] += tmpf_8; 1278 | outp[six_i + 15] += tmpf_9; 1279 | outp[six_i + 16] += tmpf_10; 1280 | outp[six_i + 17] += tmpf_11; 1281 | 1282 | six_i += 6; 1283 | } 1284 | } else { 1285 | // 36 point IDCT 1286 | // input aliasing for 36 point IDCT 1287 | inp[17] += inp[16]; 1288 | inp[16] += inp[15]; 1289 | inp[15] += inp[14]; 1290 | inp[14] += inp[13]; 1291 | inp[13] += inp[12]; 1292 | inp[12] += inp[11]; 1293 | inp[11] += inp[10]; 1294 | inp[10] += inp[9]; 1295 | inp[9] += inp[8]; 1296 | inp[8] += inp[7]; 1297 | inp[7] += inp[6]; 1298 | inp[6] += inp[5]; 1299 | inp[5] += inp[4]; 1300 | inp[4] += inp[3]; 1301 | inp[3] += inp[2]; 1302 | inp[2] += inp[1]; 1303 | inp[1] += inp[0]; 1304 | 1305 | // 18 point IDCT for odd indices 1306 | // input aliasing for 18 point IDCT 1307 | inp[17] += inp[15]; 1308 | inp[15] += inp[13]; 1309 | inp[13] += inp[11]; 1310 | inp[11] += inp[9]; 1311 | inp[9] += inp[7]; 1312 | inp[7] += inp[5]; 1313 | inp[5] += inp[3]; 1314 | inp[3] += inp[1]; 1315 | 1316 | var tmp0:Number, tmp1:Number, tmp2:Number, tmp3:Number, tmp4:Number 1317 | var tmp0_:Number, tmp1_:Number, tmp2_:Number, tmp3_:Number; 1318 | var tmp0o:Number, tmp1o:Number, tmp2o:Number, tmp3o:Number, tmp4o:Number; 1319 | var tmp0_o:Number, tmp1_o:Number, tmp2_o:Number, tmp3_o:Number; 1320 | 1321 | // Fast 9 Point Inverse Discrete Cosine Transform 1322 | // 1323 | // By Francois-Raymond Boyer 1324 | // mailto:boyerf@iro.umontreal.ca 1325 | // http://www.iro.umontreal.ca/~boyerf 1326 | // 1327 | // The code has been optimized for Intel processors 1328 | // (takes a lot of time to convert float to and from iternal FPU representation) 1329 | // 1330 | // It is a simple "factorization" of the IDCT matrix. 1331 | 1332 | // 9 point IDCT on even indices 1333 | // 5 points on odd indices (not realy an IDCT) 1334 | var i00:Number = inp[0] + inp[0]; 1335 | var iip12:Number = i00 + inp[12]; 1336 | tmp0 = iip12 + inp[4] * 1.8793852415718 + inp[8] * 1.532088886238 + inp[16] * 0.34729635533386; 1337 | tmp1 = i00 + inp[4] - inp[8] - inp[12] - inp[12] - inp[16]; 1338 | tmp2 = iip12 - inp[4] * 0.34729635533386 - inp[8] * 1.8793852415718 + inp[16] * 1.532088886238; 1339 | tmp3 = iip12 - inp[4] * 1.532088886238 + inp[8] * 0.34729635533386 - inp[16] * 1.8793852415718; 1340 | tmp4 = inp[0] - inp[4] + inp[8] - inp[12] + inp[16]; 1341 | 1342 | // 4 points on even indices 1343 | var i66_:Number = inp[6] * 1.732050808; // Sqrt[3] 1344 | tmp0_ = inp[2] * 1.9696155060244 + i66_ + inp[10] * 1.2855752193731 + inp[14] * 0.68404028665134; 1345 | tmp1_ = (inp[2] - inp[10] - inp[14]) * 1.732050808; 1346 | tmp2_ = inp[2] * 1.2855752193731 - i66_ - inp[10] * 0.68404028665134 + inp[14] * 1.9696155060244; 1347 | tmp3_ = inp[2] * 0.68404028665134 - i66_ + inp[10] * 1.9696155060244 - inp[14] * 1.2855752193731; 1348 | 1349 | // 9 point IDCT on odd indices 1350 | // 5 points on odd indices (not realy an IDCT) 1351 | var i0:Number = inp[1] + inp[1]; 1352 | var i0p12:Number = i0 + inp[12 + 1]; 1353 | tmp0o = i0p12 + inp[4+1] * 1.8793852415718 + inp[8+1] * 1.532088886238 + inp[16+1] * 0.34729635533386; 1354 | tmp1o = i0 + inp[4+1] - inp[8+1] - inp[12+1] - inp[12+1] - inp[16+1]; 1355 | tmp2o = i0p12 - inp[4+1] * 0.34729635533386 - inp[8+1] * 1.8793852415718 + inp[16+1] * 1.532088886238; 1356 | tmp3o = i0p12 - inp[4+1] * 1.532088886238 + inp[8+1] * 0.34729635533386 - inp[16+1] * 1.8793852415718; 1357 | tmp4o = (inp[1] - inp[4+1] + inp[8+1] - inp[12+1] + inp[16+1]) * 0.707106781; // Twiddled 1358 | 1359 | // 4 points on even indices 1360 | var i6_:Number = inp[6+1] * 1.732050808; // Sqrt[3] 1361 | tmp0_o = inp[2+1] * 1.9696155060244 + i6_ + inp[10+1] * 1.2855752193731 + inp[14+1] * 0.68404028665134; 1362 | tmp1_o = (inp[2+1] - inp[10+1] - inp[14+1]) * 1.732050808; 1363 | tmp2_o = inp[2+1] * 1.2855752193731 - i6_ - inp[10+1] * 0.68404028665134 + inp[14+1] * 1.9696155060244; 1364 | tmp3_o = inp[2+1] * 0.68404028665134 - i6_ + inp[10+1] * 1.9696155060244 - inp[14+1] * 1.2855752193731; 1365 | 1366 | // Twiddle factors on odd indices 1367 | // and 1368 | // Butterflies on 9 point IDCT's 1369 | // and 1370 | // twiddle factors for 36 point IDCT 1371 | var e:Number; 1372 | var o:Number; 1373 | e = tmp0 + tmp0_; o = (tmp0o + tmp0_o) * 0.501909918; tmpf_0 = e + o; tmpf_17 = e - o; 1374 | e = tmp1 + tmp1_; o = (tmp1o + tmp1_o) * 0.517638090; tmpf_1 = e + o; tmpf_16 = e - o; 1375 | e = tmp2 + tmp2_; o = (tmp2o + tmp2_o) * 0.551688959; tmpf_2 = e + o; tmpf_15 = e - o; 1376 | e = tmp3 + tmp3_; o = (tmp3o + tmp3_o) * 0.610387294; tmpf_3 = e + o; tmpf_14 = e - o; 1377 | tmpf_4 = tmp4 + tmp4o; 1378 | tmpf_13 = tmp4 - tmp4o; 1379 | e = tmp3 - tmp3_; o = (tmp3o - tmp3_o) * 0.871723397; tmpf_5 = e + o; tmpf_12 = e - o; 1380 | e = tmp2 - tmp2_; o = (tmp2o - tmp2_o) * 1.183100792; tmpf_6 = e + o; tmpf_11 = e - o; 1381 | e = tmp1 - tmp1_; o = (tmp1o - tmp1_o) * 1.931851653; tmpf_7 = e + o; tmpf_10 = e - o; 1382 | e = tmp0 - tmp0_; o = (tmp0o - tmp0_o) * 5.736856623; tmpf_8 = e + o; tmpf_9 = e - o; 1383 | 1384 | // end 36 point IDCT 1385 | // shift to modified IDCT 1386 | win_bt = win[block_type]; 1387 | 1388 | outp[0] =- tmpf_9 * win_bt[0]; 1389 | outp[1] =- tmpf_10 * win_bt[1]; 1390 | outp[2] =- tmpf_11 * win_bt[2]; 1391 | outp[3] =- tmpf_12 * win_bt[3]; 1392 | outp[4] =- tmpf_13 * win_bt[4]; 1393 | outp[5] =- tmpf_14 * win_bt[5]; 1394 | outp[6] =- tmpf_15 * win_bt[6]; 1395 | outp[7] =- tmpf_16 * win_bt[7]; 1396 | outp[8] =- tmpf_17 * win_bt[8]; 1397 | outp[9] = tmpf_17 * win_bt[9]; 1398 | outp[10] = tmpf_16 * win_bt[10]; 1399 | outp[11] = tmpf_15 * win_bt[11]; 1400 | outp[12] = tmpf_14 * win_bt[12]; 1401 | outp[13] = tmpf_13 * win_bt[13]; 1402 | outp[14] = tmpf_12 * win_bt[14]; 1403 | outp[15] = tmpf_11 * win_bt[15]; 1404 | outp[16] = tmpf_10 * win_bt[16]; 1405 | outp[17] = tmpf_9 * win_bt[17]; 1406 | outp[18] = tmpf_8 * win_bt[18]; 1407 | outp[19] = tmpf_7 * win_bt[19]; 1408 | outp[20] = tmpf_6 * win_bt[20]; 1409 | outp[21] = tmpf_5 * win_bt[21]; 1410 | outp[22] = tmpf_4 * win_bt[22]; 1411 | outp[23] = tmpf_3 * win_bt[23]; 1412 | outp[24] = tmpf_2 * win_bt[24]; 1413 | outp[25] = tmpf_1 * win_bt[25]; 1414 | outp[26] = tmpf_0 * win_bt[26]; 1415 | outp[27] = tmpf_0 * win_bt[27]; 1416 | outp[28] = tmpf_1 * win_bt[28]; 1417 | outp[29] = tmpf_2 * win_bt[29]; 1418 | outp[30] = tmpf_3 * win_bt[30]; 1419 | outp[31] = tmpf_4 * win_bt[31]; 1420 | outp[32] = tmpf_5 * win_bt[32]; 1421 | outp[33] = tmpf_6 * win_bt[33]; 1422 | outp[34] = tmpf_7 * win_bt[34]; 1423 | outp[35] = tmpf_8 * win_bt[35]; 1424 | } 1425 | } 1426 | 1427 | protected function createReorderTable(scalefac_band:Vector.):Vector. { 1428 | var j:int = 0; 1429 | var ix:Vector. = new Vector.(576, true); 1430 | for (var sfb:uint = 0; sfb < 13; sfb++) { 1431 | var start:int = scalefac_band[sfb]; 1432 | var end:int = scalefac_band[sfb + 1]; 1433 | for (var window:uint = 0; window < 3; window++) { 1434 | for (var i:int = start; i < end; i++) { 1435 | ix[3 * i + window] = j++; 1436 | } 1437 | } 1438 | } 1439 | return ix; 1440 | } 1441 | 1442 | 1443 | protected function initialize():void 1444 | { 1445 | is_1d = new Vector.(SBLIMIT * SSLIMIT + 4, true); 1446 | ro = (new VectorNumber3D(2, SBLIMIT, SSLIMIT)).v; 1447 | lr = (new VectorNumber3D(2, SBLIMIT, SSLIMIT)).v; 1448 | out_1d = new Vector.(SBLIMIT * SSLIMIT, true); 1449 | prevblck = (new VectorNumber2D(2, SBLIMIT * SSLIMIT)).v; 1450 | k = (new VectorNumber2D(2, SBLIMIT * SSLIMIT)).v; 1451 | nonzero = new Vector.(2, true); 1452 | 1453 | scalefac = new Vector.(2, true); 1454 | scalefac[0] = new Temporaire2(); 1455 | scalefac[1] = new Temporaire2(); 1456 | 1457 | sfBandIndex = new Vector.(9, true); 1458 | var l0:Vector. = Vector.([ 0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576 ]); 1459 | var s0:Vector. = Vector.([ 0,4,8,12,18,24,32,42,56,74,100,132,174,192 ]); 1460 | var l1:Vector. = Vector.([ 0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576 ]); 1461 | var s1:Vector. = Vector.([ 0,4,8,12,18,26,36,48,62,80,104,136,180,192 ]); 1462 | var l2:Vector. = Vector.([ 0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576 ]); 1463 | var s2:Vector. = Vector.([ 0,4,8,12,18,26,36,48,62,80,104,134,174,192 ]); 1464 | var l3:Vector. = Vector.([ 0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576 ]); 1465 | var s3:Vector. = Vector.([ 0,4,8,12,16,22,30,40,52,66,84,106,136,192 ]); 1466 | var l4:Vector. = Vector.([ 0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576 ]); 1467 | var s4:Vector. = Vector.([ 0,4,8,12,16,22,28,38,50,64,80,100,126,192 ]); 1468 | var l5:Vector. = Vector.([ 0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576 ]); 1469 | var s5:Vector. = Vector.([ 0,4,8,12,16,22,30,42,58,78,104,138,180,192 ]); 1470 | var l6:Vector. = Vector.([ 0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576 ]); 1471 | var s6:Vector. = Vector.([ 0,4,8,12,18,26,36,48,62,80,104,134,174,192 ]); 1472 | var l7:Vector. = Vector.([ 0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576 ]); 1473 | var s7:Vector. = Vector.([ 0,4,8,12,18,26,36,48,62,80,104,134,174,192 ]); 1474 | var l8:Vector. = Vector.([ 0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576 ]); 1475 | var s8:Vector. = Vector.([ 0,8,16,24,36,52,72,96,124,160,162,164,166,192 ]); 1476 | sfBandIndex[0] = new SBI(l0, s0); 1477 | sfBandIndex[1] = new SBI(l1, s1); 1478 | sfBandIndex[2] = new SBI(l2, s2); 1479 | sfBandIndex[3] = new SBI(l3, s3); 1480 | sfBandIndex[4] = new SBI(l4, s4); 1481 | sfBandIndex[5] = new SBI(l5, s5); 1482 | sfBandIndex[6] = new SBI(l6, s6); 1483 | sfBandIndex[7] = new SBI(l7, s7); 1484 | sfBandIndex[8] = new SBI(l8, s8); 1485 | 1486 | reorder_table = new Vector.>(9, true); 1487 | for (var i:uint = 0; i < 9; i++) { 1488 | reorder_table[i] = createReorderTable(sfBandIndex[i].s); 1489 | } 1490 | 1491 | sftable = new SFTable( 1492 | Vector.([ 0, 6, 11, 16, 21 ]), 1493 | Vector.([ 0, 6, 12 ]) 1494 | ); 1495 | 1496 | scalefac_buffer = new Vector.(54, true); 1497 | 1498 | //stream = stream0; 1499 | //header = header0; 1500 | //filter1 = filtera; 1501 | //filter2 = filterb; 1502 | //buffer = buffer0; 1503 | 1504 | channels = (currentFrame.channelMode == MPEGFrame.CHANNEL_MODE_MONO) ? 1 : 2; 1505 | 1506 | first_channel = 0; 1507 | last_channel = (channels == 2) ? 1 : 0; 1508 | 1509 | max_gr = (currentFrame.version == MPEGFrame.MPEG_VERSION_1_0) ? 2 : 1; 1510 | 1511 | switch(currentFrame.version) { 1512 | case MPEGFrame.MPEG_VERSION_1_0: 1513 | sfreq = currentFrame.samplingrateIndex + 3; 1514 | break; 1515 | case MPEGFrame.MPEG_VERSION_2_5: 1516 | sfreq = currentFrame.samplingrateIndex + 6; 1517 | break; 1518 | default: 1519 | sfreq = currentFrame.samplingrateIndex; 1520 | break; 1521 | } 1522 | sfBandIndexCurrent = sfBandIndex[sfreq]; 1523 | 1524 | nonzero[0] = nonzero[1] = 576; 1525 | 1526 | si = new LayerIIISideInfo(); 1527 | 1528 | seek_notify(); 1529 | 1530 | initialized = true; 1531 | } 1532 | 1533 | public function seek_notify():void { 1534 | frame_start = 0; 1535 | for (var ch:uint = 0; ch < 2; ch++) { 1536 | for (var j:int = 0; j < 576; j++) { 1537 | prevblck[ch][j] = 0.0; 1538 | } 1539 | } 1540 | br = new BitReserve(); 1541 | } 1542 | 1543 | 1544 | public static var pretab:Vector. = Vector.( 1545 | [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 ] 1546 | ); 1547 | 1548 | public static var two_to_negative_half_pow:Vector. = 1549 | Vector.([ 1550 | 1.0000000000E+00, 7.0710678119E-01, 5.0000000000E-01, 3.5355339059E-01, 1551 | 2.5000000000E-01, 1.7677669530E-01, 1.2500000000E-01, 8.8388347648E-02, 1552 | 6.2500000000E-02, 4.4194173824E-02, 3.1250000000E-02, 2.2097086912E-02, 1553 | 1.5625000000E-02, 1.1048543456E-02, 7.8125000000E-03, 5.5242717280E-03, 1554 | 3.9062500000E-03, 2.7621358640E-03, 1.9531250000E-03, 1.3810679320E-03, 1555 | 9.7656250000E-04, 6.9053396600E-04, 4.8828125000E-04, 3.4526698300E-04, 1556 | 2.4414062500E-04, 1.7263349150E-04, 1.2207031250E-04, 8.6316745750E-05, 1557 | 6.1035156250E-05, 4.3158372875E-05, 3.0517578125E-05, 2.1579186438E-05, 1558 | 1.5258789062E-05, 1.0789593219E-05, 7.6293945312E-06, 5.3947966094E-06, 1559 | 3.8146972656E-06, 2.6973983047E-06, 1.9073486328E-06, 1.3486991523E-06, 1560 | 9.5367431641E-07, 6.7434957617E-07, 4.7683715820E-07, 3.3717478809E-07, 1561 | 2.3841857910E-07, 1.6858739404E-07, 1.1920928955E-07, 8.4293697022E-08, 1562 | 5.9604644775E-08, 4.2146848511E-08, 2.9802322388E-08, 2.1073424255E-08, 1563 | 1.4901161194E-08, 1.0536712128E-08, 7.4505805969E-09, 5.2683560639E-09, 1564 | 3.7252902985E-09, 2.6341780319E-09, 1.8626451492E-09, 1.3170890160E-09, 1565 | 9.3132257462E-10, 6.5854450798E-10, 4.6566128731E-10, 3.2927225399E-10 1566 | ]); 1567 | 1568 | public static const d43:Number = 4.0 / 3.0; 1569 | public static var t_43:Vector. = create_t_43(); 1570 | protected static function create_t_43():Vector. { 1571 | var _d43:Number = d43; 1572 | var t43:Vector. = new Vector.(8192, true); 1573 | for (var i:uint = 0; i < 8192; i++) { 1574 | t43[i] = Math.pow(i, _d43); 1575 | } 1576 | return t43; 1577 | } 1578 | 1579 | public static var io:Vector.> = 1580 | Vector.>([ 1581 | Vector.([ 1582 | 1.0000000000E+00, 8.4089641526E-01, 7.0710678119E-01, 5.9460355751E-01, 1583 | 5.0000000001E-01, 4.2044820763E-01, 3.5355339060E-01, 2.9730177876E-01, 1584 | 2.5000000001E-01, 2.1022410382E-01, 1.7677669530E-01, 1.4865088938E-01, 1585 | 1.2500000000E-01, 1.0511205191E-01, 8.8388347652E-02, 7.4325444691E-02, 1586 | 6.2500000003E-02, 5.2556025956E-02, 4.4194173826E-02, 3.7162722346E-02, 1587 | 3.1250000002E-02, 2.6278012978E-02, 2.2097086913E-02, 1.8581361173E-02, 1588 | 1.5625000001E-02, 1.3139006489E-02, 1.1048543457E-02, 9.2906805866E-03, 1589 | 7.8125000006E-03, 6.5695032447E-03, 5.5242717285E-03, 4.6453402934E-03 1590 | ]), 1591 | Vector.([ 1592 | 1.0000000000E+00, 7.0710678119E-01, 5.0000000000E-01, 3.5355339060E-01, 1593 | 2.5000000000E-01, 1.7677669530E-01, 1.2500000000E-01, 8.8388347650E-02, 1594 | 6.2500000001E-02, 4.4194173825E-02, 3.1250000001E-02, 2.2097086913E-02, 1595 | 1.5625000000E-02, 1.1048543456E-02, 7.8125000002E-03, 5.5242717282E-03, 1596 | 3.9062500001E-03, 2.7621358641E-03, 1.9531250001E-03, 1.3810679321E-03, 1597 | 9.7656250004E-04, 6.9053396603E-04, 4.8828125002E-04, 3.4526698302E-04, 1598 | 2.4414062501E-04, 1.7263349151E-04, 1.2207031251E-04, 8.6316745755E-05, 1599 | 6.1035156254E-05, 4.3158372878E-05, 3.0517578127E-05, 2.1579186439E-05 1600 | ]) 1601 | ]); 1602 | 1603 | public static var TAN12:Vector. = 1604 | Vector.([ 1605 | 0.0, 0.26794919, 0.57735027, 1.0, 1606 | 1.73205081, 3.73205081, 9.9999999e10, -3.73205081, 1607 | -1.73205081, -1.0, -0.57735027, -0.26794919, 1608 | 0.0, 0.26794919, 0.57735027, 1.0 1609 | ]); 1610 | 1611 | protected static var slen:Vector.> = 1612 | Vector.>([ 1613 | Vector.([ 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 ]), 1614 | Vector.([ 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 ]) 1615 | ]); 1616 | 1617 | public static var win:Vector.> = 1618 | Vector.>([ 1619 | Vector.([ 1620 | -1.6141214951E-02, -5.3603178919E-02, -1.0070713296E-01, -1.6280817573E-01, 1621 | -4.9999999679E-01, -3.8388735032E-01, -6.2061144372E-01, -1.1659756083E+00, 1622 | -3.8720752656E+00, -4.2256286556E+00, -1.5195289984E+00, -9.7416483388E-01, 1623 | -7.3744074053E-01, -1.2071067773E+00, -5.1636156596E-01, -4.5426052317E-01, 1624 | -4.0715656898E-01, -3.6969460527E-01, -3.3876269197E-01, -3.1242222492E-01, 1625 | -2.8939587111E-01, -2.6880081906E-01, -5.0000000266E-01, -2.3251417468E-01, 1626 | -2.1596714708E-01, -2.0004979098E-01, -1.8449493497E-01, -1.6905846094E-01, 1627 | -1.5350360518E-01, -1.3758624925E-01, -1.2103922149E-01, -2.0710679058E-01, 1628 | -8.4752577594E-02, -6.4157525656E-02, -4.1131172614E-02, -1.4790705759E-02 1629 | ]), 1630 | Vector.([ 1631 | -1.6141214951E-02, -5.3603178919E-02, -1.0070713296E-01, -1.6280817573E-01, 1632 | -4.9999999679E-01, -3.8388735032E-01, -6.2061144372E-01, -1.1659756083E+00, 1633 | -3.8720752656E+00, -4.2256286556E+00, -1.5195289984E+00, -9.7416483388E-01, 1634 | -7.3744074053E-01, -1.2071067773E+00, -5.1636156596E-01, -4.5426052317E-01, 1635 | -4.0715656898E-01, -3.6969460527E-01, -3.3908542600E-01, -3.1511810350E-01, 1636 | -2.9642226150E-01, -2.8184548650E-01, -5.4119610000E-01, -2.6213228100E-01, 1637 | -2.5387916537E-01, -2.3296291359E-01, -1.9852728987E-01, -1.5233534808E-01, 1638 | -9.6496400054E-02, -3.3423828516E-02, 0.0000000000E+00, 0.0000000000E+00, 1639 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00 1640 | ]), 1641 | Vector.([ 1642 | -4.8300800645E-02, -1.5715656932E-01, -2.8325045177E-01, -4.2953747763E-01, 1643 | -1.2071067795E+00, -8.2426483178E-01, -1.1451749106E+00, -1.7695290101E+00, 1644 | -4.5470225061E+00, -3.4890531002E+00, -7.3296292804E-01, -1.5076514758E-01, 1645 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 1646 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 1647 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 1648 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 1649 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 1650 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00 1651 | ]), 1652 | Vector.([ 1653 | 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 0.0000000000E+00, 1654 | 0.0000000000E+00, 0.0000000000E+00, -1.5076513660E-01, -7.3296291107E-01, 1655 | -3.4890530566E+00, -4.5470224727E+00, -1.7695290031E+00, -1.1451749092E+00, 1656 | -8.3137738100E-01, -1.3065629650E+00, -5.4142014250E-01, -4.6528974900E-01, 1657 | -4.1066990750E-01, -3.7004680800E-01, -3.3876269197E-01, -3.1242222492E-01, 1658 | -2.8939587111E-01, -2.6880081906E-01, -5.0000000266E-01, -2.3251417468E-01, 1659 | -2.1596714708E-01, -2.0004979098E-01, -1.8449493497E-01, -1.6905846094E-01, 1660 | -1.5350360518E-01, -1.3758624925E-01, -1.2103922149E-01, -2.0710679058E-01, 1661 | -8.4752577594E-02, -6.4157525656E-02, -4.1131172614E-02, -1.4790705759E-02 1662 | ]) 1663 | ]); 1664 | 1665 | protected static var nr_of_sfb_block:Vector.>> = 1666 | Vector.>>([ 1667 | Vector.>([ Vector.([ 6,5,5,5 ]), Vector.([ 9,9,9,9 ]), Vector.([ 6,9,9,9 ]) ]), 1668 | Vector.>([ Vector.([ 6,5,7,3 ]), Vector.([ 9,9,12,6 ]), Vector.([ 6,9,12,6 ]) ]), 1669 | Vector.>([ Vector.([ 11,10,0,0 ]), Vector.([ 18,18,0,0 ]), Vector.([ 15,18,0,0 ]) ]), 1670 | Vector.>([ Vector.([ 7,7,7,0 ]), Vector.([ 12,12,12,0 ]), Vector.([ 6,15,12,0 ]) ]), 1671 | Vector.>([ Vector.([ 6,6,6,3 ]), Vector.([ 12,9,9,6 ]), Vector.([ 6,12,9,6 ]) ]), 1672 | Vector.>([ Vector.([ 8,8,5,0 ]), Vector.([ 15,12,9,0 ]), Vector.([ 6,18,9,0 ]) ]) 1673 | ]); 1674 | 1675 | protected static var cs:Vector. = 1676 | Vector.([ 1677 | 0.857492925712, 0.881741997318, 0.949628649103, 0.983314592492, 1678 | 0.995517816065, 0.999160558175, 0.999899195243, 0.999993155067 1679 | ]); 1680 | 1681 | protected static var ca:Vector. = 1682 | Vector.([ 1683 | -0.5144957554270, -0.4717319685650, -0.3133774542040, -0.1819131996110, 1684 | -0.0945741925262, -0.0409655828852, -0.0141985685725, -0.00369997467375 1685 | ]); 1686 | } 1687 | } 1688 | --------------------------------------------------------------------------------