On the Nsound development branch, I’ve exposed the C++ circular iterators for the Buffer class to the Python module. This code will eventually get released as part of Nsound-0.9.3.
Here’s how one might use them:
1 2 3 4 5 6 7 8 9 10 11 |
import Nsound as ns b = ns.Buffer() b << 1 << 2 << 3 c = b.cbegin() for i in xrange(10): print float(c) c += 1 |
Which will produce the this output:
1 2 3 4 5 6 7 8 9 10 |
1.0 2.0 3.0 1.0 2.0 3.0 1.0 2.0 3.0 1.0 |
The function cbegin()
returns a Buffer::circular_iterator
object that can be dereferenced using the Python builtin float()
. The iterator can be incremented using the +=
operator. Once the iterator goes off the end of the Buffer, it wraps around back to the beginning again, circular.