Esempio n. 1
0
        public void Read(Stream stream)
        {
            var masterChunk = new RiffChunk(stream);

            if (masterChunk.Id != "RIFF")
            {
                throw new FileFormatException("WaveFile.masterChunk.Id", masterChunk.Id, "RIFF");
            }

            // masterChunk
            using (var masterStream = masterChunk.GetStream()) {
                var WaveId = StreamHelperLe.ReadString(masterStream, 4);
                if (WaveId != "WAVE")
                {
                    throw new FileFormatException("WaveFile.WaveId", WaveId, "WAVE");
                }

                // formatChunk
                var formatChunk = new RiffChunk(masterStream);
                if (formatChunk.Id != "fmt ")
                {
                    throw new FileFormatException("WaveFile.formatChunk.Id", formatChunk.Id, "fmt ");
                }
                using (var formatStream = formatChunk.GetStream()) {
                    FormatTag      = StreamHelperLe.ReadUInt16(formatStream);
                    Channels       = StreamHelperLe.ReadUInt16(formatStream);
                    SamplePerSec   = StreamHelperLe.ReadUInt32(formatStream);
                    AvgBytesPerSec = StreamHelperLe.ReadUInt32(formatStream);
                    BlockAlign     = StreamHelperLe.ReadUInt16(formatStream);
                    BitsPerSample  = StreamHelperLe.ReadUInt16(formatStream);
                }

                if (Format != WaveFileFormat.MicrosoftPcm)
                {
                    throw new FileFormatException("WaveFile.Format", Format, WaveFileFormat.MicrosoftPcm);
                }

                // dataChunk
                while (masterStream.Position < masterStream.Length)
                {
                    var chunk = new RiffChunk(masterStream);
                    if (chunk.Id == "data")
                    {
                        Data = chunk.Data;
                        using (var dataStream = chunk.GetStream()) {
                            BuildSamples(dataStream);
                        }
                        break;
                    }
                }

                if (Data == null)
                {
                    throw new FileFormatException("WaveFile.WaveData", "null", "byte[]");
                }
            }
        }
Esempio n. 2
0
        public PresetHeader(Stream stream)
        {
            PresetName     = StreamHelperLe.ReadString(stream, 20);
            Preset         = StreamHelperLe.ReadUInt16(stream);
            Bank           = StreamHelperLe.ReadUInt16(stream);
            PresetBagIndex = StreamHelperLe.ReadUInt16(stream);

            Library    = StreamHelperLe.ReadUInt32(stream);
            Genre      = StreamHelperLe.ReadUInt32(stream);
            Morphology = StreamHelperLe.ReadUInt32(stream);
        }
Esempio n. 3
0
 public SampleHeader(Stream stream)
 {
     SampleName     = StreamHelperLe.ReadString(stream, 20);
     Start          = StreamHelperLe.ReadUInt32(stream);
     End            = StreamHelperLe.ReadUInt32(stream);
     Startloop      = StreamHelperLe.ReadUInt32(stream);
     Endloop        = StreamHelperLe.ReadUInt32(stream);
     SampleRate     = StreamHelperLe.ReadUInt32(stream);
     OriginalKey    = (byte)stream.ReadByte();
     Correction     = (sbyte)stream.ReadByte();
     SampleLink     = StreamHelperLe.ReadUInt16(stream);
     SampleLinkType = (SampleLinkType)StreamHelperLe.ReadUInt16(stream);
 }