Nondeterministic pyaudio/ALSA failure

北城余情 提交于 2020-12-13 03:17:48

问题


I test some vanilla python code making a sound, specifically the code from this other question.

As I run that code from the command line a la python code.py, it issues this series of messages coming directly from ALSA. So far that's not unusual, as I understand it is ignoring some unavailable devices that are somehow present in the involved ALSA config files, and skipping on using jack after not finding it present:

ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave

However, when I modify the duration of the sound to e.g. 50 or 100 milliseconds, then the duration actually heard via the speakers is noticeably different on different runs. And as I wish to program some special beeps and stuff, this is an issue. It remains non-deterministic, also after restarts.

How would you go about figuring the reason for the variability in the actual sound duration being heard?

An accompanying symptom: the message about "unable to open slave" does not get issued on every run, sometimes it does and sometimes it does not. Something is nondeterministic, and I wonder whether you'd put down a day for cleaning up the elaborate ALSA config or approach this very differently.

Anyway, duplicating the play_sound call to add another sound right after the first one:

play_sound("sine", 150, 0.8, 100)
play_sound("sine", 130, 0.8, 200)

I get a slightly different console output:

attempt to connect to server failed
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave

I have not manually tinkered the ALSA configuration and it is an Ubuntu 20.04 system. Maybe I'm using the wrong linux distribution for having it all work very smoothly out of the box.

How would you approach figuring why the duration of the sound is non-deterministic?

来源:https://stackoverflow.com/questions/65003469/nondeterministic-pyaudio-alsa-failure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!