* moved "binPlayers" into libEmbedVideo (more modular folder layout)
[lhc/web/wiklou.git] / js2 / mwEmbed / libEmbedVideo / binPlayers / omtk-fx / src / as / org / omtk / vorbis / Residue2.as
1 /*
2
3 Copyright 2008 Tor-Einar Jarnbjo
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 */
18
19 package org.omtk.vorbis {
20
21 import flash.errors.IllegalOperationError;
22 import flash.utils.Dictionary;
23 import org.omtk.util.BitByteArray;
24
25 public class Residue2 extends Residue {
26
27 public function Residue2(source:BitByteArray, header:SetupHeader) {
28 super(source, header);
29 }
30
31 public override function decodeResidue(
32 vorbis:VorbisStream, source:BitByteArray,
33 mode:Mode, ch:int,
34 doNotDecodeFlags:Vector.<Boolean>, vectors0:Vector.<Number>, vectors1:Vector.<Number>):void {
35
36 var i:int;
37 var j:int;
38 var k:int;
39 var l:int;
40 var s:int;
41 var slim:int;
42
43 var look:Look = getLook(vorbis, mode);
44
45 var codeBook:CodeBook = vorbis.setupHeader.codeBooks[classBook];
46
47 var classvalsPerCodeword:int = codeBook.dimensions;
48 var nToRead:int = end - begin;
49 var partitionsToRead:int = nToRead / partitionSize; // partvals
50
51 var samplesPerPartition:int = partitionSize;
52 var partitionsPerWord:int = look.phrasebook.dimensions;
53
54 var partWords:int = (partitionsToRead + partitionsPerWord - 1) / partitionsPerWord;
55
56 var offset:int;
57
58 var left:Boolean = false;
59 var right:Boolean = false;
60
61 for (i = 0; i < doNotDecodeFlags.length; i++) {
62 if (!doNotDecodeFlags[i]) {
63 if(i==0) {
64 left = true;
65 }
66 else if (i==1) {
67 right = true;
68 }
69 }
70 }
71
72 var partword:Array = new Array(partWords);
73
74 var pb:int = source.position;
75
76 slim = look.stages;
77 for (s = 0; s < slim; s++) {
78
79 for (i = 0, l = 0; i < partitionsToRead; l++) {
80
81 if (s == 0) {
82 var temp:int = source.readUnsignedHuffmanInt(look.phrasebook.huffmanRoot);
83 if (temp == -1) {
84 throw new Error("Foo??");
85 }
86 partword[l] = look.decodemap[temp];
87 if (partword[l] == null) {
88 throw new Error("Foo??");
89 }
90 }
91
92 for (k = 0; k < partitionsPerWord && i < partitionsToRead; k++, i++) {
93 offset = begin + i * samplesPerPartition;
94
95 if ((cascade[partword[l][k]] & (1 << s)) != 0) {
96 var stagebook:CodeBook =
97 vorbis.setupHeader.codeBooks[look.partbooks[partword[l][k]][s]];
98 if (stagebook != null) {
99 stagebook.readVvAdd(vectors0, vectors1, left, right, source, offset, samplesPerPartition);
100 }
101 }
102 }
103 }
104 }
105
106 }
107
108 }
109 }