feat(sointu): show filter frequency in Hz

Closes #158.
This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-10-06 21:54:19 +03:00
parent 47d7568552
commit b538737643
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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