Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] How do you make ALSA devices visible to pulseaudio?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 534
Location: New Zealand

PostPosted: Sat Mar 20, 2021 9:33 pm    Post subject: [SOLVED] How do you make ALSA devices visible to pulseaudio? Reply with quote

I've gone through the wiki pages for ALSA, pulseaudio and bluetooth, and whatever else I could find online, but the documentation only seems to work for physical (hardware) devices. In my .asoundrc I have:
Code:
pcm.bt1 {
   type plug
   slave.pcm {
      type bluealsa
      device "94:DB:56:E0:DA:82"
      profile "a2dp"
   }
   hint {
      show on
      description "Sony WH-1000XM4 headphones (1)"
   }
}

pcm.bt2 {
   type plug
   slave.pcm {
      type bluealsa
      device "14:3F:A6:15:39:A6"
      profile "a2dp"
   }
   hint {
      show on
      description "Sony WH-1000XM4 headphones (2)"
   }
}
for a couple of identical sets of bluetooth headphones. This setup works with ALSA: I can e.g.
Code:
aplay -D bt1 noise.wav
and the audio is output through the appropriate headset. Nothing I've tried will get this output to show up for pulseaudio though.

I assume it's related to the fact that aplay -l only shows the physical audio devices (analog and HDMI): these are the two devices that pulseaudio is making available, presumably via udev or whatever. I've tried stuff like
Code:
load-module module-alsa-source device=bt1
in /etc/pulse/default.pa but suspect the syntax is wrong there (the "device=" part in particular), and/or that there are other things I need to do.

Does anyone know how to make these two working ALSA devices visible to pulseaudio? I'd always thought (wrongly, obviously) that pulseaudio just sat on top of ALSA and used its devices, but it looks as though pulseaudio is ignoring my .asoundrc. For some context, prior to creating the above .asoundrc bluetooth audio *was* available to pulseaudio so I know the kernel and hardware are fine: it would only ever see one of the two simultaneously connected headphones though, so I thought with two virtual devices I could use pulseaudio's "simultaneous output" feature to use both sets at once. This being the end goal, I'm happy with solutions that scrap the above .asoundrc entirely, although my preference would be to have independent access to either set of headphones (as I currently have via ALSA) rather than just a single "bluetooth headphones" output in pulseaudio (though this would be satisfactory).


Last edited by psycho on Mon Mar 22, 2021 7:03 am; edited 1 time in total
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1555
Location: Montréal

PostPosted: Sat Mar 20, 2021 10:04 pm    Post subject: Reply with quote

Well, if bluetooth audio work with alsa you must use version 4 of alsa because the Alsa project stopped to support bluetooth with version 5. I may be not up to date wtih this.

If you want to use pulseaudio for bluetooth audio and make it work through alsa you must redirect alsa clients to pulseaudio and install bluetooth for pulseaudio. This is done like this in /etc/asound.conf or ~/.asoundrc
Code:
pcm.pulse {
    type pulse
}

ctl.pulse {
    type pulse
}

pcm.!default {
    type pulse
}

ctl.!default {
    type pulse
}

Be sure that pulseaudio is not running when you use alsa like 'aplay -D bt1 noise.wav'.
_________________
Paul
Back to top
View user's profile Send private message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 534
Location: New Zealand

PostPosted: Sun Mar 21, 2021 4:09 am    Post subject: Reply with quote

Thanks for replying. I'm using bluez-alsa which I understand to be a kind of interface to ALSA rather than bluetooth support within it.

I tried your suggestion, both as an addition to and as my entire .asoundrc, but it didn't work: it broke the headphone audio via ALSA, but did nothing to enable it via pulseaudio. I don't think those "pulse" lines are necessary as the default setup seems to work OOTB: or at least, my .mplayer/config is set to ao=pulse and the pulseaudio volume slider adjusts its volume as it plays audio (through the analog output that pulseaudio can actually see).

I've continued to experiment and have found that adding ctl sections (e.g. ctl.bt1 {type bluealsa}) enables e.g. alsamixer -D bt1 to *display* the controls, but sliding them has no effect on actual output levels. Similarly if I make them e.g. ctl.!default I can simply
Code:
aplay foo.wav
and the audio goes straight to the bluetooth headphones...yet even as the default output in my .asoundrc it's completely invisible to pulseaudio. I suspect the issue's with my ALSA setup though: if I enable the old ALSA mixer plugin on my (XFCE) panel, again it's only the non-bluetooth hardware devices (analog and HDMI) that work. If I set one of the bluetooth outputs as ALSA's default device and then set the ALSA mixer applet to "default", the volume slider becomes inactive. I feel as though I'm forgetting some kind of explicit mixer setup (dmix or whatever) but have wasted a whole day trying to figure it out so am going to stop experimenting and just hope that someone actually understands what's going on here.

Am I barking up the wrong tree by trying to make these bluetooth audio devices visible as ALSA devices? I thought in the past I'd done something in an asoundrc to make the devices configured there show up in e.g. GUI mixer applets, but maybe not. Clearly the hardware side of things is fine as ALSA has no trouble sending audio to either set of headphones. The issue is simply that pulseaudio can't see them as available outputs. I suspect this is because I've misconfigured my .asoundrc and that if it were set up properly so that my bluetooth devices were visible to the ALSA panel applet they'd be made visible to the pulseaudio mixer too...but that could be completely wrong. I could of course set up keyboard shortcuts or panel toggles or whatever to bypass pulseaudio and work the headphones purely via ALSA, but that's an ugly workaround: I'd much prefer to get pulseaudio working properly. Maybe all this is just my karma for choosing pulseaudio over apulse (hoping for fewer issues with the likes of Skype etc.).
Back to top
View user's profile Send private message
Ralphred
Guru
Guru


Joined: 31 Dec 2013
Posts: 498

PostPosted: Sun Mar 21, 2021 10:55 am    Post subject: Reply with quote

You've hit the limitation of pulseaudio when using alsa; it only talks to hardware devices.
To be honest, it's been a couple of years since I played with pulse trying to connect with non-hardware alsa devices, but it was a hard rejection when I did.
As you can see from your original .acoundrc, alsa is using a plugin to talk to the BT devices, how do the pulse-bluetooth plugins behave if you try to connect with pulse directly to the BT devices?
Back to top
View user's profile Send private message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 534
Location: New Zealand

PostPosted: Mon Mar 22, 2021 7:02 am    Post subject: Reply with quote

Thanks for confirming that my efforts were futile. I solved the problem by doing what I should have done in the first place: avoiding nasty pulseaudio like the plague. Now that pulseaudio has gone, everything works perfectly: I've used yad --notification to set up a little panel icon displaying my current audio output and enabling me to click and select whatever else I want to use...I'm actually much happier with this kind of manual control anyway so am glad to be rid of pulseaudio.

Weirdly, I also don't seem to need to use apulse. I initially tried
Code:
apulse skypeforlinux
and it didn't work. I was about to trawl the Internet looking for solutions when I decided first to try just running Skype with ALSA as in the old days. It seems to be working perfectly. Have Microsoft built ALSA support back into Skype?! Anyway, I'd better dig out a webcam and try an actual call, but so far all seems well.

Ah, the sweet freshness of Lennartless Linux.
Back to top
View user's profile Send private message
steve_v
Guru
Guru


Joined: 20 Jun 2004
Posts: 388
Location: New Zealand

PostPosted: Mon Mar 22, 2021 10:41 am    Post subject: Reply with quote

psycho wrote:
Ah, the sweet freshness of Lennartless Linux.

It is refreshing, isn't it. Almost like a step back to the times when we ran GNU/Linux because it was a unix-like system that was near-infinitely configurable and did what we told it to without talking back or making life difficult. :P
I just got around to setting up loopback recording and simple ogg/FLAC over HTTP streaming of my system audio to the MPD server in my lounge, and despite the wailings of the "ALSA is too hard" crowd, it was surprisingly easy. All I was missing was a round tuit.

This has been the fundamental problem with pulseaudio since day one: For many people it "just works", but the further your setup deviates from "Lennart's laptop" the more broken, invasive, and intractable it it becomes, and the more avoidable bugs and idiotic design flaws are revealed.
It's pretty much the same story as with all the other "nu-linux" stuff coming from the trendy late-drinkers at Redhat/GNOME et.al these days - multiple layers of abstraction, flashy GUIs, gratuitous "managers" and dbus interfaces for everything imaginable... And software that fails in weird and difficult to debug ways unless you use it exactly as the developers intended.
The "simple, pluggable, flexible tools" part of the unix philosophy is completely lost on these people, as is the idea that someone might actually want direct control over what their system is doing.

Anyway, word on the street these days is that a standard-issue laptop running systemd + pulseaudio + networkmanager + GNOME is the future, and if that doesn't work for you you're obviously doing it wrong and should probably just buy a macbook. :roll:
_________________
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
Back to top
View user's profile Send private message
Ralphred
Guru
Guru


Joined: 31 Dec 2013
Posts: 498

PostPosted: Mon Mar 22, 2021 11:27 am    Post subject: Reply with quote

steve_v wrote:
The "simple, pluggable, flexible tools" part of the unix philosophy is completely lost on these people, as is the idea that someone might actually want direct control over what their system is doing.
Just need someone to fork and modularise *webkit based browser backends and that demon can be excised too.
Back to top
View user's profile Send private message
steve_v
Guru
Guru


Joined: 20 Jun 2004
Posts: 388
Location: New Zealand

PostPosted: Mon Mar 22, 2021 1:31 pm    Post subject: Reply with quote

Ralphred wrote:
Just need someone to fork and modularise *webkit

The irony there being that webkit itself is a bloated fork of KHTML, once a nice lightweight backend. We've come full-circle. :P
_________________
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
Back to top
View user's profile Send private message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 534
Location: New Zealand

PostPosted: Tue Mar 23, 2021 6:11 am    Post subject: Reply with quote

OK, just a quick postscript to this in case someone is referring to it someday in their own struggles with bluetooth and/or pulseaudio. It turns out Skype *does* still need apulse: the testing works with pure ALSA (the test sound plays successfully, normally a sign that the application's using the sound system correctly)...however when I attempted an actual call, nothing happened: it didn't make a call with unsuccessful audio, it just did nothing at all, as if I'd never clicked the call button. Clearly it does need pulseaudio or parts of it just crash.

It turns out that the reason my quick test of
Code:
apulse skypeforlinux
didn't work was simply that I'd forgotten to check that apulse had been built with abi_x86_32. Once that was fixed it worked as expected.

One final thing was necessary to get it to use my webcam's microphone. On pure ALSA (and presumably on pulseaudio) you can select the capture device from Skype's settings menu: using apulse you're stuck with the default devices, so have to set whichever capture device you want to the default for the duration of your Skype call. I set up my .asoundrc like this:
Code:
pcm.usb
{
    type hw
    card C170
}

pcm.!default
{
    type asym
    playback.pcm
    {
        type plug
        slave.pcm "dmix"
    }
    capture.pcm
    {
        type plug
        slave.pcm "usb"
    }
}

...where "C170" was the microphone name reported by
Code:
arecord -L

A little bit of mucking around, but in the end I'm happy to be back to a pure ALSA setup, and with working pulseaudio-dependent software thanks to apulse. I've added Skype to the little ALSA menu I mentioned before as an alternative to the pulseaudio output selection menu. I'm not a fan of having my output switched automatically when I plug something in so this kind of manual setup is in every way preferable to me than pulseaudio. It's a bit wordy to describe so here's a screenshot:

https://imgur.com/a/vBkaCEq

At some point I will probably remove Skype from the menu (as I think I'll just leave the webcam input as the default) and add some more entries (e.g. output via HDMI and/or the two headphones simultaneously...maybe output to everything simultaneously) but for now this is enough progress that I'm kissing goodbye to pulseaudio on all my systems and will set them up along these lines instead, as in the old days. I'm glad it's still doable with bluetooth audio despite ALSA's not supporting it directly.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum