comparison effects/phaser/Source/PluginProcessor.h @ 0:e32fe563e124

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