private static MetadataBlock GetBlock(MetadataBlockHeader header) { MetadataBlock block; switch (header.BlockType) { case 0: { block = new MetadataBlockStreamInfo(header); break; } case 1: { block = new MetadataBlockPadding(header); break; } case 2: case 3: case 4: case 5: case 6: { // we won't read any block except streaminfo // skip over them all. // think of them as padding. block = new MetadataBlockPadding(header); break; } case 127: { throw new FlacFormatInvalidException(); } default: { throw new FlacFormatReservedException(); } } return block; }
protected override void ProcessMetaInformation(MetadataBlock metadataBlock) { MetadataBlockStreamInfo readStreamInfo = metadataBlock as MetadataBlockStreamInfo; if (readStreamInfo != null) { streamInfo_ = readStreamInfo; readStreamInfo.Write(outStream_); } }
public void Decode() { signature_ = new Signature(); signature_.Read(this); streamInfo_ = MetadataBlock.New(this) as MetadataBlockStreamInfo; Validation.IsValid(streamInfo_ != null); MetadataBlock block = streamInfo_; if (MetadataRead != null) { MetadataRead(streamInfo_); } while (!block.Header.IsLastMetadataBlock) { block = MetadataBlock.New(this); if (MetadataRead != null) { MetadataRead(block); } } while (!reader_.Done) { Frame frame = new Frame(); long offset = reader_.Debug_BytesRead; frame.ReadHeader(this); bool haveRead = false; if (BeforeFrameDataRead != null) { FrameCallbackArgs a = new FrameCallbackArgs(frame, this); a.Offset = offset; BeforeFrameDataRead(a); if (!a.ContinueDecoding) { break; } haveRead = a.HaveReadData; } if (!haveRead) { frame.ReadData(this); frame.ReadFooter(this); } } }
public void Read(FlacStream stream) { stream.Reader.Crc.Start(); streamInfo_ = stream.StreamInfo; Validation.IsValid(stream.Reader.ReadBitsAsShort(SYNC_CODE_BITS_COUNT) == SYNC_CODE); // reserved sbyte reserved0 = stream.Reader.ReadBit(); Validation.IsReserved(reserved0 == 0); blockingStrategy_ = stream.Reader.ReadBit(); blockSizeInInterChannelSamples_ = stream.Reader.ReadBitsAsSByte(BLOCK_SIZE_BITS_COUNT); sampleRate_ = stream.Reader.ReadBitsAsSByte(SAMPLE_RATE_BITS_COUNT); channelAssignment_ = stream.Reader.ReadBitsAsSByte(CHANNELS_BITS_COUNT); bitsPerSample_ = stream.Reader.ReadBitsAsSByte(BPS_BITS_COUNT); // reserved sbyte reserved1 = stream.Reader.ReadBit(); Validation.IsReserved(reserved1 == 0); long pos = stream.Reader.Debug_BytesRead; DecodeSampleNumber(stream); sampleIdSize_ = (int)(stream.Reader.Debug_BytesRead - pos); if (blockSizeInInterChannelSamples_ == 6) { blockSizeHint_ = stream.Reader.ReadByte(); } else if (blockSizeInInterChannelSamples_ == 7) { blockSizeHint_ = stream.Reader.ReadUShort(); } else { // is zero } if (sampleRate_ == 0xc) { sampleRateHint_ = stream.Reader.ReadByte(); } else if (sampleRate_ == 0xd || sampleRate_ == 0xe) { sampleRateHint_ = stream.Reader.ReadUShort(); } else { // is zero } byte crc = stream.Reader.Crc.GetCRC8(); crc_ = stream.Reader.ReadByte(); Validation.IsValid(crc_ == crc); }
private void ReadHeader() { outStream_.Encode(); inStream_.Reader.Seek(4); MetadataBlockHeader h = new MetadataBlockHeader(); h.Read(inStream_); MetadataBlockStreamInfo si = new MetadataBlockStreamInfo(h); si.Read(inStream_); h.IsLastMetadataBlock = false; si.MinBlockSize = track_.MinBlockSize; si.MaxBlockSize = track_.MaxBlockSize; si.MinFrameSize = track_.MinFrameSize; si.MaxFrameSize = track_.MaxFrameSize; si.TotalSamples = track_.TotalSamples; si.Checksum[0] = 0; si.Checksum[1] = 0; si.Checksum[2] = 0; si.Checksum[3] = 0; si.Write(outStream_); long pos = outStream_.FileStream.Position; h = new MetadataBlockHeader(); h.IsLastMetadataBlock = true; h.BlockLengthInBytes = track_.Metadata.block.Length; h.BlockType = MetadataBlockHeader.METADATA_BLOCK_VORBIS_COMMENT; MetadataBlockVorbisComment vc = new MetadataBlockVorbisComment(h, track_.Metadata.block); vc.Write(outStream_); Debug.Assert(outStream_.FileStream.Position == pos + h.BlockLengthInBytes + 4); outStream_.FileStream.Flush(); header_ = ReadAllBytes(); }