コード例 #1
0
        public static bool Load(RiffChunk parent, RiffChunk chunk, IReadable stream)
        {
            if (parent != null && RiffChunk.HeaderSize > parent.Size)
            {
                return(false);
            }

            if (stream.Position + HeaderSize >= stream.Length)
            {
                return(false);
            }

            chunk.Id = stream.Read8BitStringLength(4);
            if (chunk.Id[0] <= ' ' || chunk.Id[0] >= 'z')
            {
                return(false);
            }
            chunk.Size = stream.ReadUInt32LE();

            if (parent != null && HeaderSize + chunk.Size > parent.Size)
            {
                return(false);
            }

            if (parent != null)
            {
                parent.Size -= HeaderSize + chunk.Size;
            }

            var isRiff = chunk.Id == "RIFF";
            var isList = chunk.Id == "LIST";

            if (isRiff && parent != null)
            {
                // not allowed
                return(false);
            }

            if (!isRiff && !isList)
            {
                // custom type without sub type
                return(true);
            }

            // for lists unwrap the list type
            chunk.Id = stream.Read8BitStringLength(4);
            if (chunk.Id[0] <= ' ' || chunk.Id[0] >= 'z')
            {
                return(false);
            }
            chunk.Size -= 4;

            return(true);
        }
コード例 #2
0
        public PresetHeaderChunk(string id, int size, IReadable input)
            : base(id, size)
        {
            if (size % 38 != 0)
            {
                throw new Exception("Invalid SoundFont. The preset chunk was invalid.");
            }

            _rawPresets = new RawPreset[((int)(size / 38.0))];
            RawPreset lastPreset = null;

            for (int x = 0; x < _rawPresets.Length; x++)
            {
                var p = new RawPreset();
                p.Name                 = input.Read8BitStringLength(20);
                p.PatchNumber          = input.ReadUInt16LE();
                p.BankNumber           = input.ReadUInt16LE();
                p.StartPresetZoneIndex = input.ReadUInt16LE();
                p.Library              = input.ReadInt32LE();
                p.Genre                = input.ReadInt32LE();
                p.Morphology           = input.ReadInt32LE();
                if (lastPreset != null)
                {
                    lastPreset.EndPresetZoneIndex = Platform.Platform.ToUInt16((p.StartPresetZoneIndex - 1));
                }
                _rawPresets[x] = p;
                lastPreset     = p;
            }
        }
コード例 #3
0
        public PresetHeaderChunk(string id, int size, IReadable input)
            : base(id, size)
        {
            if (size % 38 != 0)
                throw new Exception("Invalid SoundFont. The preset chunk was invalid.");

            _rawPresets = new RawPreset[((int)(size / 38.0))];
            RawPreset lastPreset = null;
            for (int x = 0; x < _rawPresets.Length; x++)
            {
                var p = new RawPreset();
                p.Name = input.Read8BitStringLength(20);
                p.PatchNumber = input.ReadUInt16LE();
                p.BankNumber = input.ReadUInt16LE();
                p.StartPresetZoneIndex = input.ReadUInt16LE();
                p.Library = input.ReadInt32LE();
                p.Genre = input.ReadInt32LE();
                p.Morphology = input.ReadInt32LE();
                if (lastPreset != null)
                {
                    lastPreset.EndPresetZoneIndex = TypeUtils.ToUInt16((p.StartPresetZoneIndex - 1));
                }
                _rawPresets[x] = p;
                lastPreset = p;
            }
        }
コード例 #4
0
        public static HydraInst Load(IReadable reader)
        {
            var inst = new HydraInst();

            inst.InstName   = reader.Read8BitStringLength(20);
            inst.InstBagNdx = reader.ReadUInt16LE();
            return(inst);
        }
コード例 #5
0
ファイル: SampleHeader.cs プロジェクト: eriser/alphaSynth
 public SampleHeader(IReadable input)
 {
     Name = input.Read8BitStringLength(20);
     Start = input.ReadInt32LE();
     End = input.ReadInt32LE();
     StartLoop = input.ReadInt32LE();
     EndLoop = input.ReadInt32LE();
     SampleRate = input.ReadInt32LE();
     RootKey = (byte) input.ReadByte();
     Tune = TypeUtils.ToInt16(input.ReadByte());
     SampleLink = input.ReadUInt16LE();
     SoundFontSampleLink = (SFSampleLink) input.ReadUInt16LE();
 }
コード例 #6
0
 public SampleHeader(IReadable input)
 {
     Name                = input.Read8BitStringLength(20);
     Start               = input.ReadInt32LE();
     End                 = input.ReadInt32LE();
     StartLoop           = input.ReadInt32LE();
     EndLoop             = input.ReadInt32LE();
     SampleRate          = input.ReadInt32LE();
     RootKey             = (byte)input.ReadByte();
     Tune                = Platform.Platform.ToInt16(input.ReadByte());
     SampleLink          = input.ReadUInt16LE();
     SoundFontSampleLink = (SFSampleLink)input.ReadUInt16LE();
 }
コード例 #7
0
        public static HydraPhdr Load(IReadable reader)
        {
            HydraPhdr phdr = new HydraPhdr();

            phdr.PresetName   = reader.Read8BitStringLength(20);
            phdr.Preset       = reader.ReadUInt16LE();
            phdr.Bank         = reader.ReadUInt16LE();
            phdr.PresetBagNdx = reader.ReadUInt16LE();
            phdr.Library      = reader.ReadUInt32LE();
            phdr.Genre        = reader.ReadUInt32LE();
            phdr.Morphology   = reader.ReadUInt32LE();

            return(phdr);
        }
コード例 #8
0
        public static HydraShdr Load(IReadable reader)
        {
            var shdr = new HydraShdr();

            shdr.SampleName      = reader.Read8BitStringLength(20);
            shdr.Start           = reader.ReadUInt32LE();
            shdr.End             = reader.ReadUInt32LE();
            shdr.StartLoop       = reader.ReadUInt32LE();
            shdr.EndLoop         = reader.ReadUInt32LE();
            shdr.SampleRate      = reader.ReadUInt32LE();
            shdr.OriginalPitch   = (byte)reader.ReadByte();
            shdr.PitchCorrection = reader.ReadSignedByte();
            shdr.SampleLink      = reader.ReadUInt16LE();
            shdr.SampleType      = reader.ReadUInt16LE();
            return(shdr);
        }
コード例 #9
0
ファイル: InstrumentChunk.cs プロジェクト: eriser/alphaSynth
 public InstrumentChunk(string id, int size, IReadable input)
     : base(id, size)
 {
     if (size % 22 != 0)
         throw new Exception("Invalid SoundFont. The preset chunk was invalid.");
     _rawInstruments = new RawInstrument[((int)(size / 22.0))];
     RawInstrument lastInstrument = null;
     for (int x = 0; x < _rawInstruments.Length; x++)
     {
         var i = new RawInstrument();
         i.Name = input.Read8BitStringLength(20);
         i.StartInstrumentZoneIndex = input.ReadUInt16LE();
         if (lastInstrument != null)
         {
             lastInstrument.EndInstrumentZoneIndex = TypeUtils.ToUInt16((i.StartInstrumentZoneIndex - 1));
         }
         _rawInstruments[x] = i;
         lastInstrument = i;
     }
 }
コード例 #10
0
        public InstrumentChunk(string id, int size, IReadable input)
            : base(id, size)
        {
            if (size % 22 != 0)
            {
                throw new Exception("Invalid SoundFont. The preset chunk was invalid.");
            }
            _rawInstruments = new RawInstrument[((int)(size / 22.0))];
            RawInstrument lastInstrument = null;

            for (int x = 0; x < _rawInstruments.Length; x++)
            {
                var i = new RawInstrument();
                i.Name = input.Read8BitStringLength(20);
                i.StartInstrumentZoneIndex = input.ReadUInt16LE();
                if (lastInstrument != null)
                {
                    lastInstrument.EndInstrumentZoneIndex = Platform.Platform.ToUInt16((i.StartInstrumentZoneIndex - 1));
                }
                _rawInstruments[x] = i;
                lastInstrument     = i;
            }
        }
コード例 #11
0
        public SoundFontInfo(IReadable input)
        {
            Tools         = "";
            Comments      = "";
            Copyright     = "";
            TargetProduct = "";
            Author        = "";
            DataRom       = "";
            CreationDate  = "";
            BankName      = "";
            SoundEngine   = "";
            var id   = input.Read8BitChars(4);
            var size = input.ReadInt32LE();

            if (id.ToLower() != "list")
            {
                throw new Exception("Invalid soundfont. Could not find INFO LIST chunk.");
            }
            var readTo = input.Position + size;

            id = input.Read8BitChars(4);
            if (id.ToLower() != "info")
            {
                throw new Exception("Invalid soundfont. The LIST chunk is not of type INFO.");
            }

            while (input.Position < readTo)
            {
                id   = input.Read8BitChars(4);
                size = input.ReadInt32LE();
                switch (id.ToLower())
                {
                case "ifil":
                    SfVersionMajor = input.ReadInt16LE();
                    SfVersionMinor = input.ReadInt16LE();
                    break;

                case "isng":
                    SoundEngine = input.Read8BitStringLength(size);
                    break;

                case "inam":
                    BankName = input.Read8BitStringLength(size);
                    break;

                case "irom":
                    DataRom = input.Read8BitStringLength(size);
                    break;

                case "iver":
                    RomVersionMajor = input.ReadInt16LE();
                    RomVersionMinor = input.ReadInt16LE();
                    break;

                case "icrd":
                    CreationDate = input.Read8BitStringLength(size);
                    break;

                case "ieng":
                    Author = input.Read8BitStringLength(size);
                    break;

                case "iprd":
                    TargetProduct = input.Read8BitStringLength(size);
                    break;

                case "icop":
                    Copyright = input.Read8BitStringLength(size);
                    break;

                case "icmt":
                    Comments = input.Read8BitStringLength(size);
                    break;

                case "isft":
                    Tools = input.Read8BitStringLength(size);
                    break;

                default:
                    throw new Exception("Invalid soundfont. The Chunk: " + id + " was not expected.");
                }
            }
        }
コード例 #12
0
ファイル: SoundFontInfo.cs プロジェクト: eriser/alphaSynth
        public SoundFontInfo(IReadable input)
        {
            Tools = "";
            Comments = "";
            Copyright = "";
            TargetProduct = "";
            Author = "";
            DataRom = "";
            CreationDate = "";
            BankName = "";
            SoundEngine = "";
            var id = input.Read8BitChars(4);
            var size = input.ReadInt32LE();
            if (id.ToLower() != "list")
                throw new Exception("Invalid soundfont. Could not find INFO LIST chunk.");
            var readTo = input.Position + size;
            id = input.Read8BitChars(4);
            if (id.ToLower() != "info")
                throw new Exception("Invalid soundfont. The LIST chunk is not of type INFO.");

            while (input.Position < readTo)
            {
                id = input.Read8BitChars(4);
                size = input.ReadInt32LE();
                switch (id.ToLower())
                {
                    case "ifil":
                        SfVersionMajor = input.ReadInt16LE();
                        SfVersionMinor = input.ReadInt16LE();
                        break;
                    case "isng":
                        SoundEngine = input.Read8BitStringLength(size);
                        break;
                    case "inam":
                        BankName = input.Read8BitStringLength(size);
                        break;
                    case "irom":
                        DataRom = input.Read8BitStringLength(size);
                        break;
                    case "iver":
                        RomVersionMajor = input.ReadInt16LE();
                        RomVersionMinor = input.ReadInt16LE();
                        break;
                    case "icrd":
                        CreationDate = input.Read8BitStringLength(size);
                        break;
                    case "ieng":
                        Author = input.Read8BitStringLength(size);
                        break;
                    case "iprd":
                        TargetProduct = input.Read8BitStringLength(size);
                        break;
                    case "icop":
                        Copyright = input.Read8BitStringLength(size);
                        break;
                    case "icmt":
                        Comments = input.Read8BitStringLength(size);
                        break;
                    case "isft":
                        Tools = input.Read8BitStringLength(size);
                        break;
                    default:
                        throw new Exception("Invalid soundfont. The Chunk: " + id + " was not expected.");
                }
            }
        }