void renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples) { if (angleDelta != 0.0) { if (tailOff > 0) { SynthesiserSound *sound = getCurrentlyPlayingSound(); while (--numSamples >= 0) { float currentSample; // LFO used to create tremolo const float lfoCurrentSample = (float) ((4.0 * sin (lfoCurrentAngle)) * level * tailOff) + 0.7; currentSample = calculateSample(sound, currentSample, lfoCurrentSample, true); for (int i = outputBuffer.getNumChannels(); --i >= 0;) *outputBuffer.getSampleData (i, startSample) += (currentSample); currentAngle += angleDelta; lfoCurrentAngle += lfoAngleDelta; ++startSample; tailOff *= 0.99; if (tailOff <= 0.005) { clearCurrentNote(); angleDelta = 0.0; lfoAngleDelta = 0.0; break; } } } else { SynthesiserSound *sound = getCurrentlyPlayingSound(); while (--numSamples >= 0) { float currentSample; // LFO used to create tremolo const float lfoCurrentSample = (float) ((4.0 * sin (lfoCurrentAngle)) * level) + 0.7; currentSample = calculateSample(sound, currentSample, lfoCurrentSample, false); for (int i = outputBuffer.getNumChannels(); --i >= 0;) *outputBuffer.getSampleData (i, startSample) += (currentSample); currentAngle += angleDelta; lfoCurrentAngle += lfoAngleDelta; ++startSample; } } } }
//============================================================================== void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples) { if (const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().get())) { const float* const inL = playingSound->data->getSampleData (0, 0); const float* const inR = playingSound->data->getNumChannels() > 1 ? playingSound->data->getSampleData (1, 0) : nullptr; float* outL = outputBuffer.getSampleData (0, startSample); float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : nullptr; while (--numSamples >= 0) { const int pos = (int) sourceSamplePosition; const float alpha = (float) (sourceSamplePosition - pos); const float invAlpha = 1.0f - alpha; // just using a very simple linear interpolation here.. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha); float r = (inR != nullptr) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha) : l; l *= lgain; r *= rgain; if (isInAttack) { l *= attackReleaseLevel; r *= attackReleaseLevel; attackReleaseLevel += attackDelta; if (attackReleaseLevel >= 1.0f) { attackReleaseLevel = 1.0f; isInAttack = false; } } else if (isInRelease) { l *= attackReleaseLevel; r *= attackReleaseLevel; attackReleaseLevel += releaseDelta; if (attackReleaseLevel <= 0.0f) { stopNote (false); break; } } if (outR != nullptr) { *outL++ += l; *outR++ += r; } else { *outL++ += (l + r) * 0.5f; } sourceSamplePosition += pitchRatio; if (sourceSamplePosition > playingSound->length) { stopNote (false); break; } } } }