Skip to content

Commit

Permalink
feat(sointu): show filter frequency in Hz
Browse files Browse the repository at this point in the history
Closes #158.
  • Loading branch information
vsariola committed Oct 6, 2024
1 parent 47d7568 commit b538737
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
19 changes: 18 additions & 1 deletion patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b538737

Please sign in to comment.