openal-soft icon indicating copy to clipboard operation
openal-soft copied to clipboard

Unable to run alplay on non-standard ALSA config

Open minghia opened this issue 4 years ago • 12 comments

I have an ALSA configuration where I play to the earpiece of an USB handset and the speaker on the motherboard of my computer at the same time. The handset has a fixed sample rate of 32 kHz but the speaker has a sound chip on it so it supports 44.1 kHz sample rate.

When I use aplay the asound.conf file that I have come up to play simultaneously on both devices it works. When I try to use the device from alplay I get the error "Failed to disable ALSA resampler" and an eventually I get an error message of 0xa001. At which point alplay exists. The device I am using is the dsp0 device in the attached asound.conf file.

I need this feature and I have tried setting alsa-resampler to true but to no effect.

Any ideas?

asound.txt

minghia avatar Apr 01 '21 06:04 minghia

When you say "eventually I get an error message of 0xa001", do you mean it works for a little bit playing audio and then stops with that error, or it gives that error before it plays? The "Failed to disable ALSA resampler" message is just a warning and shouldn't stop the device from working. Can you say what the 0xa001 error actually says? Or provide a full trace log?

kcat avatar Apr 01 '21 06:04 kcat

I get the following from the command alplay -device /usr/share/sounds/alsa/Front_Center.wav AL lib: (II) Initializing library v1.20.1-unknown UNKNOWN AL lib: (II) Supported backends: pulse, alsa, oss, null, wave AL lib: (II) Loading config /etc/openal/alsoft.conf... AL lib: (II) found 'drivers' = 'alsa' AL lib: (II) found 'alsa/device' = 'dsp0' AL lib: (II) found 'alsa/capture' = 'dsp0' AL lib: (II) found 'alsa/custom-devices' = 'dsp0=dsp0;dsp1=dsp1;dsp2=dsp2' AL lib: (II) found 'alsa/mmap' = 'true' AL lib: (II) found 'alsa/allow-resampler' = 'true' AL lib: (II) Loading config /etc/xdg/alsoft.conf... AL lib: (II) Loading config /home/users/cooee/.alsoftrc... AL lib: (II) Loading config /home/users/cooee/.config/alsoft.conf... AL lib: (II) Got binary: /usr/bin, alplay AL lib: (II) Loading config /usr/bin/alsoft.conf... AL lib: (II) Key disable-cpu-exts not found AL lib: (II) Detected max CPUID function: 0xb (ext. 0x80000008) AL lib: (II) Vendor ID: "" AL lib: (II) Name: " Intel(R) Celeron(R) CPU J1900 @ 1.99GHz" AL lib: (II) Extensions: +SSE +SSE2 +SSE3 +SSE4.1 AL lib: (II) Key rt-prio not found AL lib: (II) Key resampler not found AL lib: (II) Key trap-al-error not found AL lib: (II) Key trap-alc-error not found AL lib: (II) Key reverb/boost not found AL lib: (II) Found drivers = "alsa" AL lib: (II) Initialized backend "alsa" AL lib: (II) Added "alsa" for playback AL lib: (II) Added "alsa" for capture AL lib: (II) Key excludefx not found AL lib: (II) Key default-reverb not found AL lib: (II) Found alsa/device = "dsp0" AL lib: (II) Found alsa/custom-devices = "dsp0=dsp0;dsp1=dsp1;dsp2=dsp2" AL lib: (II) Got device "dsp0", "dsp0" AL lib: (II) Got device "dsp1", "dsp1" AL lib: (II) Got device "dsp2", "dsp2" AL lib: (II) Key alsa/device-prefix not found AL lib: (II) Key alsa/device-prefix-PCH not found AL lib: (II) Key alsa/device-prefix-PCH-0 not found AL lib: (II) Got device "HDA Intel PCH, ALC888-VD Analog (CARD=PCH,DEV=0)", "plughw:CARD=PCH,DEV=0" AL lib: (II) Key alsa/device-prefix-PCH-3 not found AL lib: (II) Got device "HDA Intel PCH, HDMI 0 (CARD=PCH,DEV=3)", "plughw:CARD=PCH,DEV=3" AL lib: (II) Key alsa/device-prefix-USB not found AL lib: (II) Key alsa/device-prefix-USB-0 not found AL lib: (II) Got device "PTC USB, USB Audio (CARD=USB,DEV=0)", "plughw:CARD=USB,DEV=0" AL lib: (II) Opening device "dsp1" AL lib: (II) Key channels not found AL lib: (II) Key sample-type not found AL lib: (II) Key frequency not found AL lib: (II) Key period_size not found AL lib: (II) Key periods not found AL lib: (II) Key sources not found AL lib: (II) Key slots not found AL lib: (II) Key sends not found AL lib: (II) Key ambi-format not found AL lib: (II) Created device 0x1b977a0, "dsp1" AL lib: (II) Key hrtf not found AL lib: (II) Pre-reset: Stereo, Float32, 44100hz, 882 / 2646 buffer AL lib: (II) Found alsa/mmap = "true" AL lib: (II) Found alsa/allow-resampler = "true" AL lib: (EE) Failed to disable ALSA resampler AL lib: (WW) Error generated on device 0x1b977a0, code 0xa001 AL lib: (II) Freeing device 0x1b977a0 Could not set a context!

I have stepped through the code and I don't believe it plays anything as the OpenAL device fails to create.

minghia avatar Apr 01 '21 07:04 minghia

Any ideas?

minghia avatar Apr 07 '21 05:04 minghia

I'm not sure. There's no reported error from ALSA (the resampler failure is really just a warning, it continues on regardless), so I'm not seeing why an error is getting generated. I do see you're using 1.20.1, so it may be worth trying 1.21.1 to see if that either fixes it or actually reports what the problem is.

kcat avatar Apr 07 '21 16:04 kcat

I could try the later version. But if the resampler failure is just a warning, why is it treated as an error?

minghia avatar Apr 07 '21 22:04 minghia

But if the resampler failure is just a warning, why is it treated as an error?

It just prints (EE) because it's logged with ERR instead of WARN, in part because WARN messages aren't shown by default in release builds. But it's not treated as a functional error... if the snd_pcm_hw_params_set_rate_resample call fails, it only prints that message, but continues on setting the remaining properties.

Though I do notice it doesn't log what the error is that the backend throws. I pushed a fix for that.

kcat avatar Apr 07 '21 23:04 kcat

I finally got around to trying 1.21.1 and it fails with the same problem. I have tried setting allow-resampler to true and false with no luck.

An exception is being raised because AlsaPlayback::reset is failing.
asound.txt

I've attached a copy of my .asoundrc file. I am trying to play on a device called dsp3 which plays on my mono aural headset and a set of speakers I have connected to the motherboard analog audio port.

Any thoughts? I know this is a non-standard configuration but I thought if ALSA can use it and play it the OpenAl should be able to as well.

minghia avatar Sep 10 '21 08:09 minghia

I think the problem is that the following line is the problem: CHECK(snd_pcm_hw_params_set_rate_near(mPcmHandle, hp.get(), &rate, nullptr));. One of my devices can handle a rate of 44.1kHz but the handset can only handle 32 kHz.

From the debugging of the mPcmHandle it's a device has the name "plug:stereo2quad" which the name of the outer most playback.pcm.

minghia avatar Sep 10 '21 09:09 minghia

I think the problem is that the following line is the problem: CHECK(snd_pcm_hw_params_set_rate_near(mPcmHandle, hp.get(), &rate, nullptr));. One of my devices can handle a rate of 44.1kHz but the handset can only handle 32 kHz.

That function should pick the closest available rate, so even if it's asking for 44.1khz when the device can only handle 32khz, the call should ultimately pick a 32khz rate with the resampler disabled. I'd need to know exactly which call is failing and what the error/return value from that call is.

kcat avatar Sep 10 '21 09:09 kcat

For some reason this call is returning -2 which gets interpreted ENOENT. openal.txt openalltrace.txt alsaltrace.txt

I have attached 3 files that may help. The openal.txt is a run of alplay with LIBASOUND_DEBUG and ALSOFT_LOGLEVEL to their maximum.

The openalltrace.txt is the output from ltrace -f -o openaltrace.txt alplay -device dsp3 /usr/share/sounds/alsa/Front_Center.wav.

The alsaltrace.txt is the output from ltrace -f -o alsaltrace,txt aplay -D dsp3 /usr/share/sounds/alsa/Front_Center.wav.

I don't know if they are of any use. I tried to follow through the openal-soft code and the alsa-lib code and I couldn't find the exact place where it returned -2.

minghia avatar Sep 13 '21 05:09 minghia

I'm unfortunately not understanding what the logs are trying to say. It goes to initialize the device, and says ALSA ERROR hw_params: set (RATE). Then it runs through a list trying to set various values, starting with value = 4000 : Invalid argument and incrementing in steps of 4000, while showing an available(?) format. While showing RATE: 48000, it goes up to and fails with 44000, then resets back to trying 4000 and does it again. After those two run-throughs, it shows RATE: 32000 while trying increments of 4000, and it resets when it would've tried 32000 and goes through it again. And it just keeps alternating this way a whole bunch of times until the last two show ALSA ERROR hw_params: set_near (RATE) with different values and return failure.

I have no idea at all why any of it is failing.

kcat avatar Sep 13 '21 13:09 kcat

ALSA's library code is rather byzantine. I suspect the various different components that are used to get the sound out of both devices adds to the confusing paths through the code.

One of the example programs that makes the same call to snd_pcm_hw_params_set_rate_near seems to have the same behaviour but it does play the sound out of both the speaker and the handset.

I have attached the program and its output with setting LIBASOUND_DEBUG to 3. pcm.c.txt pcm1.txt

It appears somewhere along the line your alsa backend thinks one of the failures is fatal but ALSA treats it as situation normal.

minghia avatar Sep 14 '21 04:09 minghia