tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_LowPass.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14LowPassPlugin::LowPassPlugin (PluginCreationInfo info) : Plugin (info)
15{
16 auto um = getUndoManager();
17
18 frequencyValue.referTo (state, IDs::frequency, um, 4000.0f);
19 mode.referTo (state, IDs::mode, um, "lowpass");
20
21 frequency = addParam ("frequency", TRANS("Frequency"), { 10.0f, 22000.0f },
22 [] (float value) { return juce::String (juce::roundToInt (value)) + " Hz"; },
23 [] (const juce::String& s) { return s.getFloatValue(); });
24
25 frequency->attachToCurrentValue (frequencyValue);
26}
27
28LowPassPlugin::~LowPassPlugin()
29{
30 notifyListenersOfDeletion();
31
32 frequency->detachFromCurrentValue();
33}
34
35const char* LowPassPlugin::xmlTypeName = "lowpass";
36
37void LowPassPlugin::updateFilters()
38{
39 const float newFreq = frequency->getCurrentValue();
40 const bool nowLowPass = isLowPass();
41
42 if (currentFilterFreq != newFreq || nowLowPass != isCurrentlyLowPass)
43 {
44 currentFilterFreq = newFreq;
45 isCurrentlyLowPass = nowLowPass;
46
47 auto c = nowLowPass ? juce::IIRCoefficients::makeLowPass (sampleRate, newFreq)
48 : juce::IIRCoefficients::makeHighPass (sampleRate, newFreq);
49
50 filter[0].setCoefficients (c);
51 filter[1].setCoefficients (c);
52 }
53}
54
55void LowPassPlugin::initialise (const PluginInitialisationInfo& info)
56{
57 sampleRate = info.sampleRate;
58
59 for (int i = 0; i < numElementsInArray (filter); ++i)
60 filter[i].reset();
61
62 currentFilterFreq = 0;
63 updateFilters();
64}
65
66void LowPassPlugin::deinitialise()
67{
68}
69
70void LowPassPlugin::applyToBuffer (const PluginRenderContext& fc)
71{
72 if (fc.destBuffer != nullptr)
73 {
74 SCOPED_REALTIME_CHECK
75
76 updateFilters();
77
78 clearChannels (*fc.destBuffer, 2, -1, fc.bufferStartSample, fc.bufferNumSamples);
79
80 for (int i = std::min (2, fc.destBuffer->getNumChannels()); --i >= 0;)
81 filter[i].processSamples (fc.destBuffer->getWritePointer (i, fc.bufferStartSample), fc.bufferNumSamples);
82
83 sanitiseValues (*fc.destBuffer, fc.bufferStartSample, fc.bufferNumSamples, 3.0f);
84 }
85}
86
87}} // namespace tracktion { inline namespace engine
Type * getWritePointer(int channelNumber) noexcept
int getNumChannels() const noexcept
static IIRCoefficients makeLowPass(double sampleRate, double frequency) noexcept
float getFloatValue() const noexcept
#define TRANS(stringLiteral)
T min(T... args)
int roundToInt(const FloatType value) noexcept
Passed into Plugins when they are being initialised, to give them useful contextual information that ...
The context passed to plugin render methods to provide it with buffers to fill.
int bufferNumSamples
The number of samples to write into the audio buffer.
juce::AudioBuffer< float > * destBuffer
The target audio buffer which needs to be filled.
int bufferStartSample
The index of the start point in the audio buffer from which data must be written.