3 Copyright 2008 Tor-Einar Jarnbjo
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org.omtk.vorbis {
21 import flash.errors.IllegalOperationError;
22 import org.omtk.util.BitByteArray;
24 public class Mapping0 extends Mapping {
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>;
32 public function Mapping0(stream:VorbisStream, source:BitByteArray, header:SetupHeader) {
39 if (source.readBit()) {
40 submaps = source.readUnsignedBitwiseInt(4) + 1;
43 var channels:int = stream.identificationHeader.channels;
44 var ilogChannels:int = Util.ilog(channels - 1);
46 if (source.readBit()) {
47 var couplingSteps:int = source.readUnsignedBitwiseInt(8) + 1;
48 _magnitudes = new Vector.<int>(couplingSteps);
49 _angles = new Vector.<int>(couplingSteps);
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.");
60 _magnitudes = Vector.<int>([]);
61 _angles = Vector.<int>([]);
64 if (source.readUnsignedBitwiseInt(2) != 0) {
65 throw new Error("A reserved mapping field has an invalid value.");
68 _mux = new Vector.<int>(channels);
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");
77 for (i = 0; i < channels; i++) {
82 _submapFloors = new Vector.<int>(submaps);
83 _submapResidues = new Vector.<int>(submaps);
85 var floorCount:int = header.floors.length;
86 var residueCount:int = header.residues.length;
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);
93 if (_submapFloors[i] > floorCount) {
94 throw new Error("A mapping floor value is higher than the number of floors.");
97 if (_submapResidues[i] > residueCount) {
98 throw new Error("A mapping residue value is higher than the number of residues.");
103 public override function get type():int {
107 public override function get couplingSteps():int {
108 return _angles.length;
111 public override function get submaps():int {
112 return _submapFloors.length;
115 public override function get angles():Vector.<int> {
119 public override function get magnitudes():Vector.<int> {
123 public override function get mux():Vector.<int> {
127 public override function get submapFloors():Vector.<int> {
128 return _submapFloors;
131 public override function get submapResidues():Vector.<int> {
132 return _submapResidues;