Hey all,
I’m just starting out with JUCE so please bear with me
What I am trying to build:
I try to build a Drum-Sampler within the Juce Framework, where a Syntesiser-Object is supplied with derived classes from SynthesiserSound, where i hold the sample data plus an ADSR-envelope (I used this Implementation: ADSR by Nigel Redmon on earlevel.com) and a panning control plus a derived class from SynthesiserVoice, where all the rendering is happening.
Because it is a Drum-Sampler no pitching is applied to the sounds and they only should be playing when a certain midi note gets triggerd.
The Implementation:
In my class derived from SynthesiserVoice I have overidden the startNote(), stopNote(), and renderNextBlock() - functions to cope with my special case.
startNote():
void CTAGSampVoice::startNote(int midiNoteNumber, float velocity, SynthesiserSound *
sampSound, int pitchWheel)
{
if( auto* playingSound = static_cast<CTAGSampSound*> (sampSound))
{
playingSound->getEnvelopeGenerator().reset();
playingSound->getEnvelopeGenerator().gate(true);
}
SamplerVoice::startNote(midiNoteNumber, velocity, sampSound, pitchWheel);
}
stopNote():
void CTAGSampVoice::stopNote(float velocity, bool allowTailOff)
{
if (auto* playingSound = static_cast<CTAGSampSound*>
(getCurrentlyPlayingSound().get()))
{
playingSound->getEnvelopeGenerator().gate(false);
if (playingSound->getEnvelopeGenerator().getState() == EnvelopeGenerator::env_idle)
{
clearCurrentNote();
}
}
SamplerVoice::stopNote(velocity, allowTailOff);
}
renderNextBlock():
void CTAGSampVoice::renderNextBlock(AudioBuffer< float > &outputBuffer, int startSample, int numSamples)
{
auto* leftData = outputBuffer.getWritePointer(0, startSample);
auto* rightData = outputBuffer.getWritePointer(1, startSample);
if (auto* playingSound = static_cast<CTAGSampSound*> (getCurrentlyPlayingSound().get()))
{
SamplerVoice::renderNextBlock(outputBuffer, startSample, numSamples);
PanPos& p = playingSound->getPanPos();
EnvelopeGenerator& e = playingSound->getEnvelopeGenerator();
float envVal;
for (int sample = 0; sample < numSamples; sample++)
{
envVal = e.process();
leftData[sample] *= envVal;
rightData[sample] *= envVal;
leftData[sample] = p.processLeftChannel(leftData[sample]);
rightData[sample] = p.processRightChannel(rightData[sample]);
}
}
}
The Problem:
My Problem now is, that when I press the same Key two times very fast I get a clicking between the two sounds when applying the envelope. I think that the problem is, that the sound playing is not finished and gets killed by the next one but without a fade applied at the end, because the release phase from the envelope hasn’t finished yet. So I think I would need to apply a small fade out to the first sound. But I really don’t now how to do this and I havn’t found any resources online which tackle this. So hopefully somebody here on the forum could help me out, I allready tried a lot but nothing worked.