What exactly did you shout at your screen?
It was a long time ago but I remember achieving it through my usual approach of thinking about it carefully to begin with and then patching up all the little crappy bits as they came along, my brain's never been good at these 'off by one' cases :)
I think the key was was thinking about it like this :
- At some point in time, you have a view of the waveform. For the sake of argument, let's choose a number and say it starts at 'pixel 100.0' in the waveform (obviously, this translates to some actual sample index in the waveform, depending on the current zoom level)
- The user scrolls the view right by approximately one pixel so it now starts at 'pixel 99.x' (where x represents some fractional value)
- Assuming you're not doing some posh sub pixel sampling, you can quantize the starting pixel position to any number between 99.0 and 99.9999 without any visible difference to where the view begins horizontally on the screen
- Then ask : how can I quantize that starting pixel position in such a way that the next pixel (pixel 100.0 before the view was scrolled) queries the same exact range of samples that it did before.
- Shout at the screen and mash keys until it works
Upon reading that, I'm not sure if it just confuses more! In short, at any given zoom level you should be able to quantize the position at where the view begins in such a way that whole pixels will always repeatedly ask for the same range of samples.
The downsampled tree stuff didn't help with this, but didn't make it any more complicated either. I seem to remember that a low res approximation worked OK as long as you chose an appropriate level in the tree and stuck with it for a particular zoom level. I don't think there was a need to use a level in the tree and also have to 'patch it up' with higher res data to make the scrolling work as described above.