Files
pete/Source/PluginProcessor.cpp
2017-06-27 00:31:01 -04:00

150 lines
3.9 KiB
C++

#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <math.h>
LampshadeAudioProcessor::LampshadeAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", AudioChannelSet::stereo(), true)
#endif
.withOutput ("Output", AudioChannelSet::stereo(), true)
#endif
)
#endif
{
}
LampshadeAudioProcessor::~LampshadeAudioProcessor()
{
}
const String LampshadeAudioProcessor::getName() const
{
return JucePlugin_Name;
}
bool LampshadeAudioProcessor::acceptsMidi() const
{
#if JucePlugin_WantsMidiInput
return true;
#else
return false;
#endif
}
bool LampshadeAudioProcessor::producesMidi() const
{
return false;
}
double LampshadeAudioProcessor::getTailLengthSeconds() const
{
return 0.0;
}
int LampshadeAudioProcessor::getNumPrograms()
{
return 1;
}
int LampshadeAudioProcessor::getCurrentProgram()
{
return 0;
}
void LampshadeAudioProcessor::setCurrentProgram (int index)
{
}
const String LampshadeAudioProcessor::getProgramName (int index)
{
return {};
}
void LampshadeAudioProcessor::changeProgramName (int index, const String& newName)
{
}
void LampshadeAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
myYin = Yin(sampleRate, samplesPerBlock);
aFilter = (filter_svf_t*)malloc(sizeof(filter_svf_t));
svf_init(aFilter, 0, sampleRate);
}
void LampshadeAudioProcessor::releaseResources()
{
}
#ifndef JucePlugin_PreferredChannelConfigurations
bool LampshadeAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
return false;
#if ! JucePlugin_IsSynth
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
return false;
#endif
return true;
}
#endif
void LampshadeAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
static float incrementer;
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
// In case we have more outputs than inputs, this code clears any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
// This is here to avoid people getting screaming feedback
// when they first compile a plugin, but obviously you don't need to keep
// this code if your algorithm always overwrites all the output channels.
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear(i, 0, buffer.getNumSamples());
float pitch = myYin.getPitch(buffer.getWritePointer (0)); // returns Pitch in Hertz
static float myPitch;
if(pitch > 0) { myPitch = pitch; }
svf_set_freq(aFilter, myPitch);
float* channel1Data = buffer.getWritePointer (0);
float* channel2Data = buffer.getWritePointer (1);
for(int i=0; i < buffer.getNumSamples(); i++){
incrementer += (myPitch / 4000);
channel1Data[i] = svf_step(aFilter, channel1Data[i]);
channel2Data[i] = channel1Data[i];
}
printf("%f\n",channel1Data[0]);
}
bool LampshadeAudioProcessor::hasEditor() const
{
return true;
}
AudioProcessorEditor* LampshadeAudioProcessor::createEditor()
{
return new LampshadeAudioProcessorEditor(*this);
}
void LampshadeAudioProcessor::getStateInformation (MemoryBlock& destData)
{
}
void LampshadeAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
}
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new LampshadeAudioProcessor();
}