Exemplo n.º 1
0
        public void NoteOffAll(bool immediate)
        {
            var node = _voiceManager.ActiveVoices.First;

            if (immediate)
            {//if immediate ignore hold pedals and clear the entire registry
                _voiceManager.ClearRegistry();
                while (node != null)
                {
                    node.Value.StopImmediately();
                    var delnode = node;
                    node = node.Next;
                    _voiceManager.ActiveVoices.Remove(delnode);
                    _voiceManager.FreeVoices.AddFirst(delnode.Value);
                }
            }
            else
            {//otherwise we have to check for hold pedals and double check the registry before removing the voice
                while (node != null)
                {
                    VoiceParameters voiceParams = node.Value.VoiceParams;
                    if (voiceParams.State == VoiceStateEnum.Playing)
                    {
                        //if hold pedal is enabled do not stop the voice
                        if (_synthChannels[voiceParams.Channel].HoldPedal)
                        {
                            voiceParams.NoteOffPending = true;
                        }
                        else
                        {
                            node.Value.Stop();
                            _voiceManager.RemoveVoiceFromRegistry(node.Value);
                        }
                    }
                    node = node.Next;
                }
            }
        }
Exemplo n.º 2
0
 public Voice()
 {
     VoiceParams = new VoiceParameters();
 }
Exemplo n.º 3
0
 public Voice()
 {
     VoiceParams = new VoiceParameters();
 }
Exemplo n.º 4
0
 public abstract void Process(VoiceParameters voiceparams, int startIndex, int endIndex);
Exemplo n.º 5
0
 public abstract void Stop(VoiceParameters voiceparams);
Exemplo n.º 6
0
 public override void Stop(VoiceParameters voiceparams)
 {
     gen.Release(voiceparams.GeneratorParams[0]);
     if (gen.LoopMode != LoopMode.OneShot)
     {
         voiceparams.Envelopes[0].Release(SynthConstants.DenormLimit);
         voiceparams.Envelopes[1].ReleaseSf2VolumeEnvelope();
     }
 }
Exemplo n.º 7
0
 public abstract bool Start(VoiceParameters voiceparams);
Exemplo n.º 8
0
 public override bool Start(VoiceParameters voiceparams)
 {
     int note = keyOverride > -1 ? keyOverride : voiceparams.Note;
     int vel = velOverride > -1 ? velOverride : voiceparams.Velocity;
     //setup generator
     voiceparams.GeneratorParams[0].QuickSetup(gen);
     //setup envelopes
     voiceparams.Envelopes[0].QuickSetupSf2(voiceparams.SynthParams.Synth.SampleRate, note, keynumToModEnvHold, keynumToModEnvDecay, false, mod_env);
     voiceparams.Envelopes[1].QuickSetupSf2(voiceparams.SynthParams.Synth.SampleRate, note, keynumToVolEnvHold, keynumToVolEnvDecay, true, vel_env);
     //setup filter
     //voiceparams.pData[0].int1 = iniFilterFc - (int)(2400 * CalculateModulator(SourceTypeEnum.Linear, TransformEnum.Linear, DirectionEnum.MaxToMin, PolarityEnum.Unipolar, voiceparams.velocity, 0, 127));
     //if (iniFilterFc >= 13500 && fltr.Resonance <= 1)
     voiceparams.Filters[0].Disable();
     //else
     //    voiceparams.filters[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, note, 1f, fltr);
     //setup lfos
     voiceparams.Lfos[0].QuickSetup(voiceparams.SynthParams.Synth.SampleRate, mod_lfo);
     voiceparams.Lfos[1].QuickSetup(voiceparams.SynthParams.Synth.SampleRate, vib_lfo);
     //calculate initial pitch
     voiceparams.PitchOffset = (note - gen.RootKey) * gen.KeyTrack + gen.Tune;
     voiceparams.PitchOffset += (int)(100.0 * (voiceparams.SynthParams.MasterCoarseTune + (voiceparams.SynthParams.MasterFineTune.Combined - 8192.0) / 8192.0));
     //calculate initial volume
     voiceparams.VolOffset = initialAttn;
     voiceparams.VolOffset -= 96.0f * (float)CalculateModulator(SourceTypeEnum.Concave, TransformEnum.Linear, DirectionEnum.MaxToMin, PolarityEnum.Unipolar, voiceparams.Velocity, 0, 127);
     voiceparams.VolOffset -= 96.0f * (float)CalculateModulator(SourceTypeEnum.Concave, TransformEnum.Linear, DirectionEnum.MaxToMin, PolarityEnum.Unipolar, voiceparams.SynthParams.Volume.Coarse, 0, 127);
     //check if we have finished before we have begun
     return voiceparams.GeneratorParams[0].CurrentState != GeneratorState.Finished && voiceparams.Envelopes[1].CurrentStage != EnvelopeState.None;
 }
Exemplo n.º 9
0
        public override void Process(VoiceParameters voiceparams, int startIndex, int endIndex)
        {
            //--Base pitch calculation
            var basePitchFrequency = SynthHelper.CentsToPitch(voiceparams.SynthParams.CurrentPitch)*gen.Frequency;
            var pitchWithBend = basePitchFrequency*SynthHelper.CentsToPitch(voiceparams.PitchOffset);
            var basePitch = pitchWithBend / voiceparams.SynthParams.Synth.SampleRate;

            float baseVolume = voiceparams.SynthParams.Synth.MasterVolume * voiceparams.SynthParams.CurrentVolume * voiceparams.SynthParams.Synth.MixGain;
            //--Main Loop
            for (int x = startIndex; x < endIndex; x += SynthConstants.DefaultBlockSize * voiceparams.SynthParams.Synth.AudioChannels)
            {
                voiceparams.Envelopes[0].Increment(SynthConstants.DefaultBlockSize);
                voiceparams.Envelopes[1].Increment(SynthConstants.DefaultBlockSize);
                voiceparams.Lfos[0].Increment(SynthConstants.DefaultBlockSize);
                voiceparams.Lfos[1].Increment(SynthConstants.DefaultBlockSize);
                //--Calculate pitch and get next block of samples
                gen.GetValues(voiceparams.GeneratorParams[0], voiceparams.BlockBuffer, basePitch *
                    SynthHelper.CentsToPitch((int)(voiceparams.Envelopes[0].Value * modEnvToPitch +
                    voiceparams.Lfos[0].Value * modLfoToPitch + voiceparams.Lfos[1].Value * vibLfoToPitch)));
                //--Filter
                if (voiceparams.Filters[0].Enabled)
                {
                    double centsFc = voiceparams.PData[0].Int1 + voiceparams.Lfos[0].Value * modLfoToFilterFc + voiceparams.Envelopes[0].Value * modEnvToFilterFc;
                    if (centsFc > 13500)
                        centsFc = 13500;
                    voiceparams.Filters[0].CutOff = SynthHelper.KeyToFrequency(centsFc / 100.0, 69);
                    if (voiceparams.Filters[0].CoeffNeedsUpdating)
                        voiceparams.Filters[0].ApplyFilterInterp(voiceparams.BlockBuffer, voiceparams.SynthParams.Synth.SampleRate);
                    else
                        voiceparams.Filters[0].ApplyFilter(voiceparams.BlockBuffer);
                }
                //--Volume calculation
                float volume = (float)SynthHelper.DBtoLinear(voiceparams.VolOffset + voiceparams.Envelopes[1].Value + voiceparams.Lfos[0].Value * modLfoToVolume) * baseVolume;

                //--Mix block based on number of channels
                if (voiceparams.SynthParams.Synth.AudioChannels == 2)
                    voiceparams.MixMonoToStereoInterp(x,
                        volume * pan.Left * voiceparams.SynthParams.CurrentPan.Left,
                        volume * pan.Right * voiceparams.SynthParams.CurrentPan.Right);
                else
                    voiceparams.MixMonoToMonoInterp(x, volume);
                //--Check and end early if necessary
                if ((voiceparams.Envelopes[1].CurrentStage > EnvelopeState.Hold && volume <= SynthConstants.NonAudible) || voiceparams.GeneratorParams[0].CurrentState == GeneratorState.Finished)
                {
                    voiceparams.State = VoiceStateEnum.Stopped;
                    return;
                }
            }
        }
Exemplo n.º 10
0
 public override void Stop(VoiceParameters voiceparams)
 {
 }
Exemplo n.º 11
0
        public override void Process(VoiceParameters voiceparams, int startIndex, int endIndex)
        {

        }
Exemplo n.º 12
0
 public override bool Start(VoiceParameters voiceparams)
 {
     return false;
 }