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

Implement reinitialization function #44

Open SiggiGue opened 9 years ago

SiggiGue commented 9 years ago

A reinitialization function would help to refresh the device/api list if they changed during running pysoundcard. My workaround until now:

pysoundcard._pa.Pa_Terminate()
pysoundcard._py.Pa_Initialize()
devlist = list(pysoundcard.devices())
mgeier commented 9 years ago

Absolutely!

I also need this if I want to switch between ALSA and JACK. In this case, re-initialization alone (in one step) isn't enough, I'd also need a way to call "terminate" first, then I would start the JACK daemon, and then I would call the (re-)initialization function.

Any ideas for function names?

SiggiGue commented 9 years ago

Why not just:

pysoundcard.terminate_portaudio()
pysoundcard.initialize_portaudio()

so the user can handle both kinds of problems without digging into ._pa namespace.

mgeier commented 9 years ago

A few more options for brainstorming:

pysoundcard.terminate()
pysoundcard.initialize()

... would be a little less verbose.

The names might suggest that a user has to manually initialize and terminate each session, which is of course not the case.

These two might avoid this problem:

pysoundcard.unload()
pysoundcard.reload()  # this should include unloading

Any more suggestions/comments?

bastibe commented 9 years ago

The downside of reload is that it doesn't clearly say that it is closing all streams. Something like reset or terminate is a little clearer about that.