VorbisInfoFloor UnpackFloor0(OggBitStream input) { var info = new VorbisInfoFloor(); int order = input.ReadBits(8); int rate = input.ReadBits(16); int barkmap = input.ReadBits(16); int ampbits = input.ReadBits(6); int ampdB = input.ReadBits(8); int numbooks = input.ReadBits(4) + 1; if (order < 1 || rate < 1 || barkmap < 1 || numbooks < 1) { return(null); } for (int j = 0; j < numbooks; ++j) { int books = input.ReadByte(); if (books < 0 || books >= CodecSetup.Books) { return(null); } } return(info); }
VorbisInfoFloor UnpackFloor1(OggBitStream input) { int max_class = -1; var info = new VorbisInfoFloor(); // read partitions int partitions = input.ReadBits(5); // only 0 to 31 legal var partition_class = new int[partitions]; for (int j = 0; j < partitions; ++j) { partition_class[j] = input.ReadBits(4); // only 0 to 15 legal if (partition_class[j] < 0) { return(null); } if (max_class < partition_class[j]) { max_class = partition_class[j]; } } // read partition classes var class_dim = new int[max_class + 1]; for (int j = 0; j < max_class + 1; ++j) { class_dim[j] = input.ReadBits(3) + 1; // 1 to 8 int class_subs = input.ReadBits(2); // 0,1,2,3 bits if (class_subs < 0) { return(null); } if (class_subs > 0) { input.ReadBits(8); // class_book } for (int k = 0; k < (1 << class_subs); ++k) { int class_subbook = input.ReadBits(8) - 1; // info.class_subbook[j][k] } } // read the post list int mult = input.ReadBits(2) + 1; // only 1,2,3,4 legal now int rangebits = input.ReadBits(4); if (rangebits < 0) { return(null); } int count = 0; // var postlist = new int[VorbisInfoFloor.Posit + 2]; for (int j = 0, k = 0; j < partitions; ++j) { count += class_dim[partition_class[j]]; if (count > VorbisInfoFloor.Posit) { return(null); } for (; k < count; ++k) { int t = input.ReadBits(rangebits); if (t < 0 || t >= (1 << rangebits)) { return(null); } // postlist[k+2] = t; } } // postlist[0] = 0; // postlist[1] = 1<<rangebits; // don't allow repeated values in post list as they'd result in // zero-length segments /* * var indices = Enumerable.Range (0, count+2).OrderBy (i => postlist[i]).ToArray(); * for (int j = 1; j < count+2; j++) * if(postlist[indices[j-1]] == postlist[indices[j]]) * return null; */ return(info); }