comparison effects/compressor/Source/PluginProcessor.cpp @ 1:04e171d2a747 tip

JUCE 4 compatible. Standardised paths on Mac: modules '../../juce/modules'; VST folder '~/SDKs/vstsdk2.4' (JUCE default). Replaced deprecated 'getSampleData(channel)'; getToggleState(...); setToggleState(...); setSelectedId(...). Removed unused variables. Ignore JUCE code and build files.
author Brecht De Man <b.deman@qmul.ac.uk>
date Sun, 22 Nov 2015 15:23:40 +0000
parents e32fe563e124
children
comparison
equal deleted inserted replaced
0:e32fe563e124 1:04e171d2a747
27 along with this program. If not, see <http://www.gnu.org/licenses/>. 27 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */ 28 */
29 29
30 #include "PluginProcessor.h" 30 #include "PluginProcessor.h"
31 #include "PluginEditor.h" 31 #include "PluginEditor.h"
32 const float tau = 200;
33 CompressorAudioProcessor::CompressorAudioProcessor() 32 CompressorAudioProcessor::CompressorAudioProcessor()
34 // Initializer List 33 // Initializer List
35 : 34 :
36 inputBuffer(1,1), 35 inputBuffer(1,1),
37 nhost(0) 36 nhost(0)
82 // compression : calculates the control voltage 81 // compression : calculates the control voltage
83 compressor(inputBuffer,m); 82 compressor(inputBuffer,m);
84 // apply control voltage to the audio signal 83 // apply control voltage to the audio signal
85 for (int i = 0 ; i < bufferSize ; ++i) 84 for (int i = 0 ; i < bufferSize ; ++i)
86 { 85 {
87 buffer.getSampleData(2*m+0)[i] *= c[i]; 86 buffer.getWritePointer(2*m+0)[i] *= c[i];
88 buffer.getSampleData(2*m+1)[i] *= c[i]; 87 buffer.getWritePointer(2*m+1)[i] *= c[i];
89 } 88 }
90 inputBuffer.clear(m,0,bufferSize); 89 inputBuffer.clear(m,0,bufferSize);
91 // Mix down left-right to analyse the output 90 // Mix down left-right to analyse the output
92 inputBuffer.addFrom(m,0,buffer,m*2,0,bufferSize,0.5); 91 inputBuffer.addFrom(m,0,buffer,m*2,0,bufferSize,0.5);
93 inputBuffer.addFrom(m,0,buffer,m*2+1,0,bufferSize,0.5); 92 inputBuffer.addFrom(m,0,buffer,m*2+1,0,bufferSize,0.5);
101 alphaAttack = exp(-1/(0.001 * samplerate * tauAttack)); 100 alphaAttack = exp(-1/(0.001 * samplerate * tauAttack));
102 alphaRelease= exp(-1/(0.001 * samplerate * tauRelease)); 101 alphaRelease= exp(-1/(0.001 * samplerate * tauRelease));
103 for (int i = 0 ; i < bufferSize ; ++i) 102 for (int i = 0 ; i < bufferSize ; ++i)
104 { 103 {
105 //Level detection- estimate level using peak detector 104 //Level detection- estimate level using peak detector
106 if (fabs(buffer.getSampleData(m)[i]) < 0.000001) x_g[i] =-120; 105 if (fabs(buffer.getWritePointer(m)[i]) < 0.000001) x_g[i] =-120;
107 else x_g[i] =20*log10(fabs(buffer.getSampleData(m)[i])); 106 else x_g[i] =20*log10(fabs(buffer.getWritePointer(m)[i]));
108 //Gain computer- static apply input/output curve 107 //Gain computer- static apply input/output curve
109 if (x_g[i] >= threshold) y_g[i] = threshold+ (x_g[i] - threshold) / ratio; 108 if (x_g[i] >= threshold) y_g[i] = threshold+ (x_g[i] - threshold) / ratio;
110 else y_g[i] = x_g[i]; 109 else y_g[i] = x_g[i];
111 x_l[i] = x_g[i] - y_g[i]; 110 x_l[i] = x_g[i] - y_g[i];
112 //Ballistics- smoothing of the gain 111 //Ballistics- smoothing of the gain