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 Distortion: distortion effect using different characteristic curves
|
andrewm@0
|
10 See textbook Chapter 7: Overdrive, Distortion and Fuzz
|
andrewm@0
|
11
|
andrewm@0
|
12 Code by Brecht De Man, Joshua Reiss and Andrew McPherson
|
andrewm@0
|
13
|
andrewm@0
|
14 When using this code (or a modified version thereof), please cite:
|
andrewm@0
|
15
|
andrewm@0
|
16 Brecht De Man and Joshua D. Reiss, "Adaptive Control of Amplitude
|
andrewm@0
|
17 Distortion Effects," 53rd Conference of the Audio Engineering Society,
|
andrewm@0
|
18 2014.
|
andrewm@0
|
19
|
andrewm@0
|
20 ---
|
andrewm@0
|
21
|
andrewm@0
|
22 This program is free software: you can redistribute it and/or modify
|
andrewm@0
|
23 it under the terms of the GNU General Public License as published by
|
andrewm@0
|
24 the Free Software Foundation, either version 3 of the License, or
|
andrewm@0
|
25 (at your option) any later version.
|
andrewm@0
|
26
|
andrewm@0
|
27 This program is distributed in the hope that it will be useful,
|
andrewm@0
|
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
andrewm@0
|
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
andrewm@0
|
30 GNU General Public License for more details.
|
andrewm@0
|
31
|
andrewm@0
|
32 You should have received a copy of the GNU General Public License
|
andrewm@0
|
33 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
andrewm@0
|
34 */
|
andrewm@0
|
35
|
andrewm@0
|
36 #ifndef __PLUGINPROCESSOR_H_88534BAA__
|
andrewm@0
|
37 #define __PLUGINPROCESSOR_H_88534BAA__
|
andrewm@0
|
38
|
andrewm@0
|
39 #include "../JuceLibraryCode/JuceHeader.h"
|
andrewm@0
|
40 #include <math.h>
|
andrewm@0
|
41
|
andrewm@0
|
42 class DistortionAudioProcessor : public AudioProcessor
|
andrewm@0
|
43 {
|
andrewm@0
|
44 public:
|
andrewm@0
|
45 DistortionAudioProcessor();
|
andrewm@0
|
46 ~DistortionAudioProcessor();
|
andrewm@0
|
47
|
andrewm@0
|
48 //==============================================================================
|
andrewm@0
|
49 // V S T M E T H O D S
|
andrewm@0
|
50
|
andrewm@0
|
51 void prepareToPlay (double sampleRate, int samplesPerBlock);
|
andrewm@0
|
52 void releaseResources();
|
andrewm@0
|
53 void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);
|
andrewm@0
|
54 AudioProcessorEditor* createEditor();
|
andrewm@0
|
55 bool silenceInProducesSilenceOut() const;
|
andrewm@0
|
56 virtual double getTailLengthSeconds() const {return 0;};
|
andrewm@0
|
57 bool hasEditor() const;
|
andrewm@0
|
58 const String getName() const;
|
andrewm@0
|
59 int getNumParameters();
|
andrewm@0
|
60 float getParameter (int index);
|
andrewm@0
|
61 void setParameter (int index, float newValue);
|
andrewm@0
|
62 const String getParameterName (int index);
|
andrewm@0
|
63 const String getParameterText (int index);
|
andrewm@0
|
64 const String getInputChannelName (int channelIndex) const;
|
andrewm@0
|
65 const String getOutputChannelName (int channelIndex) const;
|
andrewm@0
|
66 bool isInputChannelStereoPair (int index) const;
|
andrewm@0
|
67 bool isOutputChannelStereoPair (int index) const;
|
andrewm@0
|
68 bool acceptsMidi() const;
|
andrewm@0
|
69 bool producesMidi() const;
|
andrewm@0
|
70 int getNumPrograms();
|
andrewm@0
|
71 int getCurrentProgram();
|
andrewm@0
|
72 void setCurrentProgram (int index);
|
andrewm@0
|
73 const String getProgramName (int index);
|
andrewm@0
|
74 void changeProgramName (int index, const String& newName);
|
andrewm@0
|
75 void getStateInformation (MemoryBlock& destData);
|
andrewm@0
|
76 void setStateInformation (const void* data, int sizeInBytes);
|
andrewm@0
|
77
|
andrewm@0
|
78 //==============================================================================
|
andrewm@0
|
79 // E N U M S
|
andrewm@0
|
80
|
andrewm@0
|
81 enum Parameters
|
andrewm@0
|
82 {
|
andrewm@0
|
83 _PARAMdeviceReset,
|
andrewm@0
|
84 _PARAMgain,
|
andrewm@0
|
85 _PARAMtype,
|
andrewm@0
|
86 // add other parameters
|
andrewm@0
|
87 _PARAMtotalNumParams
|
andrewm@0
|
88 };
|
andrewm@0
|
89
|
andrewm@0
|
90
|
andrewm@0
|
91 enum Types
|
andrewm@0
|
92 {
|
andrewm@0
|
93 _hardClipping = 0,
|
andrewm@0
|
94 _softClipping,
|
andrewm@0
|
95 _softClippingExp,
|
andrewm@0
|
96 _fullWaveRectifier,
|
andrewm@0
|
97 _halfWaveRectifier,
|
andrewm@0
|
98 _numberOfTypes
|
andrewm@0
|
99 };
|
andrewm@0
|
100
|
andrewm@0
|
101 //==============================================================================
|
andrewm@0
|
102 // O U R M E T H O D S
|
andrewm@0
|
103
|
andrewm@0
|
104 void Reset();
|
andrewm@0
|
105
|
andrewm@0
|
106 private:
|
andrewm@0
|
107
|
andrewm@0
|
108 // Accessors and mutators
|
andrewm@0
|
109 inline float GetGainIndB();
|
andrewm@0
|
110 inline void SetGainIndB(float gainIndB);
|
andrewm@0
|
111 inline DistortionAudioProcessor::Types GetType();
|
andrewm@0
|
112 inline void SetType(Types type);
|
andrewm@0
|
113
|
andrewm@0
|
114 int _numChannels;
|
andrewm@0
|
115 int _numSamples;
|
andrewm@0
|
116 int _sampleRate;
|
andrewm@0
|
117 float _gainIndB;
|
andrewm@0
|
118
|
andrewm@0
|
119 Types _typeNumber;
|
andrewm@0
|
120
|
andrewm@0
|
121 bool _isFirstFrame;
|
andrewm@0
|
122
|
andrewm@0
|
123 // Buffers
|
andrewm@0
|
124 AudioSampleBuffer _currentTrackBuffer;
|
andrewm@0
|
125
|
andrewm@0
|
126 int _lastUIWidth, _lastUIHeight;
|
andrewm@0
|
127
|
andrewm@0
|
128 friend class DistortionAudioProcessorEditor;
|
andrewm@0
|
129
|
andrewm@0
|
130 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DistortionAudioProcessor);
|
andrewm@0
|
131 };
|
andrewm@0
|
132
|
andrewm@0
|
133 //=============================================================================
|
andrewm@0
|
134 // I N L I N E F U N C T I O N S C O D E S E C T I O N
|
andrewm@0
|
135
|
andrewm@0
|
136
|
andrewm@0
|
137 //-----------------------------------------------------------------------------
|
andrewm@0
|
138 //
|
andrewm@0
|
139 inline float
|
andrewm@0
|
140 DistortionAudioProcessor::GetGainIndB()
|
andrewm@0
|
141 {
|
andrewm@0
|
142 return _gainIndB;
|
andrewm@0
|
143 }
|
andrewm@0
|
144
|
andrewm@0
|
145
|
andrewm@0
|
146 //-----------------------------------------------------------------------------
|
andrewm@0
|
147 //
|
andrewm@0
|
148 inline void
|
andrewm@0
|
149 DistortionAudioProcessor::SetGainIndB(float gainIndB)
|
andrewm@0
|
150 {
|
andrewm@0
|
151 _gainIndB = gainIndB;
|
andrewm@0
|
152 }
|
andrewm@0
|
153
|
andrewm@0
|
154
|
andrewm@0
|
155 //-----------------------------------------------------------------------------
|
andrewm@0
|
156 //
|
andrewm@0
|
157 inline DistortionAudioProcessor::Types
|
andrewm@0
|
158 DistortionAudioProcessor::GetType()
|
andrewm@0
|
159 {
|
andrewm@0
|
160 return _typeNumber;
|
andrewm@0
|
161 }
|
andrewm@0
|
162
|
andrewm@0
|
163
|
andrewm@0
|
164 //-----------------------------------------------------------------------------
|
andrewm@0
|
165 //
|
andrewm@0
|
166 inline void
|
andrewm@0
|
167 DistortionAudioProcessor::SetType(Types type)
|
andrewm@0
|
168 {
|
andrewm@0
|
169 _typeNumber = type;
|
andrewm@0
|
170 }
|
andrewm@0
|
171
|
andrewm@0
|
172 #endif // __PLUGINPROCESSOR_H_88534BAA__
|