andrewm@0
|
1 /*
|
andrewm@0
|
2 This code accompanies the textbook:
|
andrewm@0
|
3
|
andrewm@0
|
4 Digital Audio Effects: Theory, Implementation and Application
|
andrewm@0
|
5 Joshua D. Reiss and Andrew P. McPherson
|
andrewm@0
|
6
|
andrewm@0
|
7 ---
|
andrewm@0
|
8
|
andrewm@0
|
9 Phaser: phasing effect using time-varying allpass filters
|
andrewm@0
|
10 See textbook Chapter 4: Filter Effects
|
andrewm@0
|
11
|
andrewm@0
|
12 Code by Andrew McPherson, Brecht De Man and Joshua Reiss
|
andrewm@0
|
13
|
andrewm@0
|
14 ---
|
andrewm@0
|
15
|
andrewm@0
|
16 This program is free software: you can redistribute it and/or modify
|
andrewm@0
|
17 it under the terms of the GNU General Public License as published by
|
andrewm@0
|
18 the Free Software Foundation, either version 3 of the License, or
|
andrewm@0
|
19 (at your option) any later version.
|
andrewm@0
|
20
|
andrewm@0
|
21 This program is distributed in the hope that it will be useful,
|
andrewm@0
|
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
andrewm@0
|
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
andrewm@0
|
24 GNU General Public License for more details.
|
andrewm@0
|
25
|
andrewm@0
|
26 You should have received a copy of the GNU General Public License
|
andrewm@0
|
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
andrewm@0
|
28 */
|
andrewm@0
|
29
|
andrewm@0
|
30 #ifndef __PLUGINPROCESSOR_H_4693CB6E__
|
andrewm@0
|
31 #define __PLUGINPROCESSOR_H_4693CB6E__
|
andrewm@0
|
32
|
andrewm@0
|
33 #define _USE_MATH_DEFINES
|
andrewm@0
|
34 #include "../JuceLibraryCode/JuceHeader.h"
|
andrewm@0
|
35 #include "OnePoleAllpassFilter.h"
|
andrewm@0
|
36 #include "TwoPoleAllpassFilter.h"
|
andrewm@0
|
37
|
andrewm@0
|
38 //==============================================================================
|
andrewm@0
|
39 /**
|
andrewm@0
|
40 */
|
andrewm@0
|
41 class PhaserAudioProcessor : public AudioProcessor
|
andrewm@0
|
42 {
|
andrewm@0
|
43 public:
|
andrewm@0
|
44 //==============================================================================
|
andrewm@0
|
45 PhaserAudioProcessor();
|
andrewm@0
|
46 ~PhaserAudioProcessor();
|
andrewm@0
|
47
|
andrewm@0
|
48 //==============================================================================
|
andrewm@0
|
49 void prepareToPlay (double sampleRate, int samplesPerBlock);
|
andrewm@0
|
50 void releaseResources();
|
andrewm@0
|
51 void reset();
|
andrewm@0
|
52 void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
|
andrewm@0
|
53
|
andrewm@0
|
54
|
andrewm@0
|
55 //==============================================================================
|
andrewm@0
|
56 AudioProcessorEditor* createEditor();
|
andrewm@0
|
57 bool hasEditor() const;
|
andrewm@0
|
58
|
andrewm@0
|
59 //==============================================================================
|
andrewm@0
|
60 const String getName() const;
|
andrewm@0
|
61
|
andrewm@0
|
62 int getNumParameters();
|
andrewm@0
|
63
|
andrewm@0
|
64 float getParameter (int index);
|
andrewm@0
|
65 void setParameter (int index, float newValue);
|
andrewm@0
|
66
|
andrewm@0
|
67 const String getParameterName (int index);
|
andrewm@0
|
68 const String getParameterText (int index);
|
andrewm@0
|
69
|
andrewm@0
|
70 const String getInputChannelName (int channelIndex) const;
|
andrewm@0
|
71 const String getOutputChannelName (int channelIndex) const;
|
andrewm@0
|
72 bool isInputChannelStereoPair (int index) const;
|
andrewm@0
|
73 bool isOutputChannelStereoPair (int index) const;
|
andrewm@0
|
74
|
andrewm@0
|
75 bool silenceInProducesSilenceOut() const;
|
andrewm@0
|
76 double getTailLengthSeconds() const;
|
andrewm@0
|
77 bool acceptsMidi() const;
|
andrewm@0
|
78 bool producesMidi() const;
|
andrewm@0
|
79
|
andrewm@0
|
80 //==============================================================================
|
andrewm@0
|
81 int getNumPrograms();
|
andrewm@0
|
82 int getCurrentProgram();
|
andrewm@0
|
83 void setCurrentProgram (int index);
|
andrewm@0
|
84 const String getProgramName (int index);
|
andrewm@0
|
85 void changeProgramName (int index, const String& newName);
|
andrewm@0
|
86
|
andrewm@0
|
87 //==============================================================================
|
andrewm@0
|
88 void getStateInformation (MemoryBlock& destData);
|
andrewm@0
|
89 void setStateInformation (const void* data, int sizeInBytes);
|
andrewm@0
|
90
|
andrewm@0
|
91 //==============================================================================
|
andrewm@0
|
92
|
andrewm@0
|
93 // these are used to persist the UI's size - the values are stored along with the
|
andrewm@0
|
94 // filter's other parameters, and the UI component will update them when it gets
|
andrewm@0
|
95 // resized.
|
andrewm@0
|
96 int lastUIWidth_, lastUIHeight_;
|
andrewm@0
|
97
|
andrewm@0
|
98 enum Parameters
|
andrewm@0
|
99 {
|
andrewm@0
|
100 kBaseFrequencyParam = 0,
|
andrewm@0
|
101 kSweepWidthParam,
|
andrewm@0
|
102 kDepthParam,
|
andrewm@0
|
103 kFeedbackParam,
|
andrewm@0
|
104 kLFOFrequencyParam,
|
andrewm@0
|
105 kFiltersParam,
|
andrewm@0
|
106 kWaveformParam,
|
andrewm@0
|
107 kStereoParam,
|
andrewm@0
|
108 kNumParameters
|
andrewm@0
|
109 };
|
andrewm@0
|
110
|
andrewm@0
|
111 enum Waveforms
|
andrewm@0
|
112 {
|
andrewm@0
|
113 kWaveformSine = 1,
|
andrewm@0
|
114 kWaveformTriangle,
|
andrewm@0
|
115 kWaveformSquare,
|
andrewm@0
|
116 kWaveformSawtooth,
|
andrewm@0
|
117 kNumWaveforms
|
andrewm@0
|
118 };
|
andrewm@0
|
119
|
andrewm@0
|
120 // Adjustable parameters:
|
andrewm@0
|
121 float baseFrequency_; // Lowest frequency of allpass filters
|
andrewm@0
|
122 float sweepWidth_; // Amount of change from min to max delay
|
andrewm@0
|
123 float depth_; // Mix level for phase-shifted signal (0-1)
|
andrewm@0
|
124 float feedback_; // Feedback level for feedback phaser (0-<1)
|
andrewm@0
|
125 float lfoFrequency_; // LFO frequency (Hz)
|
andrewm@0
|
126 int filtersPerChannel_; // How many allpass filters to use
|
andrewm@0
|
127 int waveform_; // What shape should be used for the LFO
|
andrewm@0
|
128 int stereo_; // Whether to use stereo phasing
|
andrewm@0
|
129
|
andrewm@0
|
130 private:
|
andrewm@0
|
131 float lfo(float phase, int waveform);
|
andrewm@0
|
132 void allocateFilters(); // Create the filter objects...
|
andrewm@0
|
133 void deallocateFilters(); // Delete them...
|
andrewm@0
|
134 void reallocateFilters(); // Delete and rebuild in one combined operation
|
andrewm@0
|
135
|
andrewm@0
|
136 CriticalSection lock_; // Lock for updating number of filters
|
andrewm@0
|
137
|
andrewm@0
|
138 float lfoPhase_; // Phase of the low-frequency oscillator
|
andrewm@0
|
139 double inverseSampleRate_; // It's more efficient to multiply than divide, so
|
andrewm@0
|
140 // cache the inverse of the sample rate
|
andrewm@0
|
141 unsigned int sampleCount_; // Counter to keep track of samples elapsed, to
|
andrewm@0
|
142 // keep track of filter updates
|
andrewm@0
|
143 unsigned int filterUpdateInterval_; // How often to update filter coefficients
|
andrewm@0
|
144
|
andrewm@0
|
145 // Bank of allpass filters that do the phasing; N filters x M channels
|
andrewm@0
|
146 OnePoleAllpassFilter **allpassFilters_;
|
andrewm@0
|
147
|
andrewm@0
|
148 // Storage of the last output sample from each bank of filters, for use in
|
andrewm@0
|
149 // feedback loop
|
andrewm@0
|
150 float *lastFilterOutputs_;
|
andrewm@0
|
151 int numLastFilterOutputs_;
|
andrewm@0
|
152
|
andrewm@0
|
153 int totalNumFilters_;
|
andrewm@0
|
154
|
andrewm@0
|
155 //==============================================================================
|
andrewm@0
|
156 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PhaserAudioProcessor);
|
andrewm@0
|
157 };
|
andrewm@0
|
158
|
andrewm@0
|
159 #endif // __PLUGINPROCESSOR_H_4693CB6E__
|