# Why deal with the situation of whether angleDelta equals zero? [midi synth]

https://docs.juce.com/master/tutorial_synth_using_midi_input.html#tutorial_synth_using_midi_input_synth_starting_voice:~:text=voice.-,Rendering%20a%20voice

``````void renderNextBlock (juce::AudioSampleBuffer& outputBuffer, int startSample, int numSamples) override
{
if (angleDelta != 0.0)
{
if (tailOff > 0.0) // [7]
{
while (--numSamples >= 0)
{
auto currentSample = (float) (std::sin (currentAngle) * level * tailOff);

for (auto i = outputBuffer.getNumChannels(); --i >= 0;)

currentAngle += angleDelta;
++startSample;

tailOff *= 0.99; // [8]

if (tailOff <= 0.005)
{
clearCurrentNote(); // [9]

angleDelta = 0.0;
break;
}
}
}
else
{
while (--numSamples >= 0) // [6]
{
auto currentSample = (float) (std::sin (currentAngle) * level);

for (auto i = outputBuffer.getNumChannels(); --i >= 0;)

currentAngle += angleDelta;
++startSample;
}
}
}
}``````

it works like this:
The angleDelta needs to contain W, the radian speed per sample.
If angleDelta is 0.0f, there is no valid frequency set.

After tailoff (tailOff <= 0.005), the angleDelta is set to 0.0f. This will therefore stop the note.

What in this tutorial’s demo project updates angleDelta?

startNote sets it with the frequency of the incoming note

``````auto cyclesPerSecond = juce::MidiMessage::getMidiNoteInHertz (midiNoteNumber);
auto cyclesPerSample = cyclesPerSecond / getSampleRate();
angleDelta = cyclesPerSample * 2.0 * juce::MathConstants<double>::pi;``````

Does this mean no key is typed or something else?

well, since the angleDelta is set at note start, the unsetting of angledelta is only used to switch the voice off. This is after the noteoff, the tailOff keeps the note alive.

oh, the stopNote. thanks

What does this line mean? [in the condition that tailOff == 0]
auto currentSample = (float) (std::sin (currentAngle) * level);

https://docs.juce.com/master/tutorial_synth_using_midi_input.html#tutorial_synth_using_midi_input_synth_rendering_voice:~:text=tailOff%20>%200.0

That calculates the actual waveform sample value using the sin() function.