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 flash.utils.Dictionary;
23 import org.omtk.util.BitByteArray;
25 public class Residue {
27 private var _begin:int;
29 private var _partitionSize:int;
30 private var _classifications:int;
31 private var _classBook:int;
32 private var _cascade:Vector.<int>;
33 private var _books:Vector.<Vector.<int>>;
35 private var _looks:Dictionary;
38 public function Residue(source:BitByteArray, header:SetupHeader) {
40 _begin = source.readUnsignedBitwiseInt(24);
41 _end = source.readUnsignedBitwiseInt(24);
42 _partitionSize = source.readUnsignedBitwiseInt(24) + 1;
43 _classifications = source.readUnsignedBitwiseInt(6) + 1;
44 _classBook = source.readUnsignedBitwiseInt(8);
46 _cascade = new Vector.<int>(classifications);
52 for (i = 0; i < classifications; i++) {
56 lowBits = source.readUnsignedBitwiseInt(3);
57 if (source.readBit()) {
58 highBits = source.readUnsignedBitwiseInt(5);
60 _cascade[i] = (highBits << 3) | lowBits;
61 acc += Util.icount(cascade[i]);
64 _books = new Vector.<Vector.<int>>(classifications);
66 for (i = 0; i < classifications; i++) {
67 books[i] = new Vector.<int>(8);
68 for (j = 0; j < 8; j++) {
69 if ((cascade[i] & (1 << j)) != 0) {
70 books[i][j] = source.readUnsignedBitwiseInt(8);
71 if (books[i][j] > header.codeBooks.length) {
73 "Reference to invalid codebook entry in residue header.");
79 _looks = new Dictionary();
82 public static function createInstance(source:BitByteArray, header:SetupHeader):Residue {
84 var type:int = source.readUnsignedBitwiseInt(16);
87 return new Residue2(source, header);
89 throw new Error("Residue type " + type + " is not supported.");
93 public function decodeResidue(
94 vorbis:VorbisStream, source:BitByteArray,
96 doNotDecodeFlags:Vector.<Boolean>, vectors0:Vector.<Number>, vectors1:Vector.<Number>):void {
98 throw new IllegalOperationError("not implemented");
102 public function getLook(stream:VorbisStream, key:Mode):Look {
103 var look:Look = _looks[key];
105 look = new Look(stream, this, key);
108 return new Look(stream, this, key);//look;
112 public function get begin():int {
116 public function get end():int {
120 public function get partitionSize():int {
121 return _partitionSize;
124 public function get classifications():int {
125 return _classifications;
128 public function get classBook():int {
132 public function get cascade():Vector.<int> {
136 public function get books():Vector.<Vector.<int>> {