コード例 #1
0
        private void ReadFrameFooter()
        {
            ushort crc16 = bitReader.Complete();

            bitReader = null;

            byte[] data        = ReadExactly(2);
            int    footerCrc16 = data[0] << 8 | data[1];

            if (crc16 != footerCrc16)
            {
                throw new FlacException("Invalid frame footer CRC16");
            }

            subframeIndex = 0;

            this.recordType = FlacRecordType.FrameFooter;
        }
コード例 #2
0
ファイル: FlacReader.cs プロジェクト: RyosukeOtani/FlacBox
        public byte[] ReadFrameRawData()
        {
            if (recordType != FlacRecordType.Frame)
            {
                throw new FlacException("Cannot read non-frame data");
            }

            MemoryStream ms = new MemoryStream();

            ms.Write(lastFrameHeaderData, 0, lastFrameHeaderData.Length);

            // replace bitReader
            ushort currentCrc16 = bitReader.Complete();

            bitReader = new FlacBitStreamReader(
                new SinkedStream(BaseStream, ms), currentCrc16);

            // read subframes
            for (int i = 0; i < FrameChannelCount; i++)
            {
                ReadSubframe();
                SkipSampleValues();
            }
            bitReader.Complete();
            bitReader = null;

            // read footer
            byte[] crc16 = ReadExactly(2);
            recordType = FlacRecordType.FrameFooter;

            int frameDataLength = checked ((int)ms.Length);

            ms.Write(crc16, 0, crc16.Length);

            byte[] frameData = ms.ToArray();

            // check CRC16
            ushort dataCrc16 = CrcUtils.Crc16(0, frameData, 0, frameDataLength);
            int    footerCrc = (crc16[0] << 8) | crc16[1];

            if (dataCrc16 != footerCrc)
            {
                throw new FlacException("Invalid frame footer CRC16");
            }

            return(frameData);
        }
コード例 #3
0
ファイル: FlacReader.cs プロジェクト: Sojaner/FlacBox
        public byte[] ReadFrameRawData()
        {
            if(recordType != FlacRecordType.Frame)
                throw new FlacException("Cannot read non-frame data");

            MemoryStream ms = new MemoryStream();
            ms.Write(lastFrameHeaderData, 0, lastFrameHeaderData.Length);

            // replace bitReader
            ushort currentCrc16 = bitReader.Complete();
            bitReader = new FlacBitStreamReader(
                new SinkedStream(BaseStream, ms), currentCrc16);

            // read subframes
            for (int i = 0; i < FrameChannelCount; i++)
            {
                ReadSubframe();
                SkipSampleValues();
            }
            bitReader.Complete();
            bitReader = null;

            // read footer
            byte[] crc16 = ReadExactly(2);
            recordType = FlacRecordType.FrameFooter;

            int frameDataLength = checked((int)ms.Length);
            ms.Write(crc16, 0, crc16.Length);

            byte[] frameData = ms.ToArray();

            // check CRC16
            ushort dataCrc16 = CrcUtils.Crc16(0, frameData, 0, frameDataLength);
            int footerCrc = (crc16[0] << 8) | crc16[1];
            if(dataCrc16 != footerCrc)
                throw new FlacException("Invalid frame footer CRC16");

            return frameData;
        }