Beispiel #1
0
 private static AiffFileReader.AiffChunk ReadChunkHeader(BinaryReader br)
 {
     AiffFileReader.AiffChunk result = new AiffFileReader.AiffChunk((uint)br.BaseStream.Position, AiffFileReader.ReadChunkName(br), AiffFileReader.ConvertInt(br.ReadBytes(4)));
     return(result);
 }
Beispiel #2
0
        public static void ReadAiffHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List <AiffFileReader.AiffChunk> chunks)
        {
            dataChunkPosition = -1L;
            format            = null;
            BinaryReader binaryReader = new BinaryReader(stream);

            if (AiffFileReader.ReadChunkName(binaryReader) != "FORM")
            {
                throw new FormatException("Not an AIFF file - no FORM header.");
            }
            AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
            string a = AiffFileReader.ReadChunkName(binaryReader);

            if (a != "AIFC" && a != "AIFF")
            {
                throw new FormatException("Not an AIFF file - no AIFF/AIFC header.");
            }
            dataChunkLength = 0;
            while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
            {
                AiffFileReader.AiffChunk item = AiffFileReader.ReadChunkHeader(binaryReader);
                if (item.ChunkName == "COMM")
                {
                    short channels = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2));
                    AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
                    short  bits = AiffFileReader.ConvertShort(binaryReader.ReadBytes(2));
                    double num  = IEEE.ConvertFromIeeeExtended(binaryReader.ReadBytes(10));
                    format = new WaveFormat((int)num, (int)bits, (int)channels);
                    if (item.ChunkLength > 18u && a == "AIFC")
                    {
                        string a2 = new string(binaryReader.ReadChars(4)).ToLower();
                        if (a2 != "none")
                        {
                            throw new FormatException("Compressed AIFC is not supported.");
                        }
                        binaryReader.ReadBytes((int)(item.ChunkLength - 22u));
                    }
                    else
                    {
                        binaryReader.ReadBytes((int)(item.ChunkLength - 18u));
                    }
                }
                else if (item.ChunkName == "SSND")
                {
                    uint num2 = AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
                    AiffFileReader.ConvertInt(binaryReader.ReadBytes(4));
                    dataChunkPosition = (long)((ulong)(item.ChunkStart + 16u + num2));
                    dataChunkLength   = (int)(item.ChunkLength - 8u);
                    binaryReader.ReadBytes((int)(item.ChunkLength - 8u));
                }
                else
                {
                    if (chunks != null)
                    {
                        chunks.Add(item);
                    }
                    binaryReader.ReadBytes((int)item.ChunkLength);
                }
                if (item.ChunkName == "\0\0\0\0")
                {
                    break;
                }
            }
            if (format == null)
            {
                throw new FormatException("Invalid AIFF file - No COMM chunk found.");
            }
            if (dataChunkPosition == -1L)
            {
                throw new FormatException("Invalid AIFF file - No SSND chunk found.");
            }
        }