private void SetRealValue(double value, EChangeType changeType) { if (!DSPFunctions.IsZero(Math.Abs(RealValue - value))) { RealValue = value; OnValueChange?.Invoke(changeType); } }
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(); } }
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)); }
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; }
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(); } } }
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); }
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 }; }
private double GetToneFrequency(int sampleNumber) { return(DSPFunctions.GetNoteFrequency(note + paramOwner.Semitone.ProcessedValue(sampleNumber) + paramOwner.Fine.ProcessedValue(sampleNumber))); }
private bool IsRealValueTrue() { return(!DSPFunctions.IsZero(GetRealValue())); }
public override string FromValueToString(double value) { return(PrintDouble(DSPFunctions.AmplitudeToDb(value))); }
public double GetDb() { return(DSPFunctions.AmplitudeToDb(Value)); }
public override double FromStringToValue(string s) { return(DSPFunctions.Clamp(ParseDouble(s), Min, Max)); }
public override double FromReal(double value) { return(DSPFunctions.Lerp(Min, Max, value)); }
public override int FromStringToValue(string s) { return((int)Math.Round(DSPFunctions.Clamp(int.Parse(s, CultureInfo.InvariantCulture), Min, Max), MidpointRounding.AwayFromZero)); }
public override int FromReal(double value) { return((int)Math.Round(DSPFunctions.Lerp(Min, Max, value), MidpointRounding.AwayFromZero)); }
public override double FromStringToValue(string s) { var volumeDb = DSPFunctions.Clamp(ParseDouble(s), DSPFunctions.KMinADb, DSPFunctions.KMaxADb); return((volumeDb - DSPFunctions.KMinADb) / (DSPFunctions.KMaxADb - DSPFunctions.KMinADb)); }
private double GetToneFrequency(int note, int sampleNumber) { return(DSPFunctions.GetNoteFrequency(note + Fine.ProcessedValue(sampleNumber))); }