bastibe / PySoundCard

PySoundCard is an audio library based on PortAudio, CFFI and NumPy
BSD 3-Clause "New" or "Revised" License
87 stars 9 forks source link

Don't call stop() in __exit__()? #35

Closed mgeier closed 8 years ago

mgeier commented 9 years ago

I'm not quite sure, but it seems more sensible to only call self.close() in __exit__().

I don't even know the implications of the call to stop(). Either it is "superseded" by the following call to close(), in which case it would be superfluous. Or it blocks until all pending buffers are played out, which is probably not what you expect from __exit__().

bastibe commented 9 years ago

stop waits for all queued samples to play. This is necessary in __exit__(), else

with Stream(...) as s:
   s.write(...)

would abort as soon as s.write() returns, which is one block length before all samples are played.

close in contrast is equivalent to abort and will not wait for queued samples to play.