예제 #1
0
 private void SetRealValue(double value, EChangeType changeType)
 {
     if (!DSPFunctions.IsZero(Math.Abs(RealValue - value)))
     {
         RealValue = value;
         OnValueChange?.Invoke(changeType);
     }
 }
예제 #2
0
 public FrequencyParameter(string name, string label, string shortLabel, double min = 1, double max = 20000, bool canBeAutomated = true) :
     base(name, label, shortLabel, min, max, 1, canBeAutomated)
 {
     if (Min < 0 ||
         DSPFunctions.IsZero(Min))
     {
         throw new ArgumentException();
     }
 }
예제 #3
0
        public double ModifyValue(double currentValue, int sampleNumber)
        {
            var gain = Gain.Value;

            if (DSPFunctions.IsZero(gain))
            {
                return(currentValue);
            }

            var amplitude = GetCurrentAmplitude(sampleNumber);

            gain *= amplitude * Math.Min(currentValue, 1 - currentValue);

            return(DSPFunctions.Clamp01(currentValue + gain));
        }
예제 #4
0
        protected Parameter(string name, string description, string label,
                            double min, double max, double step, bool canBeAutomated = true) :
            base(name, description, label, canBeAutomated)
        {
            if (max <= min ||
                step > (max - min))
            {
                throw new ArgumentException();
            }

            Min = min;
            Max = max;

            Step     = Range / Math.Max(1, (int)(1 / DSPFunctions.Clamp01(step / Range)));
            RealStep = Step / Range;
        }
예제 #5
0
        private void Knob_OnMouseMove(object sender, MouseEventArgs e)
        {
            if (_isMouseDown)
            {
                var position = e.GetPosition(this);
                var delta    = position.Y - _mouseStartPoint.Y;

                _value = _knobStartValue - delta * KDeltaFactor;
                _value = DSPFunctions.Clamp01(_value);
                _value = (int)(_value * _invertedStep) / _invertedStep;

                if (_parameter != null)
                {
                    SetValue();
                }
                else
                {
                    UpdateController();
                }
            }
        }
예제 #6
0
        public double NextSample(int i)
        {
            double value = 0.0;
            double t     = phase / twoPI;

            if (type == EOscillatorType.Sine)
            {
                value = naiveWaveformForMode(EOscillatorType.Sine);
            }
            else if (type == EOscillatorType.Saw)
            {
                value  = naiveWaveformForMode(EOscillatorType.Saw);
                value -= PolyBlep(t);
            }
            else if (type == EOscillatorType.Noise)
            {
                value = naiveWaveformForMode(EOscillatorType.Noise);
            }
            else
            {
                value  = naiveWaveformForMode(EOscillatorType.Square);
                value += PolyBlep(t);
                value -= PolyBlep(DSPFunctions.Fmod(t + 0.5, 1.0));
                if (type == EOscillatorType.Triangle)
                {
                    // Leaky integrator: y[n] = A * x[n] + (1 - A) * y[n-1]
                    value      = phaseIncrement * value + (1 - phaseIncrement) * lastOutput;
                    lastOutput = value;
                }
            }

            UpdateIncrement(i);

            phase += phaseIncrement;
            while (phase >= twoPI)
            {
                phase -= twoPI;
            }
            return(value);
        }
예제 #7
0
        private void MidiListenerOnNoteOn(object sender, MidiListener.NoteEventArgs e)
        {
            var newNote = e.NoteAbsolute;

            // если уже была нажата нота, нужно скопировать ее фазу, чтобы не было щелчка
            double time = 0;

            if (_tone != null)
            {
                // фаза от 0 до 1
                var tonePhase = DSPFunctions.Frac(_tone.Time * GetToneFrequency(_tone.Note, 0));

                // фаза второй ноты должна быть такой же, определим время по частоте
                time = tonePhase / GetToneFrequency(newNote, 0);
            }

            _tone = new Tone
            {
                Time = time,
                Note = e.NoteAbsolute
            };
        }
예제 #8
0
 private double GetToneFrequency(int sampleNumber)
 {
     return(DSPFunctions.GetNoteFrequency(note + paramOwner.Semitone.ProcessedValue(sampleNumber) + paramOwner.Fine.ProcessedValue(sampleNumber)));
 }
예제 #9
0
 private bool IsRealValueTrue()
 {
     return(!DSPFunctions.IsZero(GetRealValue()));
 }
예제 #10
0
 public override string FromValueToString(double value)
 {
     return(PrintDouble(DSPFunctions.AmplitudeToDb(value)));
 }
예제 #11
0
 public double GetDb()
 {
     return(DSPFunctions.AmplitudeToDb(Value));
 }
예제 #12
0
 public override double FromStringToValue(string s)
 {
     return(DSPFunctions.Clamp(ParseDouble(s), Min, Max));
 }
예제 #13
0
 public override double FromReal(double value)
 {
     return(DSPFunctions.Lerp(Min, Max, value));
 }
예제 #14
0
 public override int FromStringToValue(string s)
 {
     return((int)Math.Round(DSPFunctions.Clamp(int.Parse(s, CultureInfo.InvariantCulture), Min, Max), MidpointRounding.AwayFromZero));
 }
예제 #15
0
 public override int FromReal(double value)
 {
     return((int)Math.Round(DSPFunctions.Lerp(Min, Max, value), MidpointRounding.AwayFromZero));
 }
예제 #16
0
        public override double FromStringToValue(string s)
        {
            var volumeDb = DSPFunctions.Clamp(ParseDouble(s), DSPFunctions.KMinADb, DSPFunctions.KMaxADb);

            return((volumeDb - DSPFunctions.KMinADb) / (DSPFunctions.KMaxADb - DSPFunctions.KMinADb));
        }
예제 #17
0
 private double GetToneFrequency(int note, int sampleNumber)
 {
     return(DSPFunctions.GetNoteFrequency(note + Fine.ProcessedValue(sampleNumber)));
 }