126 lines
3.7 KiB
C++
126 lines
3.7 KiB
C++
#include "PluginProcessor.h"
|
|
#include "PluginEditor.h"
|
|
#include <math.h>
|
|
PeteAudioProcessor::PeteAudioProcessor()
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
: AudioProcessor (BusesProperties()
|
|
#if ! JucePlugin_IsMidiEffect
|
|
#if ! JucePlugin_IsSynth
|
|
.withInput ("Input", AudioChannelSet::stereo(), true)
|
|
#endif
|
|
.withOutput ("Output", AudioChannelSet::stereo(), true)
|
|
#endif
|
|
)
|
|
#endif
|
|
{
|
|
}
|
|
PeteAudioProcessor::~PeteAudioProcessor()
|
|
{
|
|
}
|
|
const String PeteAudioProcessor::getName() const
|
|
{
|
|
return JucePlugin_Name;
|
|
}
|
|
bool PeteAudioProcessor::acceptsMidi() const
|
|
{
|
|
#if JucePlugin_WantsMidiInput
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
bool PeteAudioProcessor::producesMidi() const
|
|
{
|
|
return false;
|
|
}
|
|
double PeteAudioProcessor::getTailLengthSeconds() const
|
|
{
|
|
return 0.0;
|
|
}
|
|
int PeteAudioProcessor::getNumPrograms()
|
|
{
|
|
return 1;
|
|
}
|
|
int PeteAudioProcessor::getCurrentProgram()
|
|
{
|
|
return 0;
|
|
}
|
|
void PeteAudioProcessor::setCurrentProgram (int index)
|
|
{
|
|
}
|
|
const String PeteAudioProcessor::getProgramName (int index)
|
|
{
|
|
return {};
|
|
}
|
|
void PeteAudioProcessor::changeProgramName (int index, const String& newName)
|
|
{
|
|
}
|
|
void PeteAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
|
|
{
|
|
myYin = Yin(sampleRate, samplesPerBlock);
|
|
aFilter = (filter_svf_t*)malloc(sizeof(filter_svf_t));
|
|
svf_init(aFilter, 0, sampleRate);
|
|
}
|
|
void PeteAudioProcessor::releaseResources()
|
|
{
|
|
}
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
bool PeteAudioProcessor::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 PeteAudioProcessor::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 PeteAudioProcessor::hasEditor() const
|
|
{
|
|
return true;
|
|
}
|
|
AudioProcessorEditor* PeteAudioProcessor::createEditor()
|
|
{
|
|
return new PeteAudioProcessorEditor(*this);
|
|
}
|
|
void PeteAudioProcessor::getStateInformation (MemoryBlock& destData)
|
|
{
|
|
}
|
|
void PeteAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
|
|
{
|
|
}
|
|
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
|
{
|
|
return new PeteAudioProcessor();
|
|
}
|