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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_Equaliser.h
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
14class EqualiserPlugin : public Plugin
15{
16public:
18 ~EqualiserPlugin() override;
19
20 //==============================================================================
22 float getDBGainAtFrequency (float f);
23
24 //==============================================================================
25 static const char* getPluginName() { return NEEDS_TRANS("4-Band Equaliser"); }
26 static const char* xmlTypeName;
27
28 juce::String getName() const override { return TRANS("4-Band Equaliser"); }
29 juce::String getPluginType() override { return xmlTypeName; }
30 juce::String getShortName (int) override { return "EQ"; }
31 juce::String getTooltip() override;
32 bool needsConstantBufferSize() override { return false; }
33
34 int getNumOutputChannelsGivenInputs (int numInputChannels) override { return juce::jmin (numInputChannels, (int) EQ_CHANS); }
35
36 juce::String getSelectableDescription() override { return TRANS("4-Band Equaliser Plugin"); }
37
38 void initialise (const PluginInitialisationInfo&) override;
39 void deinitialise() override;
40 void applyToBuffer (const PluginRenderContext&) override;
41
42 void resetToDefault();
43 void restorePluginStateFromValueTree (const juce::ValueTree&) override;
44
45 static constexpr float minFreq = 20.0f;
46 static constexpr float maxFreq = 20000.0f;
47 static constexpr float minGain = -20.0f;
48 static constexpr float maxGain = 20.0f;
49 static constexpr float minQ = 0.1f;
50 static constexpr float maxQ = 4.0f;
51
52 void setLowGain (float v) { loGain ->setParameter (juce::jlimit (minGain, maxGain, v), juce::sendNotification); }
53 void setLowFreq (float v) { loFreq ->setParameter (juce::jlimit (minFreq, maxFreq, v), juce::sendNotification); }
54 void setLowQ (float v) { loQ ->setParameter (juce::jlimit (minQ, maxQ, v), juce::sendNotification); }
55 void setMidGain1 (float v) { midGain1->setParameter (juce::jlimit (minGain, maxGain, v), juce::sendNotification); }
56 void setMidFreq1 (float v) { midFreq1->setParameter (juce::jlimit (minFreq, maxFreq, v), juce::sendNotification); }
57 void setMidQ1 (float v) { midQ1 ->setParameter (juce::jlimit (minQ, maxQ, v), juce::sendNotification); }
58 void setMidGain2 (float v) { midGain2->setParameter (juce::jlimit (minGain, maxGain, v), juce::sendNotification); }
59 void setMidFreq2 (float v) { midFreq2->setParameter (juce::jlimit (minFreq, maxFreq, v), juce::sendNotification); }
60 void setMidQ2 (float v) { midQ2 ->setParameter (juce::jlimit (minQ, maxQ, v), juce::sendNotification); }
61 void setHighGain (float v) { hiGain ->setParameter (juce::jlimit (minGain, maxGain, v), juce::sendNotification); }
62 void setHighFreq (float v) { hiFreq ->setParameter (juce::jlimit (minFreq, maxFreq, v), juce::sendNotification); }
63 void setHighQ (float v) { hiQ ->setParameter (juce::jlimit (minQ, maxQ, v), juce::sendNotification); }
64
65 juce::CachedValue<float> loFreqValue, loGainValue, loQValue,
66 hiFreqValue, hiGainValue, hiQValue,
67 midFreqValue1, midGainValue1, midQValue1,
68 midFreqValue2, midGainValue2, midQValue2;
69
70 juce::CachedValue<bool> phaseInvert;
71
72 AutomatableParameter::Ptr loFreq, loGain, loQ,
73 hiFreq, hiGain, hiQ,
74 midFreq1, midGain1, midQ1,
75 midFreq2, midGain2, midQ2;
76
77private:
78 class EQAutomatableParameter;
79
80 Spline curve;
81 float lastSampleRate = 44100.0f;
82 bool curveNeedsUpdating = true;
83
84 enum { EQ_CHANS = 2 };
85 juce::IIRFilter low[EQ_CHANS], mid1[EQ_CHANS], mid2[EQ_CHANS], high[EQ_CHANS];
86
87 enum { fftOrder = 10 };
88 juce::dsp::FFT fft { fftOrder };
89
90 void updateIIRFilters();
91 std::atomic<bool> needToUpdateFilters[4];
92 juce::CriticalSection filterLock;
93
94 void valueTreePropertyChanged (juce::ValueTree&, const juce::Identifier&) override;
95
97};
98
99}} // namespace tracktion { inline namespace engine
void deinitialise() override
Called after play stops to release resources.
int getNumOutputChannelsGivenInputs(int numInputChannels) override
This must return the number of output channels that the plugin will produce, given a number of input ...
juce::String getName() const override
The name of the type, e.g.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
void applyToBuffer(const PluginRenderContext &) override
Process the next block of data.
juce::String getTooltip() override
default returns the name, others can return special stuff if needed
float getDBGainAtFrequency(float f)
Finds the gain at a frequency - used to plot the EQ graph.
#define TRANS(stringLiteral)
#define NEEDS_TRANS(stringLiteral)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
constexpr Type jmin(Type a, Type b)
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
sendNotification
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.