PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.43k stars 296 forks source link

Pa_GetDeviceCount() get not all devices anymore on Raspberry with latest firmware update #804

Open STMAndreas opened 1 year ago

STMAndreas commented 1 year ago

Because Raspberry OS is now on 64bit kernel after last update it seems PortAudio have a problem to communicate to ALSA layer. Fortunately it is possible to swich back to 32 bit kernel after update it is easy to verify the difference.

To Reproduce allways after sudo apt full-upgrade (on March 27th) on Raspberry OS 32bit version (Bullseye)

  1. set/add arm_64bit=0 to /boot/config.txt switch back to 32 bit kernel and Pa_GetDeviceCount() works as before

  2. remove arm_64bit=0 at /boot/config.txt (after update this switch isn't there in config.txt) and run on 64bit kernel Pa_GetDeviceCount() return less devices

Expected behavior Pa_GetDeviceCount() should return the same count of devices

In addition I see Error messages in logs: With 64bit kernel PortAudio write several time this error log during calling Pa_Initialize():

Expression 'GetExactSampleRate( hwParams, &defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 895

This doesn't happen with 32bit kernel

In my case I can not anymore select the different sound devices by name. I can just work with the "default" device anymore. All the sound devices are not listed anymore.

dawid-nowak commented 11 months ago

Thanks for flagging it :) Got bitten by the same problem when installing brand new Pi 4 and Pimoroni Enviro hat..

philburk commented 3 months ago

I booted an RPi4 running Linux neuhaus98 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

entered:

cd portaudio
./configure && make
bin/pa_devs

and got the attached output; pa_devs_dump.txt

I notice a few problems. 1) The vc4-hdmi listing shows no supported sample rates. Maybe related to #805

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition
        'cards.bcm2835_headpho.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

2) The dmix device is spewing errors: ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave

I connected headphones to the RPi4 board and entered: bin/paex_sine

I got a very noisy sine wave on the headphones.

philburk commented 3 months ago

I tried to follow the instructions in the first comment and tried to set arm_64bit=0 Unfortunately the device would no longer boot after that.

But I was able to edit the boot/config.txt file back to 64-bit mode by mounting the SD card on my Mac and was then able to boot.

Reading the first comment, it seems the original reporter was running a 32-bit RPi OS on a 64-bit kernel. I am running a 64-bit OS on a 64-bit kernel. So reverting back to 32-bits is probably not an option with this OS.

I will flash a 32-bit Raspbian OS and try again.

b-schliessmann commented 2 months ago

Hello guys, I can confirm this on my Raspberry Pi 4B with kernels 6.1.19-v8+ aarm64 (not ok) vs. 5.10.103-v7l+ armhf (ok).

I've verified this with a freshly built pa_stable_v190700_20210406.tgz and am able and willing to test patches, if available.

EDIT: Just to clarify, I'm getting the exact same line as above about a failed GetExactSampleRate() call. EDIT: Can also confirm that with arm_64bit=0, the latest kernel version (6.1.21-v7l+ armv7l) does not show the problem.

b-schliessmann commented 2 months ago

I've compiled portaudio-19.7.0 with debug output and this yields the following. Not much unfortunately, just "Invalid argument".

[...]
BuildDeviceList: Filling device info for 32 devices
FillInDevInfo: Filling device info for: bcm2835 HDMI 1: - (hw:0,0)
GropeDevice: collecting info ..
Expression 'GetExactSampleRate( hwParams, &defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 895
Host error description: Invalid argument
FillInDevInfo: Failed groping hw:0,0 for playback
FillInDevInfo: Filling device info for: bcm2835 HDMI 1: - (hw:0,1)
GropeDevice: collecting info ..
Expression 'GetExactSampleRate( hwParams, &defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 895
Host error description: Invalid argument
FillInDevInfo: Failed groping hw:0,1 for playback
FillInDevInfo: Filling device info for: bcm2835 Headphones: - (hw:1,0)
GropeDevice: collecting info ..
Expression 'GetExactSampleRate( hwParams, &defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 895
Host error description: Invalid argument
FillInDevInfo: Failed groping hw:1,0 for playback
FillInDevInfo: Filling device info for: USB Audio Device: - (hw:2,0)
GropeDevice: collecting info ..
Expression 'GetExactSampleRate( hwParams, &defaultSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 895
Host error description: Invalid argument
FillInDevInfo: Failed groping hw:2,0 for capture
[...]
b-schliessmann commented 2 months ago

In the above case, the numerical return value of the failing ALSA function snd_pcm_hw_params_get_rate_numden() is -22. Not much help either. The docs about the function say that it should only be called if there is a single configuration inside the configuration space which is passed as parameter. Unfortunately, my current expertise in ALSA isn't deep enough to debug the corresponding snd_pcm_hw_params_t struct. :(