How to smooth the echo duration change to get rid of audio clicks?
Maybe, when $D$ changes, you can crossfade from the audio at the old $D$ to audio at the new $D$.
If you ran a pitch detector alongside of the delay (and stored the detected period length in a corresponding array) you could crossfade one period at a time until you got to within a period of your new $D$.  Then slide very slowly to the exact $D$.