Exemplo n.º 1
0
 private void SetRealValue(double value, EChangeType changeType)
 {
     if (!DSPFunctions.IsZero(Math.Abs(RealValue - value)))
     {
         RealValue = value;
         OnValueChange?.Invoke(changeType);
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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;
        }
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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
            };
        }
Exemplo n.º 8
0
 private double GetToneFrequency(int sampleNumber)
 {
     return(DSPFunctions.GetNoteFrequency(note + paramOwner.Semitone.ProcessedValue(sampleNumber) + paramOwner.Fine.ProcessedValue(sampleNumber)));
 }
Exemplo n.º 9
0
 private bool IsRealValueTrue()
 {
     return(!DSPFunctions.IsZero(GetRealValue()));
 }
Exemplo n.º 10
0
 public override string FromValueToString(double value)
 {
     return(PrintDouble(DSPFunctions.AmplitudeToDb(value)));
 }
Exemplo n.º 11
0
 public double GetDb()
 {
     return(DSPFunctions.AmplitudeToDb(Value));
 }
Exemplo n.º 12
0
 public override double FromStringToValue(string s)
 {
     return(DSPFunctions.Clamp(ParseDouble(s), Min, Max));
 }
Exemplo n.º 13
0
 public override double FromReal(double value)
 {
     return(DSPFunctions.Lerp(Min, Max, value));
 }
Exemplo n.º 14
0
 public override int FromStringToValue(string s)
 {
     return((int)Math.Round(DSPFunctions.Clamp(int.Parse(s, CultureInfo.InvariantCulture), Min, Max), MidpointRounding.AwayFromZero));
 }
Exemplo n.º 15
0
 public override int FromReal(double value)
 {
     return((int)Math.Round(DSPFunctions.Lerp(Min, Max, value), MidpointRounding.AwayFromZero));
 }
Exemplo n.º 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));
        }
Exemplo n.º 17
0
 private double GetToneFrequency(int note, int sampleNumber)
 {
     return(DSPFunctions.GetNoteFrequency(note + Fine.ProcessedValue(sampleNumber)));
 }