MorseKOB / PyKOB

Python implementation of a library for Morse and MorseKOB functionality
https://sites.google.com/site/morsekob/morsekob40
MIT License
4 stars 2 forks source link

Audio produces multiple ALSA error messages on Linux. #33

Closed leskerr closed 5 months ago

leskerr commented 4 years ago

When I run Sample.py, I do hear the simulated sounder through the speakers, but the program produces the following warning messages:

les@Whimsy:~/PyKOB$ python3 Sample.py
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
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
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
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
ALSA lib pcm.c:8526:(snd_pcm_recover) underrun occurred
HI
~ The quick brown fox +
les@Whimsy:~/PyKOB$

If I try listening to an active wire using the MKOB client, the 'ALSA underrun' message appears over and over again.

AESilky commented 4 years ago

Issue #136 could be related to this.

AESilky commented 4 years ago

I have a branch that uses 'python-sounddevice' instead of 'PyAudio'. Using 'python-sounddevice' resolves the ALSA errors - 'es-33-alsa-errors'.

To try it sounddevice needs to be installed by running:

python3 -m pip install sounddevice

and soundfile by running:

python3 -m pip install soundfile
AESilky commented 4 years ago

Testing still needs to be done on Windows and Mac. Additional testing also needs to be done on Linux.

AESilky commented 4 years ago

@Greg-R it would be great if you could pull branch 'es-33-alsa-errors' and give it a try, but I understand if you want to wait until it is tested and moved into master.

AESilky commented 4 years ago

The 'es-33-alsa-errors' branch doesn't update pykob.syscheck yet. I will work on that later today.

leskerr commented 4 years ago

I tried the es-33-alsa-errors branch on my Linux laptop just now. The first problem I ran into is pip wasn't installed on my computer. Hard to believe, but true.

les@Whimsy:~/PyKOB/MKOB$ python3 -m pip install sounddevice
/usr/bin/python3: No module named pip

I installed pip and installed sounddevice and soundfile. Then I ran MKOB and tried sending some letters on the keyboard. No more ALSA errors and I did get sound, but it was very sluggish. This resulted in buffer underrun warnings coming from KOB.sounder.

les@Whimsy:~/PyKOB/MKOB$ python3 MKOB.pyw
2020-09-17 09:17:13     INFO:   Load audio file: /usr/local/lib/python3.8/dist-packages/pykob/resources/clack48.wav
2020-09-17 09:17:13     INFO:   Load audio file: /usr/local/lib/python3.8/dist-packages/pykob/resources/click48.wav
2020-09-17 09:17:13     INFO:   Interface for key and sounder on serial port '/dev/ttyUSB0' not available. Key and sounder will not be used.
2020 9 17 - 9 0001-01-01 00:00:00 14
2020-09-17 09:17:14     INFO:   Record to 'Session-20200917-0917.json'
PyKOB 1.2.9
MorseKOB 4.0.11
Circuit Closer True, internet_active was False
KOB.sounder buffer empty: 1.653 -0.07 -60 (-460, 60, -60, 60, -60, 60, -60, 180)
KOB.sounder buffer empty: 1.858 -0.085 -60 (-460, 60, -60, 60, -60, 60, -60, 180)
KOB.sounder buffer empty: 2.039 -0.062 -60 (-460, 60, -60, 60, -60, 60, -60, 180)

I'll try this on Windows later today.

Greg-R commented 4 years ago

I have a few things on order to patch up my old DCM-6 based KOB circuit to safely interface to a Raspberry Pi. I should have everything today and give it a try this weekend. I have also been upgrading my knowledge of git, in particular working with remote repositories. So I am motivated to pull the branch!

leskerr commented 4 years ago

I tried with my Windows laptop and got the same kind of extreme sluggishness from the audio as I did with Linux.

The good news is that the pip install commands worked right away for sounddevice and soundfile.

AESilky commented 4 years ago

@leskerr thank you for your testing efforts and your results. I saw the same thing in my Mac testing but wanted to get some other testing results without influencing anything. I didn't see the same on my Linux machine, but good to get that info as well.

There is quite a bit of information about improving performance, but it takes more code, so I wanted to start with a basic implementation first and then work from there as needed.

I was happy to see that it did work (albeit, with performance problems) and it got rid of the ALSA errors (that didn't keep it from working but were very annoying and would concern many users).

I will work on resolving the performance issues.

AESilky commented 4 years ago

Updated pykob.syscheck to display python-sounddevice info rather than PyAudio and also added the device (path) to the serial port information listed.

AESilky commented 5 months ago

I have tried a few different libraries, but PyAudio still seems to be the best overall choice for cross-platform use.

It seems to be well-documented that on Linux its use results in a number of ALSA error messages unless a lot of system level configuration is done to eliminate them. In most cases they are harmless (there should really be an ALSA option to turn them off). One option is to redirect stderr to /dev/null. That cleans up the output so the PyKOB information is easier to see, but of course, that will hide other errors that may be important.