* moved "binPlayers" into libEmbedVideo (more modular folder layout)
[lhc/web/wiklou.git] / js2 / mwEmbed / libEmbedVideo / binPlayers / omtk-fx / src / as / org / omtk / vorbis / Mapping0.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 org.omtk.util.BitByteArray;
23
24 public class Mapping0 extends Mapping {
25
26 private var _magnitudes:Vector.<int>;
27 private var _angles:Vector.<int>;
28 private var _mux:Vector.<int>;
29 private var _submapFloors:Vector.<int>;
30 private var _submapResidues:Vector.<int>;
31
32 public function Mapping0(stream:VorbisStream, source:BitByteArray, header:SetupHeader) {
33
34 var i:int;
35 var j:int;
36
37 var submaps:int = 1;
38
39 if (source.readBit()) {
40 submaps = source.readUnsignedBitwiseInt(4) + 1;
41 }
42
43 var channels:int = stream.identificationHeader.channels;
44 var ilogChannels:int = Util.ilog(channels - 1);
45
46 if (source.readBit()) {
47 var couplingSteps:int = source.readUnsignedBitwiseInt(8) + 1;
48 _magnitudes = new Vector.<int>(couplingSteps);
49 _angles = new Vector.<int>(couplingSteps);
50
51 for (i = 0; i < couplingSteps; i++) {
52 magnitudes[i] = source.readUnsignedBitwiseInt(ilogChannels);
53 angles[i] = source.readUnsignedBitwiseInt(ilogChannels);
54 if (magnitudes[i] == angles[i] || magnitudes[i] >= channels
55 || angles[i] >= channels) {
56 throw new Error("The channel magnitude and/or angle mismatch.");
57 }
58 }
59 } else {
60 _magnitudes = Vector.<int>([]);
61 _angles = Vector.<int>([]);
62 }
63
64 if (source.readUnsignedBitwiseInt(2) != 0) {
65 throw new Error("A reserved mapping field has an invalid value.");
66 }
67
68 _mux = new Vector.<int>(channels);
69 if (submaps > 1) {
70 for (i = 0; i < channels; i++) {
71 _mux[i] = source.readUnsignedBitwiseInt(4);
72 if (_mux[i] > submaps) {
73 throw new Error("A mapping mux value is higher than the number of submaps");
74 }
75 }
76 } else {
77 for (i = 0; i < channels; i++) {
78 _mux[i] = 0;
79 }
80 }
81
82 _submapFloors = new Vector.<int>(submaps);
83 _submapResidues = new Vector.<int>(submaps);
84
85 var floorCount:int = header.floors.length;
86 var residueCount:int = header.residues.length;
87
88 for (i = 0; i < submaps; i++) {
89 source.readUnsignedBitwiseInt(8); // discard time placeholder
90 _submapFloors[i] = source.readUnsignedBitwiseInt(8);
91 _submapResidues[i] = source.readUnsignedBitwiseInt(8);
92
93 if (_submapFloors[i] > floorCount) {
94 throw new Error("A mapping floor value is higher than the number of floors.");
95 }
96
97 if (_submapResidues[i] > residueCount) {
98 throw new Error("A mapping residue value is higher than the number of residues.");
99 }
100 }
101 }
102
103 public override function get type():int {
104 return 0;
105 }
106
107 public override function get couplingSteps():int {
108 return _angles.length;
109 }
110
111 public override function get submaps():int {
112 return _submapFloors.length;
113 }
114
115 public override function get angles():Vector.<int> {
116 return _angles;
117 }
118
119 public override function get magnitudes():Vector.<int> {
120 return _magnitudes;
121 }
122
123 public override function get mux():Vector.<int> {
124 return _mux;
125 }
126
127 public override function get submapFloors():Vector.<int> {
128 return _submapFloors;
129 }
130
131 public override function get submapResidues():Vector.<int> {
132 return _submapResidues;
133 }
134 }
135
136 }