python-rtmixer icon indicating copy to clipboard operation
python-rtmixer copied to clipboard

Can't stop execution when coreaudiod restarts. Stale read

Open SolomidHero opened this issue 3 years ago • 5 comments

I am using examples/signal_processing.py

My system is macos, so I use coreaudio. When I restart coreaudiod (when running script) by: sudo launchctl stop com.apple.audio.coreaudiod && sudo launchctl start com.apple.audio.coreaudiod or simply sudo killall coreaudiod

process doesn't throw anything and stales in read loop. Throwing exception by myself doesn't help too (it doesn't throw and continues in stale mode).

Same if I delete virtual audio device I used in definition of mixer class.

SolomidHero avatar Feb 12 '22 11:02 SolomidHero

I think the underlying PortAudio library simply cannot handle changing audio settings.

The API doesn't provide anything to detect such a situation.

Normally, you would call sd._terminate(), then change your audio settings, and afterwards call sd._initialize(). See https://python-sounddevice.readthedocs.io/en/0.4.4/api/expert-mode.html.

Since many years, there have been discussions and plans for a "hotplug" feature, which would probably help in your case. See https://github.com/PortAudio/portaudio/issues/11 and https://github.com/PortAudio/portaudio/wiki/HotPlug.

mgeier avatar Feb 13 '22 16:02 mgeier

See also https://github.com/spatialaudio/python-sounddevice/issues/382.

mgeier avatar Feb 13 '22 16:02 mgeier

Thank you for your response. Using sd._terminate() and sd._initialize() seem pretty legit fix for me. I'll also try using hotplug in future

SolomidHero avatar Feb 14 '22 14:02 SolomidHero

I also wonder what is the cause of stale condition?

SolomidHero avatar Feb 14 '22 14:02 SolomidHero

I don't know. You could ask the PortAudio community: http://portaudio.com/contacts.html

mgeier avatar Feb 17 '22 18:02 mgeier

I'm closing this because it can only be fixed upstream. A possible work-around is using sd._terminate() and sd._initialize().

mgeier avatar Sep 07 '24 16:09 mgeier