예제 #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
        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
        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;
        }