Created
May 28, 2017 19:56
-
-
Save anonymous/9711cf14b53f50e2e6408812e19438f1 to your computer and use it in GitHub Desktop.
PluginProcessor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "PluginProcessor.h" | |
#include "PluginEditor.h" | |
#include <math.h> | |
#include <iostream> | |
#include <windows.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "C:\Users\Chris\Desktop\Bobby\Source\FilterType.h" | |
//============================================================================== | |
BobbyAudioProcessor::BobbyAudioProcessor() | |
{ | |
uOutputGainDb = DEFAULT_U_OUTPUT_GAIN_DB; | |
uBand1GainDb = DEFAULT_U_BAND1_GAIN_DB; | |
uBand2GainDb = DEFAULT_U_BAND2_GAIN_DB; | |
uBand3GainDb = DEFAULT_U_BAND3_GAIN_DB; | |
uBand4GainDb = DEFAULT_U_BAND4_GAIN_DB; | |
uBand5GainDb = DEFAULT_U_BAND5_GAIN_DB; | |
uBand6GainDb = DEFAULT_U_BAND6_GAIN_DB; | |
uBand7GainDb = DEFAULT_U_BAND7_GAIN_DB; | |
uBand8GainDb = DEFAULT_U_BAND8_GAIN_DB; | |
uBand9GainDb = DEFAULT_U_BAND9_GAIN_DB; | |
uBand10GainDb = DEFAULT_U_BAND10_GAIN_DB; | |
aOutputGain = DEFAULT_A_OUTPUT_GAIN; | |
aBand1Gain = DEFAULT_A_BAND1_GAIN; | |
aBand2Gain = DEFAULT_A_BAND2_GAIN; | |
aBand3Gain = DEFAULT_A_BAND3_GAIN; | |
aBand4Gain = DEFAULT_A_BAND4_GAIN; | |
aBand5Gain = DEFAULT_A_BAND5_GAIN; | |
aBand6Gain = DEFAULT_A_BAND6_GAIN; | |
aBand7Gain = DEFAULT_A_BAND7_GAIN; | |
aBand8Gain = DEFAULT_A_BAND8_GAIN; | |
aBand9Gain = DEFAULT_A_BAND9_GAIN; | |
aBand10Gain = DEFAULT_A_BAND10_GAIN; | |
} | |
BobbyAudioProcessor::~BobbyAudioProcessor() | |
{ | |
} | |
String BobbyAudioProcessor::filterTypeString(FilterType type) { | |
switch (type) { | |
case FilterType::LowPass: return String("LowPass"); | |
case FilterType::HighPass: return String("HighPass"); | |
default: return String::empty; | |
} | |
} | |
//============================================================================== | |
const String BobbyAudioProcessor::getName() const | |
{ | |
return JucePlugin_Name; | |
} | |
int BobbyAudioProcessor::getNumParameters() | |
{ | |
return totalNumParams; | |
} | |
float BobbyAudioProcessor::getParameter(int index) // Must return 0-1.f | |
{ | |
switch (index) { | |
case outputGainParam: return uOutputGainDb; | |
case band1GainParam: return uBand1GainDb; | |
case band2GainParam: return uBand2GainDb; | |
case band3GainParam: return uBand3GainDb; | |
case band4GainParam: return uBand4GainDb; | |
case band5GainParam: return uBand5GainDb; | |
case band6GainParam: return uBand6GainDb; | |
case band7GainParam: return uBand7GainDb; | |
case band8GainParam: return uBand8GainDb; | |
case band9GainParam: return uBand9GainDb; | |
case band10GainParam: return uBand10GainDb; | |
default: return 0.0f; | |
} | |
} | |
void BobbyAudioProcessor::setParameter(int index, float newValue) // newValue always 0-1.f | |
{ | |
switch (index) | |
{ | |
case outputGainParam: | |
uOutputGainDb = newValue; | |
aOutputGain = powf(10, (-24 + (uOutputGainDb) * 48) / 20); | |
break; | |
case band1GainParam: | |
uBand1GainDb = newValue; | |
aBand1Gain = powf(10, (-24 + (uBand1GainDb) * 48) / 20); | |
break; | |
case band2GainParam: | |
uBand2GainDb = newValue; | |
aBand2Gain = powf(10, (-24 + (uBand2GainDb) * 48) / 20); | |
break; | |
case band3GainParam: | |
uBand3GainDb = newValue; | |
aBand3Gain = powf(10, (-24 + (uBand3GainDb) * 48) / 20); | |
break; | |
case band4GainParam: | |
uBand4GainDb = newValue; | |
aBand4Gain = powf(10, (-24 + (uBand4GainDb) * 48) / 20); | |
break; | |
case band5GainParam: | |
uBand5GainDb = newValue; | |
aBand5Gain = powf(10, (-24 + (uBand5GainDb) * 48) / 20); | |
break; | |
case band6GainParam: | |
uBand6GainDb = newValue; | |
aBand6Gain = powf(10, (-24 + (uBand6GainDb) * 48) / 20); | |
break; | |
case band7GainParam: | |
uBand7GainDb = newValue; | |
aBand7Gain = powf(10, (-24 + (uBand7GainDb) * 48) / 20); | |
break; | |
case band8GainParam: | |
uBand8GainDb = newValue; | |
aBand8Gain = powf(10, (-24 + (uBand8GainDb) * 48) / 20); | |
break; | |
case band9GainParam: | |
uBand9GainDb = newValue; | |
aBand9Gain = powf(10, (-24 + (uBand9GainDb) * 48) / 20); | |
break; | |
case band10GainParam: | |
uBand10GainDb = newValue; | |
aBand10Gain = powf(10, (-24 + (uBand10GainDb) * 48) / 20); | |
break; | |
} | |
} | |
float BobbyAudioProcessor::getParameterDefaultValue(int index) // Must return 0-1.f | |
{ | |
switch (index) | |
{ | |
case outputGainParam: return DEFAULT_U_OUTPUT_GAIN_DB; | |
case band1GainParam: return DEFAULT_U_BAND1_GAIN_DB; | |
case band2GainParam: return DEFAULT_U_BAND2_GAIN_DB; | |
case band3GainParam: return DEFAULT_U_BAND3_GAIN_DB; | |
case band4GainParam: return DEFAULT_U_BAND4_GAIN_DB; | |
case band5GainParam: return DEFAULT_U_BAND5_GAIN_DB; | |
case band6GainParam: return DEFAULT_U_BAND6_GAIN_DB; | |
case band7GainParam: return DEFAULT_U_BAND7_GAIN_DB; | |
case band8GainParam: return DEFAULT_U_BAND8_GAIN_DB; | |
case band9GainParam: return DEFAULT_U_BAND9_GAIN_DB; | |
case band10GainParam: return DEFAULT_U_BAND10_GAIN_DB; | |
default: return 0.0f; | |
} | |
} | |
// MAYBE NO NEED FOR THAT SINCE WE DO NOT HAVE NUMBER OF STEPS -- WE DO NOT CHANGE FILTER TYPE -- | |
int BobbyAudioProcessor::getParameterNumSteps(int index) | |
{ | |
switch (index) | |
{ | |
return (int)FilterType::TotalNumFilters; | |
default: return AudioProcessor::getDefaultNumParameterSteps(); | |
} | |
} | |
const String BobbyAudioProcessor::getParameterName(int index) | |
{ | |
switch (index) { | |
case outputGainParam: return String("Output Gain"); | |
case band1GainParam: return String("Band1 Gain"); | |
case band2GainParam: return String("Band2 Gain"); | |
case band3GainParam: return String("Band3 Gain"); | |
case band4GainParam: return String("Band4 Gain"); | |
case band5GainParam: return String("Band5 Gain"); | |
case band6GainParam: return String("Band6 Gain"); | |
case band7GainParam: return String("Band7 Gain"); | |
case band8GainParam: return String("Band8 Gain"); | |
case band9GainParam: return String("Band10 Gain"); | |
default: return String::empty; | |
} | |
} | |
//======================================================================================= | |
const String BobbyAudioProcessor::getParameterText(int index) | |
{ | |
switch (index) { | |
default: return String(getParameter(index), 2); | |
} | |
} | |
//______________________________________________________________________________________** | |
//========================================================================================= | |
const String BobbyAudioProcessor::getInputChannelName(int channelIndex) const | |
{ | |
return String(channelIndex + 1); | |
} | |
const String BobbyAudioProcessor::getOutputChannelName(int channelIndex) const | |
{ | |
return String(channelIndex + 1); | |
} | |
bool BobbyAudioProcessor::isInputChannelStereoPair(int index) const | |
{ | |
return true; | |
} | |
bool BobbyAudioProcessor::isOutputChannelStereoPair(int index) const | |
{ | |
return true; | |
} | |
bool BobbyAudioProcessor::acceptsMidi() const | |
{ | |
#if JucePlugin_WantsMidiInput | |
return true; | |
#else | |
return false; | |
#endif | |
} | |
bool BobbyAudioProcessor::producesMidi() const | |
{ | |
#if JucePlugin_ProducesMidiOutput | |
return true; | |
#else | |
return false; | |
#endif | |
} | |
bool BobbyAudioProcessor::silenceInProducesSilenceOut() const | |
{ | |
return false; | |
} | |
double BobbyAudioProcessor::getTailLengthSeconds() const | |
{ | |
return 0.0; | |
} | |
int BobbyAudioProcessor::getNumPrograms() | |
{ | |
return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs, | |
// so this should be at least 1, even if you're not really implementing programs. | |
} | |
int BobbyAudioProcessor::getCurrentProgram() | |
{ | |
return 0; | |
} | |
void BobbyAudioProcessor::setCurrentProgram(int index) | |
{ | |
} | |
const String BobbyAudioProcessor::getProgramName(int index) | |
{ | |
return String(); | |
} | |
void BobbyAudioProcessor::changeProgramName(int index, const String& newName) | |
{ | |
} | |
//============================================================================== | |
void BobbyAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) | |
{ | |
// Use this method as the place to do any pre-playback | |
// initialisation that you need.. | |
fs = sampleRate; | |
{ | |
// F I L T E R S : LEFT CHANNEL | |
filterL1 = new MultiFilter(FilterType::HighPass, sampleRate, ***.f); | |
filterL2 = new MultiFilter(FilterType::LowPass, sampleRate, ***.f); | |
filterL3 = new MultiFilter(FilterType::HighPass, sampleRate, ***.f); | |
filterL4 = new MultiFilter(FilterType::LowPass, sampleRate, ***.f); | |
filterL5 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL6 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL7 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL8 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL9 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL10 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL11 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL12 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL13 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL14 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL15 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL16 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL17 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL18 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL19 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL20 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL21 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL22 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL23 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL24 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL25 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL26 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL27 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL28 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL29 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL30 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL31 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL32 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL33 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL34 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL35 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL36 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL37 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL38 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterL39 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterL40 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
// F I L T E R S : RIGHT CHANNEL | |
filterR1 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR2 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR3 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR4 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR5 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR6 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR7 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR8 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR9 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR10 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR11 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR12 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR13 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR14 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR15 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR16 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR17 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR18 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR19 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR20 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR21 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR22 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR23 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR24 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR25 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR26 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR27 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR28 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR29 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR30 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR31 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR32 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR33 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR34 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR35 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR36 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR37 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR38 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
filterR39 = new MultiFilter(FilterType::HighPass, sampleRate, ***..f); | |
filterR40 = new MultiFilter(FilterType::LowPass, sampleRate, ***..f); | |
} | |
//else | |
{ | |
} | |
} | |
void BobbyAudioProcessor::releaseResources() | |
{ | |
// When playback stops, you can use this as an opportunity to free up any | |
// spare memory, etc. | |
} | |
//========================================================================================= | |
void BobbyAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) | |
{ | |
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i) | |
buffer.clear(i, 0, buffer.getNumSamples()); | |
float * leftChannel = buffer.getWritePointer(0); | |
float * rightChannel = buffer.getWritePointer(1); | |
float BAND1L, BAND1R, BAND2L, BAND2R, BAND3L, BAND3R, BAND4L, BAND4R, BAND5L, BAND5R, | |
BAND6L, BAND6R, BAND7L, BAND7R, BAND8L, BAND8R, BAND9L, BAND9R, BAND10L, BAND10R; | |
for (int i = 0; i < buffer.getNumSamples(); i++) | |
{ | |
// ======== L E F T C H A N N E L | |
BAND1L = (aBand1Gain)*(filterL4->tick(filterL2->tick(filterL3->tick((filterL1->tick(leftChannel[i])))))); | |
BAND2L = (aBand2Gain)*(filterL8->tick(filterL6->tick(filterL7->tick((filterL5->tick(leftChannel[i])))))); | |
BAND3L = (aBand3Gain)*(filterL12->tick(filterL10->tick(filterL11->tick((filterL9->tick(leftChannel[i])))))); | |
BAND4L = (aBand4Gain)*(filterL16->tick(filterL14->tick(filterL15->tick((filterL13->tick(leftChannel[i])))))); | |
BAND5L = (aBand5Gain)*(filterL20->tick(filterL18->tick(filterL19->tick((filterL17->tick(leftChannel[i])))))); | |
BAND6L = (aBand6Gain)*(filterL24->tick(filterL22->tick(filterL23->tick((filterL21->tick(leftChannel[i])))))); | |
BAND7L = (aBand7Gain)*(filterL28->tick(filterL26->tick(filterL27->tick((filterL25->tick(leftChannel[i])))))); | |
BAND8L = (aBand8Gain)*(filterL32->tick(filterL30->tick(filterL31->tick((filterL29->tick(leftChannel[i])))))); | |
BAND9L = (aBand9Gain)*(filterL36->tick(filterL34->tick(filterL35->tick((filterL33->tick(leftChannel[i])))))); | |
BAND10L = (aBand10Gain)*(filterL40->tick(filterL38->tick(filterL39->tick((filterL37->tick(leftChannel[i])))))); | |
leftChannel[i] = (BAND1L + BAND2L + BAND3L + BAND4L + BAND5L + BAND6L + BAND7L + BAND8L + BAND9L + BAND10L)* aOutputGain; | |
// ======== R I G H T C H A N N E L | |
BAND1R = (aBand1Gain)*(filterR4->tick(filterR2->tick((filterR3->tick(filterR1->tick(rightChannel[i])))))); | |
BAND2R = (aBand2Gain)*(filterR8->tick(filterR6->tick(filterR7->tick((filterR5->tick(rightChannel[i])))))); | |
BAND3R = (aBand3Gain)*(filterR12->tick(filterR10->tick((filterR11->tick(filterR9->tick(rightChannel[i])))))); | |
BAND4R = (aBand4Gain)*(filterR16->tick(filterR14->tick(filterR15->tick((filterR13->tick(rightChannel[i])))))); | |
BAND5R = (aBand5Gain)*(filterR20->tick(filterR18->tick((filterR19->tick(filterR17->tick(rightChannel[i])))))); | |
BAND6R = (aBand6Gain)*(filterR24->tick(filterR22->tick(filterR23->tick((filterR21->tick(rightChannel[i])))))); | |
BAND7R = (aBand7Gain)*(filterR28->tick(filterR26->tick((filterR27->tick(filterR25->tick(rightChannel[i])))))); | |
BAND8R = (aBand7Gain)*(filterR32->tick(filterR30->tick(filterR31->tick((filterR29->tick(rightChannel[i])))))); | |
BAND9R = (aBand9Gain)*(filterR36->tick(filterR34->tick((filterR35->tick(filterR33->tick(rightChannel[i])))))); | |
BAND10R = (aBand10Gain)*(filterR40->tick(filterR38->tick(filterR39->tick((filterR37->tick(rightChannel[i])))))); | |
rightChannel[i] = (BAND1R + BAND2R + BAND3R + BAND4R + BAND5R + BAND6R + BAND7R + BAND8R + BAND9R + BAND10R)* aOutputGain; | |
} | |
} | |
//============================================================================== | |
bool BobbyAudioProcessor::hasEditor() const | |
{ | |
return true; // (change this to false if you choose to not supply an editor) | |
} | |
AudioProcessorEditor* BobbyAudioProcessor::createEditor() | |
{ | |
return new BobbyAudioProcessorEditor(*this); | |
} | |
//============================================================================== | |
void BobbyAudioProcessor::getStateInformation(MemoryBlock& destData) | |
{ | |
// You should use this method to store your parameters in the memory block. | |
// You could do that either as raw data, or use the XML or ValueTree classes | |
// as intermediaries to make it easy to save and load complex data. | |
} | |
void BobbyAudioProcessor::setStateInformation(const void* data, int sizeInBytes) | |
{ | |
// You should use this method to restore your parameters from this memory block, | |
// whose contents will have been created by the getStateInformation() call. | |
} | |
//============================================================================== | |
// This creates new instances of the plugin.. | |
AudioProcessor* JUCE_CALLTYPE createPluginFilter() | |
{ | |
return new BobbyAudioProcessor(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment