Skip to content

Commit

Permalink
set up resizing c-arrays for FFT
Browse files Browse the repository at this point in the history
  • Loading branch information
hsetlik committed Apr 12, 2021
1 parent acbc88e commit 8c51697
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
6 changes: 6 additions & 0 deletions Source/DAHDSR.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class DAHDSR
void setSampleRate(double value) {sampleRate = value;}
float process(float input);
envPhase getPhase() {return currentPhase;}
bool isActive()
{
if(currentPhase == envPhase::noteOff)
return false;
return true;
}
double output;
private:
//data
Expand Down
2 changes: 2 additions & 0 deletions Source/FmVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void FmVoice::renderNextBlock(juce::AudioBuffer<float> &outputBuffer, int startS
if(fabs(opSum - lastOpSample) > 0.2f)
++numJumps;
lastOpSample = opSum;
if(!isActive())
clearCurrentNote();
}
}
void FmVoice::applyLfo(int index)
Expand Down
23 changes: 11 additions & 12 deletions Source/FmVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ class FmVoice : public juce::SynthesiserVoice
{
printf("Voice #: %d -- %d total jumps\n", voiceIndex, numJumps);
}
bool isActive()
{
for(Operator* i : operators)
{
if(i->envelope.getPhase() != DAHDSR::noteOff)
{
return true;
}
}
return false;
}
bool canPlaySound(juce::SynthesiserSound* sound)
{
return dynamic_cast<FmSound*>(sound) != nullptr;
Expand All @@ -68,8 +57,9 @@ class FmVoice : public juce::SynthesiserVoice
i->envelope.triggerOff();
}
allowTailOff = true;
if(velocity == 0)
if(velocity == 0 || !isActive())
clearCurrentNote();

}
void applyLfo(int index);
void setRoutingFromGrid(juce::AudioProcessorValueTreeState* pTree, std::vector<std::vector<juce::String>> grid);
Expand Down Expand Up @@ -98,6 +88,15 @@ class FmVoice : public juce::SynthesiserVoice
{
return *tree->getRawParameterValue(str);
}
bool isActive()
{
for(auto op : operators)
{
if(op->envelope.isActive())
return true;
}
return false;
}
void updateParams();
int voiceIndex;
int numJumps;
Expand Down
40 changes: 13 additions & 27 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ HexFmAudioProcessor::HexFmAudioProcessor()
#endif
.withOutput ("Output", juce::AudioChannelSet::stereo(), true)
#endif
), tree(*this, nullptr, "synthParams", createLayout(numOperators)), synth(6, 4, 6, &tree)
),
tree(*this, nullptr, "synthParams", createLayout(numOperators)),
synth(6, 4, 6, &tree),
fwdFFT(10),
invFFT(10),
bufferSize(getBlockSize()),
fftArray1(new float[bufferSize]),
fftArray2(new float[2 * bufferSize])
#endif
{
for(int i = 0; i < 4; ++i)
Expand Down Expand Up @@ -228,6 +235,7 @@ void HexFmAudioProcessor::changeProgramName (int index, const juce::String& newN
//==============================================================================
void HexFmAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
bufferSize = samplesPerBlock;
juce::ignoreUnused(samplesPerBlock);
synth.setCurrentPlaybackSampleRate(sampleRate);
maxiSettings::setup((int)sampleRate, 2, samplesPerBlock);
Expand Down Expand Up @@ -270,34 +278,12 @@ bool HexFmAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) co

void HexFmAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
/*
ParamStatic::setRouting(&tree, routingIds);
for(lfoIndex = 0; lfoIndex < TOTAL_LFOS; ++lfoIndex)
{
ParamStatic::lfoTarget[lfoIndex] = (int)*tree.getRawParameterValue(lfoTargetIds[lfoIndex]);
ParamStatic::lfoWave[lfoIndex] = (int)*tree.getRawParameterValue(lfoWaveIds[lfoIndex]);
ParamStatic::lfoRate[lfoIndex].setFrom(tree.getRawParameterValue(lfoRateIds[lfoIndex]));
ParamStatic::lfoLevel[lfoIndex] = *tree.getRawParameterValue(lfoLevelIds[lfoIndex]);
ParamStatic::lfoRatioMode[lfoIndex] = *tree.getRawParameterValue(lfoRatioModeIds[lfoIndex]);
}
for(opIndex = 0; opIndex < TOTAL_OPERATORS; ++opIndex)
if(bufferSize != buffer.getNumSamples())
{
ParamStatic::opRatio[opIndex].setFrom(tree.getRawParameterValue(ratioIds[opIndex]));
ParamStatic::opLevel[opIndex].setFrom(tree.getRawParameterValue(levelIds[opIndex]));
ParamStatic::opModIndex[opIndex].setFrom(tree.getRawParameterValue(modIndexIds[opIndex]));
ParamStatic::opAudible[opIndex] = (int)*tree.getRawParameterValue(audibleIds[opIndex]);
ParamStatic::opPanValue[opIndex].setFrom(tree.getRawParameterValue(panIds[opIndex]));
ParamStatic::opDelayTime[opIndex].setFrom(tree.getRawParameterValue(delayIds[opIndex]));
ParamStatic::opAttackTime[opIndex].setFrom(tree.getRawParameterValue(attackIds[opIndex]));
ParamStatic::opHoldTime[opIndex].setFrom(tree.getRawParameterValue(holdIds[opIndex]));
ParamStatic::opDecayTime[opIndex].setFrom(tree.getRawParameterValue(decayIds[opIndex]));
ParamStatic::opSustainLevel[opIndex].setFrom(tree.getRawParameterValue(sustainIds[opIndex]));
ParamStatic::opReleaseTime[opIndex].setFrom(tree.getRawParameterValue(releaseIds[opIndex]));
bufferSize = buffer.getNumSamples();
fftArray1 = new float[bufferSize];
fftArray2 = new float[2 * bufferSize];
}
*/

buffer.clear();
synth.updateParams();
synth.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
Expand Down
6 changes: 6 additions & 0 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class HexFmAudioProcessor : public juce::AudioProcessor
int opIndex;
int voiceIndex;
FmSynth synth;

juce::dsp::FFT fwdFFT;
juce::dsp::FFT invFFT;
int bufferSize;
float* fftArray1;
float* fftArray2;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HexFmAudioProcessor)
};

0 comments on commit 8c51697

Please sign in to comment.