Fix uni- and bi-directional looping of zero-length samples.

Previously both cases would occasionally get stuck in infinite loops.