public VorbisCodebook(ByteArray aByteArray) { count = aByteArray.ReadByte() + 1; Logger.LogWarning("Vorbis Codebook Count:" + count); headerArray = new CodebookHeader[count]; for (int i = 0; i < count; i++) { headerArray[i] = new CodebookHeader(aByteArray); } }
public void DecodePacket1(CodebookHeader aCodebookHeader, double[] a, ByteArray aByteArray, int offset) { int n = ( int )partitionSizeAdd1; int i = 0; while (i < n) { //Logger.LogError( "aCodebookHeader.ReadVv( aByteArray ):" + i ); double[] entry_temp = aCodebookHeader.ReadVv(aByteArray); for (int j = 0; j < aCodebookHeader.dimensions; j++) { a[offset + i] += entry_temp[j]; i++; } } }
private void DecodePacket0(Identification aOggHeaderIdentification, Setup aOggHeaderSetup) { CodebookHeader lCodebookHeader = aOggHeaderSetup.codebook.headerArray[classbook]; // Check 61. int n = ( int )partitionSizeAdd1; //[v] is the residue vector //[offset] is the beginning read ofset in [v] int step = n / lCodebookHeader.dimensions; for (int i = 0; i < step; i++) { //vector[entry_temp] = 0;//read vector from packet using current codebook in VQ context for (int j = 0; j < lCodebookHeader.dimensions; j++) { //vector [v] element ([offset]+[i]+[j]*[step]) = vector [v] element ([offset]+[i]+[j]*[step]) + vector [entry\_temp] element [j] } } }
public void DecodePacket2(CodebookHeader aCodebookHeader, int aAudioChannels, double[][] a, ByteArray aByteArray, int offset, int aCh, Byte[] do_not_decode_flag) { for (int i = 0; i < aCh; i++) { if (do_not_decode_flag[i] == 1) { Logger.LogError("do_not_decode_flag:" + i); } } double[] lValueArray = new double[aAudioChannels * a[0].Length]; DecodePacket1(aCodebookHeader, lValueArray, aByteArray, offset); for (int i = 0; i < a[0].Length; i++) { for (int j = 0; j < aAudioChannels; j++) { a[j][i] += lValueArray[i * aAudioChannels + j]; } } }
private int DecodePacket1(ByteArray aByteArray, CodebookHeader[] aCodebookHeaderArray) { Logger.LogWarning("■DecodePacket1"); Byte lNonzero = aByteArray.ReadBitsAsByte(1); if (lNonzero == 0x01) { Logger.LogWarning("Nonzero"); UInt16[] vector = { 256, 128, 86, 64 }; range = vector[multiplier1Add1 - 1]; Logger.LogWarning("Range" + range); //Logger.LogWarning( "iLog:" + ilog( ( UInt32 )( range - 1 ) ) ); Logger.LogWarning("Count:" + xList1.Count); floorYList1 = new UInt16[xList1.Count]; floorYList1[0] = aByteArray.ReadBitsAsUInt16(ilog(( UInt32 )(range - 1))); floorYList1[1] = aByteArray.ReadBitsAsUInt16(ilog(( UInt32 )(range - 1))); //Logger.LogError( "xList1,floorYList1[0]:" + xList1[0] + "," + floorYList1[0] ); //Logger.LogError( "xList1,floorYList1[1]:" + xList1[1] + "," + floorYList1[1] ); int offset = 2; for (int i = 0; i < partitions1; i++) { Byte lClass = partitionClassList1[i]; int cdim = classDimensions1Add1[lClass]; Byte cbits = classSubClasses1[lClass]; int csub = ( int )Math.Pow(2, cbits) - 1; UInt32 cval = 0; if (cbits > 0) { CodebookHeader lCodebookHeader = aCodebookHeaderArray[classMasterbooks1[lClass]]; int lHuffman = lCodebookHeader.huffmanRoot.Read(aByteArray); //Logger.LogError( "Huffman1:" + lHuffman ); cval = ( UInt32 )lHuffman; } for (int j = 0; j < cdim; j++) { int book = subClassBooks1Sub1[lClass][cval & csub]; cval >>= cbits; if (book >= 0) { CodebookHeader lCodebookHeader = aCodebookHeaderArray[book]; int lHuffman = lCodebookHeader.huffmanRoot.Read(aByteArray); //Logger.LogError( "Huffman2:" + lHuffman ); floorYList1[j + offset] = ( UInt16 )lHuffman; } else { floorYList1[j + offset] = 0; } //Logger.LogError( "xList1,floorYList1[" + ( j + offset ) + "]:" + xList1[j + offset] + "," + floorYList1[j + offset] ); } offset += cdim; } } else { Logger.LogError("Zero"); return(1); } return(0); }
public void DecodePacket(ByteArray aByteArray, int aAudioChannels, CodebookHeader[] aCodebookHeaderArray, int n, int aCh, Byte[] do_not_decode_flag, double[][] aResidueArray) { //Logger.LogError( "■DecodePacket:" + classbook ); CodebookHeader lCodebookHeader = aCodebookHeaderArray[classbook]; int actual_size = n / 2; if (types == 0x0002) { actual_size *= aCh; aCh = 1; } // Maximum. /* * int limit_residue_begin = actual_size; * * if( begin > actual_size ) * { * limit_residue_begin = ( int )begin; * } * * int limit_residue_end = actual_size; * * if( end > actual_size ) * { * limit_residue_end = ( int )end; * } */ // Miminam. int limit_residue_begin = ( int )begin; if (actual_size < begin) { limit_residue_begin = actual_size; } int limit_residue_end = ( int )end; if (actual_size < end) { limit_residue_end = actual_size; } Logger.LogDebug("■actual_size,.begin,end:" + actual_size + "," + begin + "," + end); int classwords_per_codeword = lCodebookHeader.dimensions; int n_to_read = limit_residue_end - limit_residue_begin; int partitions_to_read = ( int )(n_to_read / partitionSizeAdd1); //Logger.LogError( "classwords_per_codeword:" + classwords_per_codeword ); //Logger.LogError( "partitionSizeAdd1:" + partitionSizeAdd1 ); //Logger.LogError( "partitions_to_read:" + partitions_to_read ); int[][] lClassifications = new int[aCh][]; for (int j = 0; j < aCh; j++) { lClassifications[j] = new int[partitions_to_read + classwords_per_codeword]; } if (n_to_read <= 0) { Logger.LogError("■there is no residue to decode."); return; } for (int pass = 0; pass < 8; pass++) { int partition_count = 0; while (partition_count < partitions_to_read) { if (pass == 0) { for (int j = 0; j < aCh; j++) { if (do_not_decode_flag[j] == 0x00) { int temp = lCodebookHeader.huffmanRoot.Read(aByteArray); //Logger.LogWarning( "temp:" + temp ); for (int i = classwords_per_codeword - 1; i >= 0; i--) { lClassifications[j][i + partition_count] = temp % classificationsAdd1; temp /= classificationsAdd1; //Logger.LogError( "classifications[" + j + "][" + ( i + partition_count ) + "]:" + classifications[j][i + partition_count] ); } } } } for (int i = 0; i < classwords_per_codeword && partition_count < partitions_to_read; i++) { for (int j = 0; j < aCh; j++) { if (do_not_decode_flag[j] == 0x00) { //Logger.LogError( "classifications[" + j + "][" + ( partition_count ) + "]:" + classifications[j][partition_count] ); int vqclass = lClassifications[j][partition_count]; UInt16 vqbook = books[vqclass][pass]; if (vqbook != 0xFFFF /*'unused'*/) { switch (types) { case 0: Logger.LogDebug("■case 0"); //DecodePacket0( aOggHeaderIdentification, aOggHeaderSetup, aResidueNumber ); break; case 1: Logger.LogDebug("■case 1"); //DecodePacket1( aOggHeaderIdentification, aOggHeaderSetup, aResidueNumber ); break; case 2: int offset = ( int )(limit_residue_begin + partition_count * partitionSizeAdd1); //Logger.LogError( "pass,partition_count,i:" + pass + "," + partition_count + "," + i ); //Logger.LogError( "■ch:" + aCh ); CodebookHeader llCodebookHeader = aCodebookHeaderArray[vqbook]; DecodePacket2(llCodebookHeader, aAudioChannels, aResidueArray, aByteArray, offset, aCh, do_not_decode_flag); //llCodebookHeader.ReadVvAdd( aOggHeaderIdentification.a, aByteArray, offset, ( int )partitionSizeAdd1 ); //DecodePacket2( aOggHeaderIdentification, aOggHeaderSetup, aResidueNumber ); break; default: Logger.LogDebug("■default"); return; } } else { //Logger.LogError( "vqbook == 0xFFFF,pass,partition_count,i:" + pass + "," + partition_count + "," + i ); } } } partition_count++; } } } }