From b538737643efd7f5e3353563cfff36dcaa677e2f Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:54:19 +0300 Subject: [PATCH] feat(sointu): show filter frequency in Hz Closes #158. --- CHANGELOG.md | 3 +++ patch.go | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec99af..9dcc449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added +- The filter unit frequency parameter is displayed in Hz, corresponding roughly + to the resonant frequency of the filter ([#158][i158]) - Include version info in the binaries, as given be `git describe`. This version info is shown as a label in the tracker and can be checked with `-v` flag in the command line tools. @@ -231,3 +233,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [i148]: https://github.com/vsariola/sointu/issues/148 [i149]: https://github.com/vsariola/sointu/issues/149 [i150]: https://github.com/vsariola/sointu/issues/150 +[i158]: https://github.com/vsariola/sointu/issues/158 diff --git a/patch.go b/patch.go index 7602fef..6641288 100644 --- a/patch.go +++ b/patch.go @@ -95,7 +95,7 @@ var UnitTypes = map[string]([]UnitParameter){ {Name: "decibels", MinValue: 0, MaxValue: 128, CanSet: true, CanModulate: true, DisplayFunc: func(v int) (string, string) { return formatFloat(40 * (float64(v)/64 - 1)), "dB" }}}, "filter": []UnitParameter{ {Name: "stereo", MinValue: 0, MaxValue: 1, CanSet: true, CanModulate: false}, - {Name: "frequency", MinValue: 0, MaxValue: 128, CanSet: true, CanModulate: true}, + {Name: "frequency", MinValue: 0, MaxValue: 128, CanSet: true, CanModulate: true, DisplayFunc: filterFrequencyDispFunc}, {Name: "resonance", MinValue: 0, MaxValue: 128, CanSet: true, CanModulate: true}, {Name: "lowpass", MinValue: 0, MaxValue: 1, CanSet: true, CanModulate: false}, {Name: "bandpass", MinValue: 0, MaxValue: 1, CanSet: true, CanModulate: false}, @@ -192,6 +192,23 @@ func arrDispFunc(arr []string) UnitParameterDisplayFunc { } } +func filterFrequencyDispFunc(v int) (string, string) { + // for reason I don't entirely understand, when r = 0, the peak seems to be + // at omega = f^2 I studied this with matlab, with + // syms f2 r z + // A = [1 f2;-f2 1-f2*f2-f2*r]; B = [0;f2]; C = [1 0]; D = 0; % C = [0 1] for the band pass filter + // H = C*inv(z*eye(2)-A)*B+D % transfer function + // and then setting r = 0 and different values of f2 with + // z = tf('z'); + // H = f2^2/(f2^2*z + r*f2*z - r*f2 + z^2 - 2*z + 1) % given by the above + // bodeplot(H); + // Then had to convert omega to Hz, taking into account the 44100 sampling + // rate + f := float64(v) / 128 + hz := 44100 * f * f / math.Pi / 2 + return strconv.FormatFloat(hz, 'f', 0, 64), "Hz" +} + func compressorTimeDispFunc(v int) (string, string) { alpha := math.Pow(2, -24*float64(v)/128) // alpha is the "smoothing factor" of first order low pass iir sec := -1 / (44100 * math.Log(1-alpha)) // from smoothing factor to time constant, https://en.wikipedia.org/wiki/Exponential_smoothing