andrewm@0: /* andrewm@0: This code accompanies the textbook: andrewm@0: andrewm@0: Digital Audio Effects: Theory, Implementation and Application andrewm@0: Joshua D. Reiss and Andrew P. McPherson andrewm@0: andrewm@0: --- andrewm@0: andrewm@0: Distortion: distortion effect using different characteristic curves andrewm@0: See textbook Chapter 7: Overdrive, Distortion and Fuzz andrewm@0: andrewm@0: Code by Brecht De Man, Joshua Reiss and Andrew McPherson andrewm@0: andrewm@0: When using this code (or a modified version thereof), please cite: andrewm@0: andrewm@0: Brecht De Man and Joshua D. Reiss, "Adaptive Control of Amplitude andrewm@0: Distortion Effects," 53rd Conference of the Audio Engineering Society, andrewm@0: 2014. andrewm@0: andrewm@0: --- andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: */ andrewm@0: andrewm@0: #ifndef __PLUGINPROCESSOR_H_88534BAA__ andrewm@0: #define __PLUGINPROCESSOR_H_88534BAA__ andrewm@0: andrewm@0: #include "../JuceLibraryCode/JuceHeader.h" andrewm@0: #include andrewm@0: andrewm@0: class DistortionAudioProcessor : public AudioProcessor andrewm@0: { andrewm@0: public: andrewm@0: DistortionAudioProcessor(); andrewm@0: ~DistortionAudioProcessor(); andrewm@0: andrewm@0: //============================================================================== andrewm@0: // V S T M E T H O D S andrewm@0: andrewm@0: void prepareToPlay (double sampleRate, int samplesPerBlock); andrewm@0: void releaseResources(); andrewm@0: void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages); andrewm@0: AudioProcessorEditor* createEditor(); andrewm@0: bool silenceInProducesSilenceOut() const; andrewm@0: virtual double getTailLengthSeconds() const {return 0;}; andrewm@0: bool hasEditor() const; andrewm@0: const String getName() const; andrewm@0: int getNumParameters(); andrewm@0: float getParameter (int index); andrewm@0: void setParameter (int index, float newValue); andrewm@0: const String getParameterName (int index); andrewm@0: const String getParameterText (int index); andrewm@0: const String getInputChannelName (int channelIndex) const; andrewm@0: const String getOutputChannelName (int channelIndex) const; andrewm@0: bool isInputChannelStereoPair (int index) const; andrewm@0: bool isOutputChannelStereoPair (int index) const; andrewm@0: bool acceptsMidi() const; andrewm@0: bool producesMidi() const; andrewm@0: int getNumPrograms(); andrewm@0: int getCurrentProgram(); andrewm@0: void setCurrentProgram (int index); andrewm@0: const String getProgramName (int index); andrewm@0: void changeProgramName (int index, const String& newName); andrewm@0: void getStateInformation (MemoryBlock& destData); andrewm@0: void setStateInformation (const void* data, int sizeInBytes); andrewm@0: andrewm@0: //============================================================================== andrewm@0: // E N U M S andrewm@0: andrewm@0: enum Parameters andrewm@0: { andrewm@0: _PARAMdeviceReset, andrewm@0: _PARAMgain, andrewm@0: _PARAMtype, andrewm@0: // add other parameters andrewm@0: _PARAMtotalNumParams andrewm@0: }; andrewm@0: andrewm@0: andrewm@0: enum Types andrewm@0: { andrewm@0: _hardClipping = 0, andrewm@0: _softClipping, andrewm@0: _softClippingExp, andrewm@0: _fullWaveRectifier, andrewm@0: _halfWaveRectifier, andrewm@0: _numberOfTypes andrewm@0: }; andrewm@0: andrewm@0: //============================================================================== andrewm@0: // O U R M E T H O D S andrewm@0: andrewm@0: void Reset(); andrewm@0: andrewm@0: private: andrewm@0: andrewm@0: // Accessors and mutators andrewm@0: inline float GetGainIndB(); andrewm@0: inline void SetGainIndB(float gainIndB); andrewm@0: inline DistortionAudioProcessor::Types GetType(); andrewm@0: inline void SetType(Types type); andrewm@0: andrewm@0: int _numChannels; andrewm@0: int _numSamples; andrewm@0: int _sampleRate; andrewm@0: float _gainIndB; andrewm@0: andrewm@0: Types _typeNumber; andrewm@0: andrewm@0: bool _isFirstFrame; andrewm@0: andrewm@0: // Buffers andrewm@0: AudioSampleBuffer _currentTrackBuffer; andrewm@0: andrewm@0: int _lastUIWidth, _lastUIHeight; andrewm@0: andrewm@0: friend class DistortionAudioProcessorEditor; andrewm@0: andrewm@0: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DistortionAudioProcessor); andrewm@0: }; andrewm@0: andrewm@0: //============================================================================= andrewm@0: // 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: andrewm@0: andrewm@0: //----------------------------------------------------------------------------- andrewm@0: // andrewm@0: inline float andrewm@0: DistortionAudioProcessor::GetGainIndB() andrewm@0: { andrewm@0: return _gainIndB; andrewm@0: } andrewm@0: andrewm@0: andrewm@0: //----------------------------------------------------------------------------- andrewm@0: // andrewm@0: inline void andrewm@0: DistortionAudioProcessor::SetGainIndB(float gainIndB) andrewm@0: { andrewm@0: _gainIndB = gainIndB; andrewm@0: } andrewm@0: andrewm@0: andrewm@0: //----------------------------------------------------------------------------- andrewm@0: // andrewm@0: inline DistortionAudioProcessor::Types andrewm@0: DistortionAudioProcessor::GetType() andrewm@0: { andrewm@0: return _typeNumber; andrewm@0: } andrewm@0: andrewm@0: andrewm@0: //----------------------------------------------------------------------------- andrewm@0: // andrewm@0: inline void andrewm@0: DistortionAudioProcessor::SetType(Types type) andrewm@0: { andrewm@0: _typeNumber = type; andrewm@0: } andrewm@0: andrewm@0: #endif // __PLUGINPROCESSOR_H_88534BAA__