Documentation
¶
Index ¶
- Constants
- type BandPassIIR
- type CompositFilter
- type Filter
- type FilterChain
- type HighPassIIR
- type LowPassIIR
- type NotchIIR
- type PeakingIIR
- func (iir *PeakingIIR) Filter(value float64) float64
- func (iir *PeakingIIR) Reset()
- func (iir *PeakingIIR) SetBandwidth(freq float64)
- func (iir *PeakingIIR) SetCenter(freq float64)
- func (iir *PeakingIIR) SetGainLinear(gain float64)
- func (iir *PeakingIIR) SetGaindB(gaindB float64)
- func (iir *PeakingIIR) SetQualityFactor(q float64)
Constants ¶
const Tau = math.Pi * 2 // why would you only have half the pie?
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BandPassIIR ¶
type BandPassIIR struct {
// contains filtered or unexported fields
}
func NewBandPassIIR ¶
func NewBandPassIIR(sampleRate uint) *BandPassIIR
NewBandPassIIR creates a new band pass filter object that implements the Filter interface. It composed of a high-pass and a low-pass filter with a common cutoff frequency. The sample rate is in Hz and can't be changed later.
func (*BandPassIIR) Filter ¶
func (irr *BandPassIIR) Filter(value float64) float64
Filter takes a value and applies the band-pass filter to it.
func (*BandPassIIR) Reset ¶
func (irr *BandPassIIR) Reset()
Reset simply resets the high-pass and low-pass filters.
func (*BandPassIIR) SetCutoff ¶
func (irr *BandPassIIR) SetCutoff(freq float64)
SetCutoff sets the same cutoff frequency for the high-pass and the low-pass filters. The freq value is in Hz.
type CompositFilter ¶
type CompositFilter struct {
// contains filtered or unexported fields
}
func NewCompositFilter ¶
func NewCompositFilter() *CompositFilter
NewCompositFilter creates an object that can hold multiple filter chains, each having an a gain value. It implements the Filter interface. Used to run the value through the chains separately and returns an average value. The gain can be used as a weight.
func (*CompositFilter) AddFilterChain ¶
func (cf *CompositFilter) AddFilterChain(chain FilterChain, gain float64)
AddFilterChain adds a filter chain with a gain value. The gain can be used as a weight and best to have it [0-1].
func (*CompositFilter) ClearFilterChains ¶
func (cf *CompositFilter) ClearFilterChains()
ClearFilters simply empties the filter and gain slices.
func (*CompositFilter) Filter ¶
func (cf *CompositFilter) Filter(value float64) float64
Filter runs the value through the filter chains separately, taking the gains into account, and averages the results.
func (*CompositFilter) Reset ¶
func (cf *CompositFilter) Reset()
Reset simply resets all the filters in the chain.
type FilterChain ¶
type FilterChain struct {
// contains filtered or unexported fields
}
func NewFilterChain ¶
func NewFilterChain() *FilterChain
NewFilterChain creates a filter chain object that chains any object that implements the Filter interface. The processing order is in the order of the AddFilter calls.
func (*FilterChain) AddFilter ¶
func (fch *FilterChain) AddFilter(filter Filter)
AddFilter adds a filter to the filter chain. The processing order is in the order of these calls.
func (*FilterChain) ClearFilters ¶
func (fch *FilterChain) ClearFilters()
ClearFilters simply empties the filter slice.
func (*FilterChain) Filter ¶
func (fch *FilterChain) Filter(value float64) float64
Filter takes a value and runs it through the filter chain.
func (*FilterChain) Reset ¶
func (fch *FilterChain) Reset()
Reset simply resets all the filters in the chain.
type HighPassIIR ¶
type HighPassIIR struct {
// contains filtered or unexported fields
}
1st order High-Pass IIR as seen at https://www.youtube.com/@PhilsLab
func NewHighPassIIR ¶
func NewHighPassIIR(sampleRate uint) *HighPassIIR
NewHighPassIIR creates a new 1st order high-pass IIR filter object that implements the Filter interface. It lets frequencies through above the cutoff frequency. The sample rate is in Hz and can't be changed later.
func (*HighPassIIR) Filter ¶
func (iir *HighPassIIR) Filter(value float64) float64
Filter takes a value and applies the high-pass filter to it.
func (*HighPassIIR) Reset ¶
func (iir *HighPassIIR) Reset()
Reset clears the rolling values but keeps the coefficients.
func (*HighPassIIR) SetCutoff ¶
func (iir *HighPassIIR) SetCutoff(freq float64)
SetCutoff Calculates coefficients for the cutoff frequency. 0 <= freq <= sampleRate/2
type LowPassIIR ¶
type LowPassIIR struct {
// contains filtered or unexported fields
}
1st order Low-Pass IIR as seen at https://www.youtube.com/@PhilsLab
func NewLowPassIIR ¶
func NewLowPassIIR(sampleRate uint) *LowPassIIR
NewLowPassIIR creates a new 1st order low-pass IIR filter object that implements the Filter interface. It lets frequencies through below the cutoff frequency. The sample rate is in Hz and can't be changed later.
func (*LowPassIIR) Filter ¶
func (iir *LowPassIIR) Filter(value float64) float64
Filter takes a value and applies the low-pass filter to it.
func (*LowPassIIR) Reset ¶
func (iir *LowPassIIR) Reset()
Reset clears the rolling value but keeps the coefficients.
func (*LowPassIIR) SetCutoff ¶
func (iir *LowPassIIR) SetCutoff(freq float64)
SetCutoff Calculates coefficients for the cutoff frequency. 0 <= freq <= sampleRate/2
type NotchIIR ¶
type NotchIIR struct {
// contains filtered or unexported fields
}
2nd order Notch IIR as seen at https://www.youtube.com/@PhilsLab
func NewNotchIIR ¶
NewNotchIIR creates a new 2nd order notch IIR filter object that implements the Filter interface. It filters a frequency spectrum around a center frequency. The bandwith can be set directly with SetNotchwidth or a quality factor with SetQualityFactor.
This filter is tipically used to remove certain frequencies so there is no variable gain function. Use a PeakingIIR filter if you need that.
The sample rate is in Hz and can't be changed later.
func (*NotchIIR) Reset ¶
func (iir *NotchIIR) Reset()
Reset clears the rolling values but keeps the coefficients.
func (*NotchIIR) SetNotchwidth ¶
SetBandwidth sets how wide is the spectrum the filter processes in Hz.
func (*NotchIIR) SetQualityFactor ¶
SetQualityFactor sets how wide is the spectrum the filter processes using a quality factor.
type PeakingIIR ¶
type PeakingIIR struct {
// contains filtered or unexported fields
}
2nd order Peaking IIR as seen at https://www.youtube.com/@PhilsLab
func NewPeakingIIR ¶
func NewPeakingIIR(sampleRate uint) *PeakingIIR
NewPeakingIIR creates a new 2nd order peaking IIR filter object that implements the Filter interface. It processes a frequency spectrum around a center frequency. The bandwith can be set directly with SetBandwidth or a quality factor with SetQualityFactor. The sample rate is in Hz and can't be changed later.
func (*PeakingIIR) Filter ¶
func (iir *PeakingIIR) Filter(value float64) float64
Filter takes a value and applies the peaking filter to it.
func (*PeakingIIR) Reset ¶
func (iir *PeakingIIR) Reset()
Reset clears the rolling values but keeps the coefficients.
func (*PeakingIIR) SetBandwidth ¶
func (iir *PeakingIIR) SetBandwidth(freq float64)
SetBandwidth sets how wide is the spectrum the filter processes in Hz.
func (*PeakingIIR) SetCenter ¶
func (iir *PeakingIIR) SetCenter(freq float64)
SetCenter sets the center frequency of the filter with freq in Hz.
func (*PeakingIIR) SetGainLinear ¶
func (iir *PeakingIIR) SetGainLinear(gain float64)
SetGainLinear sets the gain as a dircets value as follows: gain > 1 -> boost, gain < 1 -> cut
func (*PeakingIIR) SetGaindB ¶
func (iir *PeakingIIR) SetGaindB(gaindB float64)
SetGaindB sets the gain using decibels
func (*PeakingIIR) SetQualityFactor ¶
func (iir *PeakingIIR) SetQualityFactor(q float64)
SetQualityFactor sets how wide is the spectrum the filter processes using a quality factor.