コード例 #1
0
        private void parseWave(BinaryReader reader)
        {
            bool[] hasChunk = new bool[] { false, false, false };

            while (reader.BaseStream.Position < reader.BaseStream.Length - 4)
            {
                uint curChunk       = Shared.Swap(reader.ReadUInt32());
                uint curChunkLength = reader.ReadUInt32();
                long nextChunkPos   = reader.BaseStream.Position + curChunkLength;

                switch (curChunk)
                {
                case 0x52494646:     //RIFF
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        header.Read(reader);
                        hasChunk[0] = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                case 0x666d7420:     //fmt
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        fmt.Read(reader);
                        hasChunk[1] = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                case 0x64617461:     //data
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        data.Read(reader);
                        hasChunk[2] = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                case 0x736d706c:     //smpl
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        smpl.Read(reader);
                        hasSmpl = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                default:
                    reader.BaseStream.Seek(curChunkLength, SeekOrigin.Current);
                    break;
                }

                if (hasChunk[0] && hasChunk[1] && hasChunk[2] && hasSmpl)
                {
                    break;
                }
            }

            if (!(hasChunk[0] && hasChunk[1] && hasChunk[2]))
            {
                throw new Exception("Couldn't parse Wave file...");
            }
        }
コード例 #2
0
        private void ParseWave(BinaryReader reader)
        {
            bool[] flagArray = new bool[3];
            while (reader.BaseStream.Position < reader.BaseStream.Length - 4L)
            {
                uint num1   = Shared.Swap(reader.ReadUInt32());
                uint num2   = reader.ReadUInt32();
                long offset = reader.BaseStream.Position + num2;
                switch (num1)
                {
                case 1380533830:
                    try
                    {
                        reader.BaseStream.Seek(-8L, SeekOrigin.Current);
                        header.Read(reader);
                        flagArray[0] = true;
                        break;
                    }
                    catch
                    {
                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);
                        break;
                    }

                case 1684108385:
                    try
                    {
                        reader.BaseStream.Seek(-8L, SeekOrigin.Current);
                        data.Read(reader);
                        flagArray[2] = true;
                        break;
                    }
                    catch
                    {
                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);
                        break;
                    }

                case 1718449184:
                    try
                    {
                        reader.BaseStream.Seek(-8L, SeekOrigin.Current);
                        fmt.Read(reader);
                        flagArray[1] = true;
                        break;
                    }
                    catch
                    {
                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);
                        break;
                    }

                case 1936552044:
                    try
                    {
                        reader.BaseStream.Seek(-8L, SeekOrigin.Current);
                        smpl.Read(reader);
                        hasSmpl = true;
                        break;
                    }
                    catch
                    {
                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);
                        break;
                    }

                default:
                    reader.BaseStream.Seek(num2, SeekOrigin.Current);
                    break;
                }
                if (flagArray[0] && flagArray[1] && (flagArray[2] && hasSmpl))
                {
                    break;
                }
            }
            if (!flagArray[0] || !flagArray[1] || !flagArray[2])
            {
                throw new Exception("Couldn't parse Wave file...");
            }
        }