circular buffer

Dave Mollen's icon

There it is again, a thread about a circular buffer.
So far I've used [tapin~] [tapout~] for a granular pitchshift effect, which works like a charm really.
But I would also like to be able to freeze or timestretch the incoming sound.

Max Patch
Copy patch and select New From Clipboard in Max.

Thus, I've been looking for a way to make such a thing work without [tapin~] [tapout~].
So far I've got this. But I think I'll have to replace [+=~] with [count~], because it will run out of memory.
Any help is appreciated.