public override void ReadSetupData( VorbisCodec codec, BitReader reader ) { int residueBegin = reader.ReadBits( 24 ); int residueEnd = reader.ReadBits( 24 ); int partitionSize = reader.ReadBits( 24 ) + 1; int classifications = reader.ReadBits( 6 ) + 1; int classbook = reader.ReadBits( 8 ); byte[] residueCascade = new byte[classifications]; for( int i = 0; i < residueCascade.Length; i++ ) { int highBits = 0; int lowBits = reader.ReadBits( 3 ); if( reader.ReadBit() == 1 ) highBits = reader.ReadBits( 5 ); residueCascade[i] = (byte)( lowBits | ( highBits << 3 ) ); } byte[][] bookNumbers = new byte[classifications][]; for( int i = 0; i < bookNumbers.Length; i++ ) { byte[] nums = new byte[8]; int cascade = residueCascade[i]; for( int j = 0; j < nums.Length; j++ ) { if( ( cascade & ( 1 << j ) ) != 0 ) { nums[j] = (byte)reader.ReadBits( 8 ); } } bookNumbers[i] = nums; } }
public override object ApplyToFrame( VorbisCodec codec, BitReader reader, object args ) { step2Flag[0] = true; step2Flag[1] = true; finalY[0] = yList[0]; finalY[1] = yList[1]; SynthesiseAmplitudeValues(); return SynthesiseCurve( (int)args ); }
public override void ReadSetupData( VorbisCodec codec, BitReader reader ) { submaps = reader.ReadBit() == 0 ? 1 : reader.ReadBits( 4 ) + 1; couplingSteps = reader.ReadBit() == 0 ? 0 : reader.ReadBits( 8 ) + 1; int channels = codec.channels; if( couplingSteps > 0 && channels > 1 ) { magnitude = new byte[couplingSteps]; angle = new byte[couplingSteps]; int bits = VorbisUtils.iLog( channels - 1 ); for( int i = 0; i < couplingSteps; i++ ) { magnitude[i] = (byte)reader.ReadBits( bits ); angle[i] = (byte)reader.ReadBits( bits ); } } if( reader.ReadBits( 2 ) != 0 ) throw new InvalidDataException( "Reserved field not 0!" ); if( submaps > 1 ) { mux = new byte[channels]; for( int i = 0; i < mux.Length; i++ ) mux[i] = (byte)reader.ReadBits( 4 ); } else { mux = new byte[channels]; } submapFloor = new byte[submaps]; submapResidue = new byte[submaps]; for( int i = 0; i < submaps; i++ ) { reader.ReadBits( 8 ); // unused time configuration submapFloor[i] = (byte)reader.ReadBits( 8 ); submapResidue[i] = (byte)reader.ReadBits( 8 ); } }
public override void ReadSetupData( VorbisCodec codec, BitReader reader ) { blockFlag = reader.ReadBit(); int windowType = reader.ReadBits( 16 ); int transformType = reader.ReadBits( 16 ); modeMapping = reader.ReadBits( 8 ); if( windowType > 0 || transformType > 0 ) throw new InvalidDataException( "windowType and/or transformType not 0" ); }
public override object ReadPerPacketData( VorbisCodec codec, BitReader reader, object args ) { bool emptyThisFrame = reader.ReadBit() == 0; if( emptyThisFrame ) return true; int offset = 0; yList[offset++] = reader.ReadBits( elems01Bits ); yList[offset++] = reader.ReadBits( elems01Bits ); for( int i = 0; i < partitions; i++ ) { int classNum = partitionClassList[i]; int cDim = classDimensions[classNum]; int cBits = classSubclasses[classNum]; int cSub = (1 << cBits) - 1; int cVal = 0; if( cBits > 0 ) { int bookNum = classMasterbooks[classNum]; Codebook codebook = codec.codebookConfigs[bookNum]; cVal = codebook.GetScalarContext( reader ); } for( int j = 0; j < cDim; j++ ) { int book = subclassBooks[classNum][cVal & cSub]; cVal = (int)((uint)cVal >> cBits); if( book != 0xFF ) { Codebook codebook = codec.codebookConfigs[book]; yList[offset++] = codebook.GetScalarContext( reader ); } else { yList[offset++] = 0; } } } return false; }
public override void ReadSetupData( VorbisCodec codec, BitReader reader ) { throw new NotSupportedException( "Floor0 not supported." ); }
public override void ReadSetupData( VorbisCodec codec, BitReader reader ) { partitions = reader.ReadBits( 5 ); int maximumClass = -1; partitionClassList = new byte[partitions]; for( int i = 0; i < partitionClassList.Length; i++ ) { int element = reader.ReadBits( 4 ); if( element > maximumClass ) { maximumClass = element; } partitionClassList[i] = (byte)element; } classDimensions = new byte[maximumClass + 1]; classSubclasses = new byte[maximumClass + 1]; classMasterbooks = new byte[maximumClass + 1]; subclassBooks = new byte[maximumClass + 1][]; for( int i = 0; i <= maximumClass; i++ ) { classDimensions[i] = (byte)( reader.ReadBits( 3 ) + 1 ); int subclass = reader.ReadBits( 2 ); classSubclasses[i] = (byte)subclass; if( subclass > 0 ) { classMasterbooks[i] = (byte)reader.ReadBits( 8 ); } int subclassMax = 1 << subclass; byte[] books = new byte[subclassMax]; for( int j = 0; j < books.Length; j++ ) { books[j] = (byte)(reader.ReadBits( 8 ) - 1); } subclassBooks[i] = books; } multiplier = reader.ReadBits( 2 ) + 1; int rangeBits = reader.ReadBits( 4 ); CalcFloor1Values(); xList = new int[floor1Values]; int xListIndex = 2; xList[1] = 1 << rangeBits; for( int i = 0; i < partitions; i++ ) { int classNumber = partitionClassList[i]; for( int j = 0; j < classDimensions[classNumber]; j++ ) { xList[xListIndex++] = reader.ReadBits( rangeBits ); } } int range = rangeElements[multiplier - 1]; elems01Bits = VorbisUtils.iLog( range - 1 ); yList = new int[floor1Values]; step2Flag = new bool[floor1Values]; finalY = new int[floor1Values]; floor = new int[floor1Values]; }
public override object ReadPerPacketData( VorbisCodec codec, BitReader reader, object data ) { throw new NotSupportedException( "Floor0 not supported." ); }
public virtual object ApplyToFrame( VorbisCodec codec, BitReader reader, object args ) { return null; }
public abstract void ReadSetupData( VorbisCodec codec, BitReader reader );
public virtual object ReadPerPacketData( VorbisCodec codec, BitReader reader, object args ) { return null; }
public override void ReadSetupData( VorbisCodec codec, BitReader reader ) { int syncPattern = reader.ReadBits( 24 ); if( syncPattern != 0x564342 ) { throw new InvalidDataException( "Invalid codebook sync pattern: " + syncPattern ); } int dimensions = reader.ReadBits( 16 ); int entries = reader.ReadBits( 24 ); int ordered = reader.ReadBit(); codewordLengths = new byte[entries]; if( ordered == 0 ) { int sparse = reader.ReadBit(); for( int i = 0; i < entries; i++ ) { if( sparse == 0 || ( reader.ReadBit() == 1 ) ) { codewordLengths[i] = (byte)( reader.ReadBits( 5 ) + 1 ); } } } else { int curEntry = 0; int curLength = reader.ReadBits( 5 ) + 1; while( curEntry < entries ) { int number = reader.ReadBits( VorbisUtils.iLog( entries - curEntry ) ); for( int i = curEntry; i < curEntry + number; i++ ) { codewordLengths[i] = (byte)curLength; } curEntry += number; curLength++; } } BuildHuffmanTree(); int lookupType = reader.ReadBits( 4 ); if( lookupType == 1 || lookupType == 2 ) { float minValue = VorbisUtils.Unpack( reader.ReadBitsU( 32 ) ); float deltaValue = VorbisUtils.Unpack( reader.ReadBitsU( 32 ) ); int valueBits = reader.ReadBits( 4 ) + 1; int sequenceP = reader.ReadBit(); int lookupValues = 0; if( lookupType == 1 ) { lookupValues = VorbisUtils.lookup1_values( entries, dimensions ); } else { lookupValues = entries * dimensions; } multiplicands = new ushort[lookupValues]; for( int i = 0; i < multiplicands.Length; i++ ) { multiplicands[i] = (ushort)reader.ReadBits( valueBits ); } VQ = new float[entries][]; for( int i = 0; i < entries; i++ ) { float[] vector = new float[dimensions]; if( lookupType == 1 ) { float last = 0; int indexDivisor = 1; for( int j = 0; j < dimensions; j++ ) { int multiplicandOffset = ( i / indexDivisor ) % lookupValues; vector[j] = multiplicands[multiplicandOffset] * deltaValue + minValue + last; if( sequenceP != 0 ) last = vector[j]; indexDivisor *= lookupValues; } } else { float last = 0; int mulitiplicandOffset = i * dimensions; for( int j = 0; j < dimensions; j++ ) { vector[j] = multiplicands[mulitiplicandOffset] * deltaValue + minValue + last; if( sequenceP != 0 ) last = vector[j]; mulitiplicandOffset++; } } VQ[i] = vector; } } }
public override void ReadMetadata() { reader = new PrimitiveReader( stream ); // TODO: Ogg can encapsulate far more than just vorbis. // We need to implement codec detection! vorbis = new VorbisCodec( this ); vorbis.ReadSetupData(); }