Exemplo n.º 1
0
        private IEnumerator <ArraySegment <byte> > ReadData(CdromReader reader, uint diskOffset, uint sectorCount, bool includeRiffHeader)
        {
            try
            {
                uint totalBytes = (uint)CdromReader.SectorSize * sectorCount;

                if (includeRiffHeader)
                {
                    const uint RiffHeaderSize            = 0x28;
                    const uint RiffHeaderSizeWithoutSize = 0x24;

                    streamTotalLength = totalBytes + RiffHeaderSize;

                    byte[] waveHeader = new byte[] {
                        0x52, 0x49, 0x46, 0x46, 0x24, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45,
                        0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
                        0x44, 0xAC, 0x00, 0x00, 0x10, 0xB1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00,
                        0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00
                    };

                    Array.Copy(BitConverter.GetBytes(totalBytes + RiffHeaderSizeWithoutSize), 0, waveHeader, 0x04, 4);
                    Array.Copy(BitConverter.GetBytes(totalBytes), 0, waveHeader, 0x28, 4);

                    yield return(new ArraySegment <byte>(waveHeader));
                }
                else
                {
                    streamTotalLength = totalBytes;
                }

                const uint BufferSizeInSectors = 20;
                const int  BufferSize          = (int)BufferSizeInSectors * CdromReader.SectorSize;
                byte[]     buffer   = new byte[BufferSize];
                uint       position = 0;
                while (position + BufferSizeInSectors < sectorCount)
                {
                    reader.ReadSectors(diskOffset + position, BufferSizeInSectors, buffer);
                    yield return(new ArraySegment <byte>(buffer));

                    position += BufferSizeInSectors;
                }

                uint tail = sectorCount - position;
                reader.ReadSectors(diskOffset + position, tail, buffer);
                yield return(new ArraySegment <byte>(buffer, 0, (int)tail * CdromReader.SectorSize));
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 2
0
        private IEnumerator<ArraySegment<byte>> ReadData(CdromReader reader, uint diskOffset, uint sectorCount, bool includeRiffHeader)
        {
            try
            {
                uint totalBytes = (uint)CdromReader.SectorSize * sectorCount;

                if (includeRiffHeader)
                {
                    const uint RiffHeaderSize = 0x28;
                    const uint RiffHeaderSizeWithoutSize = 0x24;

                    streamTotalLength = totalBytes + RiffHeaderSize;

                    byte[] waveHeader = new byte[] {
                        0x52, 0x49, 0x46, 0x46, 0x24, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45,
                        0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
                        0x44, 0xAC, 0x00, 0x00, 0x10, 0xB1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00,
                        0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00 };

                    Array.Copy(BitConverter.GetBytes(totalBytes + RiffHeaderSizeWithoutSize), 0, waveHeader, 0x04, 4);
                    Array.Copy(BitConverter.GetBytes(totalBytes), 0, waveHeader, 0x28, 4);

                    yield return new ArraySegment<byte>(waveHeader);
                }
                else
                    streamTotalLength = totalBytes;

                const uint BufferSizeInSectors = 20;
                const int BufferSize = (int)BufferSizeInSectors * CdromReader.SectorSize;
                byte[] buffer = new byte[BufferSize];
                uint position = 0;
                while (position + BufferSizeInSectors < sectorCount)
                {
                    reader.ReadSectors(diskOffset + position, BufferSizeInSectors, buffer);
                    yield return new ArraySegment<byte>(buffer);
                    position += BufferSizeInSectors;
                }

                uint tail = sectorCount - position;
                reader.ReadSectors(diskOffset + position, tail, buffer);
                yield return new ArraySegment<byte>(buffer, 0, (int)tail * CdromReader.SectorSize);
            }
            finally
            {
                reader.Close();
            }
        }