I really hope this question stays a programming question and do not end up an Sound Mechanics question... Here goes...
I am doing some experiments in order to figure
This is an audio issue, not a programming problem. The click you hear occurs when a waveform is stopped/cut in the middle of a wave, rather than at a zero-crossing.
The best simple solution from a audio paradigm is to very quickly fade-out, instead of just stopping playback.
A slightly more complex solution is to find the next zero-crossing and stop playback at precisely that point.