Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rpi zero 2w][KMSDRM] CX31993 USB sound card; crackle and choppy sound; USB driver issue; ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred 0B f=0/0 #265 #6402

Open
qrp73 opened this issue Oct 5, 2024 · 3 comments

Comments

@qrp73
Copy link

qrp73 commented Oct 5, 2024

Describe the bug

When using the CX31993 USB sound card on a Raspberry Pi Zero 2W with application running in KMSDRM mode, the audio is choppy, even when selecting a low sampling rate. However, the same USB sound card works without interruptions on a Raspberry Pi 4B. Additionally, using a different USB sound card on the Raspberry Pi Zero 2W does not result in audio issues.

This problem has been observed for a long time ago and remains unresolved, even with the latest updates.

It is suspected that the issue is related to the USB device driver, as the interruptions only occur with this specific device RPI02W and CX31993 USB sound card combination.

Steps to reproduce the behaviour

  1. Use Raspberry Pi Zero 2W with the default clock speed, running on latest Raspi-OS lite aarch64.

  2. Connect an HDMI display (using a 1280x1024@60 resolution).

  3. Connect a USB hub with a keyboard and a CX31993 USB sound card.

  4. Run sudo reboot to restart the system.

  5. Create a test directory and navigate to it: mkdir TEST && cd TEST

  6. Download the test audio file:

wget https://www.mediacollege.com/audio/tone/files/1kHz_44100Hz_16bit_05sec.wav
  1. Play the audio file using aplay:
aplay 1kHz_44100Hz_16bit_05sec.wav

Expected result: The sound is played correctly, without issues.

  1. Play the same audio file using ffplay with SDL_VIDEODRIVER=kmsdrm:
SDL_VIDEODRIVER=kmsdrm ffplay 1kHz_44100Hz_16bit_05sec.wav

Expected result: The sound should be played correctly.

Actual result: The sound is played choppy with crackling noises, and multiple errors appear in the console output:

ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred  0B f=0/0
ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred  0B f=0/0
ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred  0B f=0/0
...

Device (s)

Raspberry Pi Zero 2 W

System

$ uname -a && cat /etc/rpi-issue && vcgencmd version
Linux rpi02w 6.6.51+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt2 (2024-10-01) aarch64 GNU/Linux
Raspberry Pi reference 2024-03-15
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, f19ee211ddafcae300827f953d143de92a5c6624, stage2
Aug 30 2024 19:19:11 
Copyright (c) 2012 Broadcom
version 2808975b80149bbfe86844655fe45c7de66fc078 (clean) (release) (start)

Logs

ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred  0B f=0/0
ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred  0B f=0/0
ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred  0B f=0/0
...

Additional context

This bug is not related to the ffplay code. I initially encountered this issue in my own SDL application that uses the librtaudio-dev library for audio playback. Upon further investigation, I found that the same problem occurs in ffplay when running in KMSDRM mode. Therefore, to simplify reproducing the issue, I used the standard ffplay program.

@qrp73 qrp73 changed the title [rpi zero 2w][KMSDRM] CX31993 USB sound card; crackle sound; USB driver issue; ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred 0B f=0/0 #265 [rpi zero 2w][KMSDRM] CX31993 USB sound card; crackle and choppy sound; USB driver issue; ALSA lib pcm.c:8570:(snd_pcm_recover) underrun occurred 0B f=0/0 #265 Oct 5, 2024
@popcornmix
Copy link
Collaborator

You would probably be better off with a 32-bit install.

32-bit kernel uses the FIQ to improve performance of the dtw_otg usb driver.
There is not FIQ support on the 64-bit kernel, which reduces USB performance.

@pelwell
Copy link
Contributor

pelwell commented Oct 5, 2024

You will also get a bit more free memory on 32-bit, which can make a useful difference on a Zero 2 W.

@qrp73
Copy link
Author

qrp73 commented Oct 5, 2024

I prefer a 64-bit kernel as it enables 64-bit integer computations with reduced overhead. I experimented with a 32-bit kernel, but encountered significant performance bottlenecks for my algorithms and additional issues.

Regarding memory usage, I'm utilizing swap in zram because running tasks like apt update on Raspi-OS Lite with only 512 MB of RAM is nearly impossible without it. However, for my needs, 100 MB of memory for user code is sufficient, speed is more important to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants