Krotos Modules 3
Loading...
Searching...
No Matches
krotos::Filter Class Reference

Filter an audio signal. More...

#include <Filter.h>

Public Types

enum class  Mode {
  LPF12 , LPF24 , HPF12 , HPF24 ,
  BPF12 , BPF24
}
 

Public Member Functions

 Filter ()
 
 ~Filter ()=default
 
void prepareToPlay (double sampleRate, int)
 
void reset () noexcept
 
float processSample (float inputValue, int channelToUse) noexcept
 
void setMode (Mode newMode) noexcept
 
void setCutoff (float newCutoff) noexcept
 
void setResonance (float newResonance) noexcept
 
void setDrive (float newDrive) noexcept
 

Private Member Functions

void setSampleRate (float newValue) noexcept
 
void setNumChannels (int newValue)
 

Private Attributes

std::vector< std::array< float, numStates > > state
 
std::array< float, numStatesA
 
float cutoffFreqHz {1.0f}
 
float cutoffFreqScaler
 
float cutoffTransformValue
 
float resonance {0.0f}
 
float scaledResonanceValue
 
float drive
 
float drive2
 
float gain
 
float gain2
 
float comp
 
dsp::LookupTableTransform< float > saturationLUT {[](float x) { return std::tanh(x); }, -5.0f, 5.0f, 128}
 
Mode mode {Mode::LPF12}
 
DryWet m_mix
 
const int NUM_CHANNELS_MAX {2}
 

Static Private Attributes

static constexpr size_t numStates = 5
 

Detailed Description

Filter an audio signal.

This class is a basic filter implementation derived from the juce::dsp::LadderFilter class. The code was copied from JUCE in order to remove the smoothers and provide better integration with the Kwidget system, which already handles parameter smoothing.

This class can also be used to add other types of filtering, such as the formant filter present in krotos_modules_2.

TODO: Add formant filtering capability.

Member Enumeration Documentation

◆ Mode

enum class krotos::Filter::Mode
strong
Enumerator
LPF12 
LPF24 
HPF12 
HPF24 
BPF12 
BPF24 

Constructor & Destructor Documentation

◆ Filter()

krotos::Filter::Filter ( )
inline

Constructs a filter object. Call prepareToPlay() before using it!

◆ ~Filter()

krotos::Filter::~Filter ( )
default

Member Function Documentation

◆ prepareToPlay()

void krotos::Filter::prepareToPlay ( double sampleRate,
int  )
inline

Call this function to prepare the filter for processing, or whenever the sample rate and block size change.

◆ processSample()

float krotos::Filter::processSample ( float inputValue,
int channelToUse )
inlinenoexcept

Process a single sample through a particular channel.

◆ reset()

void krotos::Filter::reset ( )
inlinenoexcept

Resets the internal state variables of the filter.

◆ setCutoff()

void krotos::Filter::setCutoff ( float newCutoff)
inlinenoexcept

Sets the cutoff frequency of the filter.

Parameters
newCutoffcutoff frequency in Hz

◆ setDrive()

void krotos::Filter::setDrive ( float newDrive)
inlinenoexcept

Sets the amount of saturation in the filter.

Parameters
newDrivesaturation amount; it can be any number greater than or equal to one. Higher values result in more distortion.

◆ setMode()

void krotos::Filter::setMode ( Mode newMode)
inlinenoexcept

Sets filter mode.

◆ setNumChannels()

void krotos::Filter::setNumChannels ( int newValue)
inlineprivate

◆ setResonance()

void krotos::Filter::setResonance ( float newResonance)
inlinenoexcept

Sets the resonance of the filter.

Parameters
newResonancea value between 0 and 1; higher values increase the resonance and can result in self oscillation!

◆ setSampleRate()

void krotos::Filter::setSampleRate ( float newValue)
inlineprivatenoexcept

Member Data Documentation

◆ A

std::array<float, numStates> krotos::Filter::A
private

◆ comp

float krotos::Filter::comp
private

◆ cutoffFreqHz

float krotos::Filter::cutoffFreqHz {1.0f}
private

◆ cutoffFreqScaler

float krotos::Filter::cutoffFreqScaler
private

◆ cutoffTransformValue

float krotos::Filter::cutoffTransformValue
private

◆ drive

float krotos::Filter::drive
private

◆ drive2

float krotos::Filter::drive2
private

◆ gain

float krotos::Filter::gain
private

◆ gain2

float krotos::Filter::gain2
private

◆ m_mix

DryWet krotos::Filter::m_mix
private

◆ mode

Mode krotos::Filter::mode {Mode::LPF12}
private

◆ NUM_CHANNELS_MAX

const int krotos::Filter::NUM_CHANNELS_MAX {2}
private

◆ numStates

size_t krotos::Filter::numStates = 5
staticconstexprprivate

◆ resonance

float krotos::Filter::resonance {0.0f}
private

◆ saturationLUT

dsp::LookupTableTransform<float> krotos::Filter::saturationLUT {[](float x) { return std::tanh(x); }, -5.0f, 5.0f, 128}
private

◆ scaledResonanceValue

float krotos::Filter::scaledResonanceValue
private

◆ state

std::vector<std::array<float, numStates> > krotos::Filter::state
private

The documentation for this class was generated from the following file: