Example #1
0
        private void ParseFmt(Riff.RiffReader reader)
        {
            Ibasa.IO.BinaryReader binreader = new IO.BinaryReader(reader.Data);

            FormatTag tag;
            int       channels, bytesPerSecond, blockAlignment, bitsPerSample, size;

            if (reader.Length < 16)
            {
                throw new System.IO.InvalidDataException("Invalid fmt chunk.");
            }
            else
            {
                tag            = (FormatTag)binreader.ReadInt16();
                channels       = binreader.ReadInt16();
                Frequency      = binreader.ReadInt32();
                bytesPerSecond = binreader.ReadInt32();
                blockAlignment = binreader.ReadInt16();
                bitsPerSample  = binreader.ReadInt16();
            }

            if (reader.Length >= 18)
            {
                size = binreader.ReadInt16();
            }

            if (tag == FormatTag.Pcm)
            {
                if (bitsPerSample == 8)
                {
                    Format = new Ibasa.SharpAL.Formats.Pcm8(channels);
                }
                else if (bitsPerSample == 16)
                {
                    Format = new Ibasa.SharpAL.Formats.Pcm16(channels);
                }
                else
                {
                    throw new NotSupportedException(string.Format("PCM {0} bit data is not supported.", bitsPerSample));
                }
            }
            else
            {
                throw new NotSupportedException(string.Format("{0} is not supported.", tag));
            }
        }
Example #2
0
File: Wav.cs Project: Frassle/Ibasa
        public Wav(System.IO.Stream stream)
        {
            Stream = stream;
            Riff.RiffReader reader = new Riff.RiffReader(stream);

            if (!reader.Read() || !reader.Type.HasValue || reader.Type.Value != "WAVE")
            {
                throw new System.IO.InvalidDataException("Not a WAVE stream.");
            }

            while (reader.Read())
            {
                if (reader.Id == "fmt ")
                {
                    ParseFmt(reader);
                }
                if (reader.Id == "data")
                {
                    ParseData(reader);
                }
            }
        }
Example #3
0
        public Wav(System.IO.Stream stream)
        {
            Stream = stream;
            Riff.RiffReader reader = new Riff.RiffReader(stream);

            if (!reader.Read() || !reader.Type.HasValue || reader.Type.Value != "WAVE")
            {
                throw new System.IO.InvalidDataException("Not a WAVE stream.");
            }

            while (reader.Read())
            {
                if (reader.Id == "fmt ")
                {
                    ParseFmt(reader);
                }
                if (reader.Id == "data")
                {
                    ParseData(reader);
                }
            }
        }
Example #4
0
 private void ParseData(Riff.RiffReader reader)
 {
     DataOffset = reader.Offset;
     DataLength = reader.Length;
 }