コード例 #1
0
        public SoundfontSfz(SfzRegion sfzData, Dictionary <string, string> aPathWaveformDictionary)
        {
            byte  lokey          = sfzData.lokey;
            byte  hikey          = sfzData.hikey;
            bool  loopMode       = sfzData.loop_mode;
            int   loopStart      = sfzData.loop_start - 1;
            int   loopEnd        = sfzData.loop_end;
            int   offset         = sfzData.offset;
            int   end            = sfzData.end;
            int   tune           = sfzData.tune;
            int   pitchKeyCenter = sfzData.pitch_keycenter;
            float volume         = sfzData.volume;

            soundinfo = new Soundinfo(lokey, hikey, loopMode, loopStart, loopEnd, offset, end, tune, pitchKeyCenter, 0, 0, volume);
            ampeg     = new Ampeg(sfzData.ampeg_delay, sfzData.ampeg_start / 100.0f, sfzData.ampeg_attack, sfzData.ampeg_hold, sfzData.ampeg_decay, sfzData.ampeg_sustain / 100.0f, sfzData.ampeg_release);

            if (aPathWaveformDictionary.ContainsKey(sfzData.sample) == false)
            {
                Logger.LogError("This waveform is not found:" + sfzData.sample);
            }
            else
            {
                waveform = LoaderWaveform.Load(aPathWaveformDictionary[sfzData.sample]);
            }
        }
コード例 #2
0
ファイル: DescriptorList.cs プロジェクト: MSylvia/DoomEngine
 public DescriptorList(SfzRegion region)
 {
     LoadSfzEnvelopes(region);
     LoadSfzFilters(region);
     LoadSfzLfos(region);
     LoadSfzGens(region);
     LoadSfzCustom(region);
 }
コード例 #3
0
ファイル: DescriptorList.cs プロジェクト: MSylvia/DoomEngine
 private void LoadSfzFilters(SfzRegion region)
 {
     FilterDescriptions    = new FilterDescriptor[1];
     FilterDescriptions[0] = new FilterDescriptor();
     FilterDescriptions[0].FilterMethod = region.filterType;
     FilterDescriptions[0].CutOff       = region.cutOff;
     FilterDescriptions[0].KeyTrack     = region.filterKeyTrack;
     FilterDescriptions[0].Resonance    = (float)SynthHelper.DBtoLinear(region.resonance);
     FilterDescriptions[0].RootKey      = region.filterKeyCenter;
     FilterDescriptions[0].VelTrack     = region.filterVelTrack;
 }
コード例 #4
0
ファイル: DescriptorList.cs プロジェクト: MSylvia/DoomEngine
 private void LoadSfzEnvelopes(SfzRegion region)
 {
     EnvelopeDescriptions                 = new EnvelopeDescriptor[3];
     EnvelopeDescriptions[0]              = new EnvelopeDescriptor();
     EnvelopeDescriptions[0].DelayTime    = region.pitchEGDelay;
     EnvelopeDescriptions[0].AttackTime   = region.pitchEGAttack;
     EnvelopeDescriptions[0].HoldTime     = region.pitchEGHold;
     EnvelopeDescriptions[0].DecayTime    = region.pitchEGDecay;
     EnvelopeDescriptions[0].SustainLevel = region.pitchEGSustain / 100f;
     EnvelopeDescriptions[0].ReleaseTime  = region.pitchEGRelease;
     EnvelopeDescriptions[0].StartLevel   = region.pitchEGStart / 100f;
     EnvelopeDescriptions[0].Depth        = region.pitchEGDepth;
     EnvelopeDescriptions[0].Vel2Delay    = region.pitchEGVel2Delay;
     EnvelopeDescriptions[0].Vel2Attack   = region.pitchEGVel2Attack;
     EnvelopeDescriptions[0].Vel2Hold     = region.pitchEGVel2Hold;
     EnvelopeDescriptions[0].Vel2Decay    = region.pitchEGVel2Decay;
     EnvelopeDescriptions[0].Vel2Sustain  = region.pitchEGVel2Sustain;
     EnvelopeDescriptions[0].Vel2Release  = region.pitchEGVel2Release;
     EnvelopeDescriptions[0].Vel2Depth    = region.pitchEGVel2Depth;
     EnvelopeDescriptions[1]              = new EnvelopeDescriptor();
     EnvelopeDescriptions[1].DelayTime    = region.filterEGDelay;
     EnvelopeDescriptions[1].AttackTime   = region.filterEGAttack;
     EnvelopeDescriptions[1].HoldTime     = region.filterEGHold;
     EnvelopeDescriptions[1].DecayTime    = region.filterEGDecay;
     EnvelopeDescriptions[1].SustainLevel = region.filterEGSustain / 100f;
     EnvelopeDescriptions[1].ReleaseTime  = region.filterEGRelease;
     EnvelopeDescriptions[1].StartLevel   = region.filterEGStart / 100f;
     EnvelopeDescriptions[1].Depth        = region.filterEGDepth;
     EnvelopeDescriptions[1].Vel2Delay    = region.filterEGVel2Delay;
     EnvelopeDescriptions[1].Vel2Attack   = region.filterEGVel2Attack;
     EnvelopeDescriptions[1].Vel2Hold     = region.filterEGVel2Hold;
     EnvelopeDescriptions[1].Vel2Decay    = region.filterEGVel2Decay;
     EnvelopeDescriptions[1].Vel2Sustain  = region.filterEGVel2Sustain;
     EnvelopeDescriptions[1].Vel2Release  = region.filterEGVel2Release;
     EnvelopeDescriptions[1].Vel2Depth    = region.filterEGVel2Depth;
     EnvelopeDescriptions[2]              = new EnvelopeDescriptor();
     EnvelopeDescriptions[2].DelayTime    = region.ampEGDelay;
     EnvelopeDescriptions[2].AttackTime   = region.ampEGAttack;
     EnvelopeDescriptions[2].HoldTime     = region.ampEGHold;
     EnvelopeDescriptions[2].DecayTime    = region.ampEGDecay;
     EnvelopeDescriptions[2].SustainLevel = region.ampEGSustain / 100f;
     EnvelopeDescriptions[2].ReleaseTime  = region.ampEGRelease;
     EnvelopeDescriptions[2].StartLevel   = region.ampEGStart / 100f;
     EnvelopeDescriptions[2].Depth        = 1f;
     EnvelopeDescriptions[2].Vel2Delay    = region.ampEGVel2Delay;
     EnvelopeDescriptions[2].Vel2Attack   = region.ampEGVel2Attack;
     EnvelopeDescriptions[2].Vel2Hold     = region.ampEGVel2Hold;
     EnvelopeDescriptions[2].Vel2Decay    = region.ampEGVel2Decay;
     EnvelopeDescriptions[2].Vel2Sustain  = region.ampEGVel2Sustain;
     EnvelopeDescriptions[2].Vel2Release  = region.ampEGVel2Release;
     EnvelopeDescriptions[2].Vel2Depth    = 0f;
 }
コード例 #5
0
        public InstrumentSfz(SfzFile aSfzFile, Dictionary <string, string> aPathWaveformDictionary)
            : base()
        {
            List <SoundfontBase> lSoundfontList = new List <SoundfontBase>();

            for (int i = 0; i < aSfzFile.sfzRegionList.Count; i++)
            {
                SfzRegion lSfzData = aSfzFile.sfzRegionList[i];

                lSoundfontList.Add(new SoundfontSfz(lSfzData, aPathWaveformDictionary));
            }

            AddSoundfont(lSoundfontList);
        }
コード例 #6
0
        public InstrumentSfz(SfzFile aSfzFile)
            : base()
        {
            List <SoundfontBase> lSoundfontList = new List <SoundfontBase>();

            for (int i = 0; i < aSfzFile.sfzRegionList.Count; i++)
            {
                SfzRegion lSfzData = aSfzFile.sfzRegionList[i];

                lSoundfontList.Add(new SoundfontSfz(lSfzData));
            }

            AddSoundfont(lSoundfontList);
        }
コード例 #7
0
 public void LoadSfz(SfzRegion[] regions, AssetManager assets, string directory)
 {
     //Load sub instruments first
     intervalList = new PatchInterval[regions.Length];
     for (int x = 0; x < intervalList.Length; x++)
     {
         SfzRegion      r        = regions[x];
         DescriptorList descList = new DescriptorList(r);
         assets.LoadSampleAsset(descList.GenDescriptions[0].AssetName, patchName, directory);
         SfzPatch sfzPatch = new SfzPatch(patchName + "_" + x);
         sfzPatch.Load(descList, assets);
         intervalList[x] = new PatchInterval(sfzPatch, r.loChan, r.hiChan, r.loKey, r.hiKey, r.loVel, r.hiVel);
     }
     DetermineIntervalType();
 }
コード例 #8
0
ファイル: DescriptorList.cs プロジェクト: MSylvia/DoomEngine
 private void LoadSfzLfos(SfzRegion region)
 {
     LfoDescriptions              = new LfoDescriptor[3];
     LfoDescriptions[0]           = new LfoDescriptor();
     LfoDescriptions[0].DelayTime = region.pitchLfoDelay; //make sure pitch lfo is enabled for midi mod event
     LfoDescriptions[0].Frequency = region.pitchLfoFrequency > 0 ? region.pitchLfoFrequency : (float)Synthesizer.DefaultLfoFrequency;
     LfoDescriptions[0].Depth     = region.pitchLfoDepth;
     LfoDescriptions[1]           = new LfoDescriptor();
     LfoDescriptions[1].DelayTime = region.filterLfoDelay;
     LfoDescriptions[1].Frequency = region.filterLfoFrequency;
     LfoDescriptions[1].Depth     = region.filterLfoDepth;
     LfoDescriptions[2]           = new LfoDescriptor();
     LfoDescriptions[2].DelayTime = region.ampLfoDelay;
     LfoDescriptions[2].Frequency = region.ampLfoFrequency;
     LfoDescriptions[2].Depth     = (float)SynthHelper.DBtoLinear(region.ampLfoDepth);
 }
コード例 #9
0
        public SoundfontSfz(SfzRegion sfzData)
        {
            byte  lokey          = sfzData.lokey;
            byte  hikey          = sfzData.hikey;
            bool  loopMode       = sfzData.loop_mode;
            int   loopStart      = sfzData.loop_start - 1;
            int   loopEnd        = sfzData.loop_end;
            int   offset         = sfzData.offset;
            int   end            = sfzData.end;
            int   tune           = sfzData.tune;
            int   pitchKeyCenter = sfzData.pitch_keycenter;
            float volume         = sfzData.volume;

            soundinfo = new Soundinfo(lokey, hikey, loopMode, loopStart, loopEnd, offset, end, tune, pitchKeyCenter, 0, 0, volume);
            ampeg     = new Ampeg(sfzData.ampeg_delay, sfzData.ampeg_start / 100.0f, sfzData.ampeg_attack, sfzData.ampeg_hold, sfzData.ampeg_decay, sfzData.ampeg_sustain / 100.0f, sfzData.ampeg_release);

            waveform = new WaveformReaderPcm(PoolCollection.GetRiffWave(sfzData.sample), true);
        }
コード例 #10
0
ファイル: DescriptorList.cs プロジェクト: MSylvia/DoomEngine
 private void LoadSfzGens(SfzRegion region)
 {
     GenDescriptions                = new GeneratorDescriptor[1];
     GenDescriptions[0]             = new GeneratorDescriptor();
     GenDescriptions[0].SamplerType = Components.WaveformEnum.SampleData;
     GenDescriptions[0].AssetName   = region.sample;
     //deal with end point
     if (region.end == -1) //-1 is silent region, so set end to 0 and let the generator figure it out later
     {
         GenDescriptions[0].EndPhase = 0;
     }
     else if (region.end == 0) //set end out of range and let the descriptor default it to the proper end value
     {
         GenDescriptions[0].EndPhase = -1;
     }
     else //add one to the value because its inclusive
     {
         GenDescriptions[0].EndPhase = region.end + 1;
     }
     GenDescriptions[0].KeyTrack = region.pitchKeyTrack;
     //deal with loop end
     if (region.loopEnd < 0)
     {
         GenDescriptions[0].LoopEndPhase = -1;
     }
     else
     {
         GenDescriptions[0].LoopEndPhase = region.loopEnd + 1;
     }
     GenDescriptions[0].LoopMethod = region.loopMode;
     if (region.loopStart < 0)
     {
         GenDescriptions[0].LoopStartPhase = -1;
     }
     else
     {
         GenDescriptions[0].LoopStartPhase = region.loopStart;
     }
     GenDescriptions[0].Offset   = region.offset;
     GenDescriptions[0].Rootkey  = region.pitchKeyCenter;
     GenDescriptions[0].Tune     = (short)(region.tune + region.transpose * 100);
     GenDescriptions[0].VelTrack = region.pitchVelTrack;
 }
コード例 #11
0
ファイル: SfzRegion.cs プロジェクト: Inuterasu/csharpsynth
 public override bool Equals(object obj)
 {
     if (obj.GetType() == typeof(SfzRegion))
     {
         SfzRegion r = (SfzRegion)obj;
         if (r.HiNote == this.HiNote && r.LoNote == this.LoNote && r.LoopEnd == this.LoopEnd &&
             r.LoopMode == this.LoopMode && r.LoopStart == this.LoopStart &&
             r.Release == this.Release && r.Root == this.Root && r.SampleIndex == this.SampleIndex &&
             r.Tune == this.Tune && r.Volume == this.Volume && r.Decay == this.Decay &&
             r.HiChannel == this.HiChannel && r.LoChannel == this.LoChannel &&
             r.HiVelocity == this.HiVelocity && r.LoVelocity == this.LoVelocity &&
             r.Pan == this.Pan && r.Offset == this.Offset && r.Effect1 == this.Effect1 &&
             r.Effect2 == this.Effect2)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #12
0
        private static int LoadSfz(PatchInfo pInfo)
        {
            SfzReader sfz;

            using (FileStream fs = File.Open(patchPath + pInfo.Name, FileMode.Open, FileAccess.Read))
            {
                sfz = new SfzReader(fs, pInfo.Name);
            }
            PatchInfo[] pInfos  = new PatchInfo[sfz.Regions.Length];
            int         nameLen = sfz.Name.Length + 1 + sfz.Regions.Length.ToString().Length;

            if (nameLen > 20)
            {
                sfz.Name = sfz.Name.Remove(0, nameLen - 20);
            }
            for (int i = 0; i < pInfos.Length; i++)
            {
                pInfos[i]             = new PatchInfo(sfz.Name + "_" + i, new PatchInterval(-1, 0, 0));
                pInfos[i].Type        = "sfz ";
                pInfos[i].Description = new DescriptorList(sfz.Regions[i]);
            }
            DescriptorList multiDesc = new DescriptorList();

            multiDesc.CustomDescriptions = new CustomDescriptor[sfz.Regions.Length];
            for (int i = 0; i < multiDesc.CustomDescriptions.Length; i++)
            {
                SfzRegion r = sfz.Regions[i];
                multiDesc.CustomDescriptions[i] = new CustomDescriptor("mpat", pInfos[i].Name.Length + 14, new object[] { pInfos[i].Name, r.loChan, r.hiChan, r.loKey, r.hiKey, r.loVel, r.hiVel });
            }
            pInfo.Type        = "mult";
            pInfo.Description = multiDesc;
            multiPatches.Add(pInfo);
            patches.Remove(pInfo);
            patches.InsertRange(0, pInfos);
            return(pInfos.Length - 1);
        }
コード例 #13
0
ファイル: DescriptorList.cs プロジェクト: MSylvia/DoomEngine
 private void LoadSfzCustom(SfzRegion region)
 {
     CustomDescriptions    = new CustomDescriptor[1];
     CustomDescriptions[0] = new CustomDescriptor("sfzi", 32,
                                                  new object[] { region.offBy, region.group, region.volume, region.pan / 100f, region.ampKeyTrack, region.ampKeyCenter, region.ampVelTrack / 100f });
 }
コード例 #14
0
        private void LoadPatchData()
        {
            for (int x = 0; x < patches.Count; x++)
            {
                switch (Path.GetExtension(patches[x].Name).ToLower())
                {
                case ".patch":
                    using (StreamReader reader = new StreamReader(patchPath + patches[x].Name))
                    {
                        string str = reader.ReadLine();
                        if (PatchBank.BankVersion != float.Parse(str.Substring(str.IndexOf("v") + 1)))
                        {
                            throw new Exception("The patch " + patches[x].Name + " has an incorrect version.");
                        }
                        patches[x].Type        = reader.ReadLine().Trim().ToLower();
                        patches[x].Description = new DescriptorList(reader);
                    }
                    if (patches[x].Type.Equals("multi"))
                    {
                        PatchInfo pInfo = patches[x];
                        patches.RemoveAt(x);
                        x--;
                        multiPatches.Add(pInfo);
                        //load sub patches
                        for (int i = 0; i < pInfo.Description.CustomDescriptions.Length; x++)
                        {
                            if (!pInfo.Description.CustomDescriptions[i].ID.Equals("mpat"))
                            {
                                throw new Exception("Invalid multi patch: " + pInfo.Name);
                            }
                            string subPatchName = (string)pInfo.Description.CustomDescriptions[i].Objects[0];
                            if (ContainsPatch(subPatchName, patches) == false)
                            {
                                PatchInfo subPatch = new PatchInfo(subPatchName, new PatchInterval(-1, 0, 0));
                                patches.Add(subPatch);
                            }
                        }
                    }
                    break;

                case ".sfz":
                {
                    SfzReader   sfz     = new SfzReader(patchPath + patches[x].Name);
                    PatchInfo[] pInfos  = new PatchInfo[sfz.Regions.Length];
                    int         nameLen = sfz.Name.Length + 1 + sfz.Regions.Length.ToString().Length;
                    if (nameLen > 20)
                    {
                        sfz.Name = sfz.Name.Remove(0, nameLen - 20);
                    }
                    for (int i = 0; i < pInfos.Length; i++)
                    {
                        pInfos[i]             = new PatchInfo(sfz.Name + "_" + i, new PatchInterval(-1, 0, 0));
                        pInfos[i].Type        = "sfz ";
                        pInfos[i].Description = new DescriptorList(sfz.Regions[i]);
                    }
                    DescriptorList multiDesc = new DescriptorList();
                    multiDesc.CustomDescriptions = new CustomDescriptor[sfz.Regions.Length];
                    for (int i = 0; i < multiDesc.CustomDescriptions.Length; i++)
                    {
                        SfzRegion r = sfz.Regions[i];
                        multiDesc.CustomDescriptions[i] = new CustomDescriptor("mpat", pInfos[i].Name.Length + 14,
                                                                               new object[] { pInfos[i].Name, r.loChan, r.hiChan, r.loKey, r.hiKey, r.loVel, r.hiVel });
                    }
                    patches[x].Type        = "mult";
                    patches[x].Description = multiDesc;
                    multiPatches.Add(patches[x]);
                    patches.RemoveAt(x);
                    patches.InsertRange(0, pInfos);
                    x += pInfos.Length - 1;
                }
                break;
                }
            }
        }