public Flanger(int sampleRate, double minDelay, double maxDelay)
        {
            if (minDelay > maxDelay)
            {
                double m = minDelay;
                minDelay = maxDelay;
                maxDelay = m;
            }
            LfoDescriptor description = new LfoDescriptor();
            this.lfo = new Lfo();
            this.lfo.QuickSetup(sampleRate, description);

            this.baseDelay = (int)(sampleRate * (maxDelay - minDelay));
            this.minDelay = (int)(sampleRate * minDelay);

            int size = (int)(sampleRate * maxDelay) + 1;
            this.inputBuffer1 = new float[size];
            this.outputBuffer1 = new float[size];
            this.position1 = 0;

            this.inputBuffer2 = new float[size];
            this.outputBuffer2 = new float[size];
            this.position2 = 0;

            this.fBack = .15f;
            this.wMix = .5f;
            this.dMix = .5f;
        }
 public DescriptorList(StreamReader reader)
 {
     List<EnvelopeDescriptor> envList = new List<EnvelopeDescriptor>();
     List<FilterDescriptor> fltrList = new List<FilterDescriptor>();
     List<LfoDescriptor> lfoList = new List<LfoDescriptor>();
     List<GeneratorDescriptor> genList = new List<GeneratorDescriptor>();
     List<CustomDescriptor> cList = new List<CustomDescriptor>();
     List<string> descList = new List<string>();
     while (!reader.EndOfStream)
     {
         string tag = ReadNextTag(reader, descList); 
         switch (tag)
         {
             case "envelope":
             {
                 EnvelopeDescriptor env = new EnvelopeDescriptor();
                 env.Read(descList.ToArray());
                 envList.Add(env);
                 break;
             }
             case "generator":
             {
                 GeneratorDescriptor gen = new GeneratorDescriptor();
                 gen.Read(descList.ToArray());
                 genList.Add(gen);
                 break;
             }
             case "filter":
             {
                 FilterDescriptor fltr = new FilterDescriptor();
                 fltr.Read(descList.ToArray());
                 fltrList.Add(fltr);
                 break;
             }
             case "lfo":
             {
                 LfoDescriptor lfo = new LfoDescriptor();
                 lfo.Read(descList.ToArray());
                 lfoList.Add(lfo);
                 break;
             }
             default:
                 if (!tag.Equals(string.Empty))
                 {
                     CustomDescriptor cus = new CustomDescriptor(tag, 0);
                     cus.Read(descList.ToArray());
                     cList.Add(cus);
                 }
                 break;
         }
         descList.Clear();
     }
     EnvelopeDescriptions = envList.ToArray();
     FilterDescriptions = fltrList.ToArray();
     LfoDescriptions = lfoList.ToArray();
     GenDescriptions = genList.ToArray();
     CustomDescriptions = cList.ToArray();
 }
 public void QuickSetup(int sampleRate, LfoDescriptor lfoInfo)
 {
     generator = lfoInfo.Generator;
     delayTime = (int)(sampleRate * lfoInfo.DelayTime);
     frequency = lfoInfo.Frequency;
     increment = generator.Period * frequency / sampleRate;
     depth = lfoInfo.Depth;
     Reset();
 }
 public override void Load(DescriptorList description, AssetManager assets)
 {
     gen = description.GenDescriptions[0].ToGenerator(assets);
     env = description.EnvelopeDescriptions[0];
     lfo = description.LfoDescriptions[0];
 }
 public DescriptorList(BinaryReader reader)
 {
     List<EnvelopeDescriptor> envList = new List<EnvelopeDescriptor>();
     List<FilterDescriptor> fltrList = new List<FilterDescriptor>();
     List<LfoDescriptor> lfoList = new List<LfoDescriptor>();
     List<GeneratorDescriptor> genList = new List<GeneratorDescriptor>();
     List<CustomDescriptor> cList = new List<CustomDescriptor>();
     int count = reader.ReadInt16();
     for (int x = 0; x < count; x++)
     {
         string id = new string(IOHelper.Read8BitChars(reader, 4));
         int size = reader.ReadInt32();
         switch (id.ToLower())
         {
             case EnvelopeDescriptor.ID:
             {
                 EnvelopeDescriptor env = new EnvelopeDescriptor();
                 env.Read(reader);
                 envList.Add(env);
                 break;
             }
             case GeneratorDescriptor.ID:
             {
                 GeneratorDescriptor gen = new GeneratorDescriptor();
                 gen.Read(reader);
                 genList.Add(gen);
                 break;
             }
             case FilterDescriptor.ID:
             {
                 FilterDescriptor fltr = new FilterDescriptor();
                 fltr.Read(reader);
                 fltrList.Add(fltr);
                 break;
             }
             case LfoDescriptor.ID:
             {
                 LfoDescriptor lfo = new LfoDescriptor();
                 lfo.Read(reader);
                 lfoList.Add(lfo);
                 break;
             }
             default:
             {
                 CustomDescriptor cus = new CustomDescriptor(id, size);
                 cus.Read(reader);
                 cList.Add(cus);
                 break;
             }
         }
     }
     EnvelopeDescriptions = envList.ToArray();
     FilterDescriptions = fltrList.ToArray();
     LfoDescriptions = lfoList.ToArray();
     GenDescriptions = genList.ToArray();
     CustomDescriptions = cList.ToArray();
 }
 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);
 }
 private void LoadLfos(Sf2Region region)
 {
     mod_lfo = new LfoDescriptor();
     mod_lfo.DelayTime = (float)Math.Pow(2, region.Generators[(int)GeneratorEnum.DelayModulationLFO] / 1200.0);
     mod_lfo.Frequency = (float)(Math.Pow(2, region.Generators[(int)GeneratorEnum.FrequencyModulationLFO] / 1200.0) * 8.176);
     mod_lfo.Generator = AudioSynthesis.Bank.Components.Generators.Generator.DefaultSine;
     vib_lfo = new LfoDescriptor();
     vib_lfo.DelayTime = (float)Math.Pow(2, region.Generators[(int)GeneratorEnum.DelayVibratoLFO] / 1200.0);
     vib_lfo.Frequency = (float)(Math.Pow(2, region.Generators[(int)GeneratorEnum.FrequencyVibratoLFO] / 1200.0) * 8.176);
     vib_lfo.Generator = AudioSynthesis.Bank.Components.Generators.Generator.DefaultSine;
 }
 public override void Load(DescriptorList description, AssetManager assets)
 {
     //read in sfz params
     CustomDescriptor sfzConfig = description.FindCustomDescriptor("sfzi");
     exTarget = (int)sfzConfig.Objects[0];
     exGroup = (int)sfzConfig.Objects[1];
     sfzVolume = (float)sfzConfig.Objects[2];
     sfzPan = new PanComponent((float)sfzConfig.Objects[3], PanFormulaEnum.Neg3dBCenter);
     ampKeyTrack = (float)sfzConfig.Objects[4];
     ampRootKey = (byte)sfzConfig.Objects[5];
     ampVelTrack = (float)sfzConfig.Objects[6];
     //read in the generator info
     GeneratorDescriptor gdes = description.GenDescriptions[0];
     if (gdes.SamplerType != WaveformEnum.SampleData)
         throw new Exception("Sfz can only support sample data generators.");
     gen = gdes.ToGenerator(assets);
     //read in the envelope info
     ptch_env = description.EnvelopeDescriptions[0];
     fltr_env = description.EnvelopeDescriptions[1];
     amp_env = description.EnvelopeDescriptions[2];
     //read in the lfo info
     ptch_lfo = description.LfoDescriptions[0];
     fltr_lfo = description.LfoDescriptions[1];
     amp_lfo = description.LfoDescriptions[2];
     //read in the filter info
     fltr = description.FilterDescriptions[0];
 }
 public override void Load(DescriptorList description, AssetManager assets)
 {
     CustomDescriptor fmConfig = description.FindCustomDescriptor("fm2c");
     cIndex = (double)fmConfig.Objects[0];
     mIndex = (double)fmConfig.Objects[1];
     feedBack = (double)fmConfig.Objects[2];
     sync = GetSyncModeFromString((string)fmConfig.Objects[3]);
     if (description.GenDescriptions[0].LoopMethod != LoopModeEnum.Continuous || description.GenDescriptions[1].LoopMethod != LoopModeEnum.Continuous)
         throw new Exception("Fm2 patches must have continuous generators with wrapping bounds.");
     cGen = description.GenDescriptions[0].ToGenerator(assets);
     mGen = description.GenDescriptions[1].ToGenerator(assets);
     cEnv = description.EnvelopeDescriptions[0];
     mEnv = description.EnvelopeDescriptions[1];
     lfo = description.LfoDescriptions[0];
 }