Exemplo n.º 1
0
 public DlsCollection(Guid?id, Version collectionVersion, DlsInfo info, IReadOnlyList <DlsInstrument> instruments, IReadOnlyList <DlsWaveFile> wavePool)
 {
     CollectionVersion = collectionVersion;
     Info        = info;
     Instruments = instruments;
     WavePool    = wavePool;
     Id          = id;
 }
Exemplo n.º 2
0
 public DlsInstrument(Guid?id, DlsInfo info, byte bankMsb, byte bankLsb, byte patch, bool isPercussion, IReadOnlyList <DlsRegion> regions, IReadOnlyList <DlsArticulator> articulatorList)
 {
     Id              = id;
     Info            = info;
     BankMsb         = bankMsb;
     BankLsb         = bankLsb;
     Patch           = patch;
     IsPercussion    = isPercussion;
     Regions         = regions;
     ArticulatorList = articulatorList;
 }
Exemplo n.º 3
0
        private static DlsInstrument?ReadDlsInstrument(RiffChunk insChunk)
        {
            var  isHeaderSet = false;
            byte msb = 0, lsb = 0, patch = 0;
            var  isPercussion = false;

            var regions         = new List <DlsRegion>();
            var id              = default(Guid?);
            var info            = new DlsInfo();
            var articulatorList = (IReadOnlyList <DlsArticulator>) new DlsArticulator[0];

            foreach (var insSubchunk in insChunk.ReadList())
            {
                switch (insSubchunk.Name)
                {
                case "dlid":
                    id = ReadDlsId(insSubchunk);
                    break;

                case "insh":
                    isHeaderSet = true;
                    insSubchunk.ReadUInt32();     // NumRegions
                    var bank = insSubchunk.ReadUInt32();
                    lsb          = (byte)bank;
                    msb          = (byte)(bank >> 8);
                    isPercussion = (bank & 0x8000000u) != 0;
                    patch        = (byte)insSubchunk.ReadUInt32();
                    break;

                case "lrgn":
                    regions.AddRange(
                        from lrgnSubchunk in insSubchunk.ReadList()
                        where lrgnSubchunk.Name == "rgn "
                        let region = ReadDlsRegion(lrgnSubchunk)
                                     where region != null
                                     select region.Value);
                    break;

                case "lart":
                    articulatorList = ReadDlsArticulatorList(insSubchunk);
                    break;

                case "INFO":
                    info = ReadDlsInfo(insSubchunk);
                    break;
                }
            }

            if (!isHeaderSet)
            {
                return(null);
            }
            return(new DlsInstrument(id, info, msb, lsb, patch, isPercussion, regions, articulatorList));
        }
Exemplo n.º 4
0
 public DlsWaveFile(DlsWaveFormat format, ushort numChannels, uint samplesPerSecond, uint avgBytesPerSec, ushort blockAlign, ushort?bitsPerSample, byte[] data, DlsWaveSample?waveSample, DlsInfo info)
 {
     Format           = format;
     NumChannels      = numChannels;
     SamplesPerSecond = samplesPerSecond;
     AvgBytesPerSec   = avgBytesPerSec;
     BlockAlign       = blockAlign;
     BitsPerSample    = bitsPerSample;
     Data             = data;
     WaveSample       = waveSample;
     Info             = info;
 }
Exemplo n.º 5
0
        public static DlsCollection Read(Stream stream)
        {
            using (var reader = new RiffReader(stream))
            {
                var collectionVersion = default(Version);
                var instruments       = new List <DlsInstrument>();
                var wavePool          = new List <DlsWaveFile>();
                var info = new DlsInfo();
                var id   = default(Guid?);

                foreach (var dlsSubchunk in reader.ReadRiff("DLS ").ReadList())
                {
                    switch (dlsSubchunk.Name)
                    {
                    case "vers":
                        var minor    = dlsSubchunk.ReadUInt16();
                        var major    = dlsSubchunk.ReadUInt16();
                        var revision = dlsSubchunk.ReadUInt16();
                        var build    = dlsSubchunk.ReadUInt16();
                        collectionVersion = new Version(major, minor, build, revision);
                        break;

                    case "dlid":
                        id = ReadDlsId(dlsSubchunk);
                        break;

                    case "lins":
                        instruments.AddRange(
                            from lrgnSubchunk in dlsSubchunk.ReadList()
                            where lrgnSubchunk.Name == "ins "
                            let instrument = ReadDlsInstrument(lrgnSubchunk)
                                             where instrument != null
                                             select instrument.Value);
                        break;

                    case "wvpl":
                        wavePool.AddRange(
                            from wvplSubchunk in dlsSubchunk.ReadList()
                            where wvplSubchunk.Name == "wave"
                            let waveFile = ReadDlsWaveFile(wvplSubchunk)
                                           where waveFile != null
                                           select waveFile.Value);
                        break;

                    case "INFO":
                        info = ReadDlsInfo(dlsSubchunk);
                        break;
                    }
                }

                return(new DlsCollection(id, collectionVersion, info, instruments, wavePool));
            }
        }
Exemplo n.º 6
0
        private static DlsWaveFile?ReadDlsWaveFile(RiffChunk waveChunk)
        {
            var format           = default(DlsWaveFormat);
            var numChannels      = default(ushort);
            var samplesPerSecond = default(uint);
            var avgBytesPerSec   = default(uint);
            var blockAlign       = default(ushort);
            var bitsPerSample    = default(ushort?);
            var data             = default(byte[]);
            var info             = new DlsInfo();
            var waveSample       = default(DlsWaveSample?);

            foreach (var waveSubchunk in waveChunk.ReadList())
            {
                switch (waveSubchunk.Name)
                {
                case "fmt ":
                    format           = (DlsWaveFormat)waveSubchunk.ReadUInt16();
                    numChannels      = waveSubchunk.ReadUInt16();
                    samplesPerSecond = waveSubchunk.ReadUInt32();
                    avgBytesPerSec   = waveSubchunk.ReadUInt32();
                    blockAlign       = waveSubchunk.ReadUInt16();
                    if (format == DlsWaveFormat.PCM)
                    {
                        bitsPerSample = waveSubchunk.ReadUInt16();
                    }
                    break;

                case "data":
                    data = waveSubchunk.ReadAllBytes();
                    break;

                case "INFO":
                    info = ReadDlsInfo(waveSubchunk);
                    break;

                case "wsmp":
                    waveSample = ReadDlsWaveSample(waveSubchunk);
                    break;
                }
            }

            return(new DlsWaveFile(format, numChannels, samplesPerSecond, avgBytesPerSec, blockAlign, bitsPerSample, data, waveSample, info));
        }