Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
using alsa for multiple outputs (onboard, bluetooth) [solved
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
s|mon
Apprentice
Apprentice


Joined: 04 Jul 2004
Posts: 217
Location: Bayern [de]

PostPosted: Wed Jan 30, 2019 5:31 pm    Post subject: using alsa for multiple outputs (onboard, bluetooth) [solved Reply with quote

I recently got a bluetooth headset i'd like to also use for audio from my machine.
Till now I used the onboard soundcard to output via analoge or spdif.

I managed to get the bluetooth headset working with alsa (although not listed as soundcard - only as pcm device after i created the entry manually in asound.conf); not sure if this is expected or relevant.

What i want to achieve is that every sound is routed to all outputs simultaneously.
So multiple sources (musicplayer, videoplayer, ....) to all 3 hardware devices (speakers:analogue, headphones:spdif and headphones:bluetooth) and i just power-off/on the devices themselves.

From what i read so far it would be possible to achive with the following chain in asound.conf

Quote:
plug -> route -> multi -> dmix -> hw/pcmdev



I can play sounds with aplay -D device
where i can use following values for device successfully:
Quote:
bluealsa, surround40, iec958
so the pcm sinks are working.

I can also combine surround and iec958 with multi (or it seems so, no error and sound out of two devices) but i can not combine surround40 and bluealsa.
Not sure why - any hints?


My asound.conf
Code:

pcm.!bluealsa {
        type plug   
        slave.pcm {
                type bluealsa
                device "AB:12:34:56:78:9C"
                profile "a2dp"
        }
        hint {
                show on
                description "Headphones"
        }
}

pcm.all {
    type multi
    slaves.a.pcm "surround40" #analogue speaker
    slaves.a.channels 2
    slaves.b.pcm "bluealsa" #bluetooth headset
    slaves.b.channels 2
#    slaves.c.pcm "iec958"  #spdif
#    slaves.c.channels 2

    bindings.0 { slave a; channel 0; }
    bindings.1 { slave a; channel 1; }
    bindings.2 { slave b; channel 0; }
    bindings.3 { slave b; channel 1; }
#    bindings.4 { slave c; channel 0; }
#    bindings.5 { slave c; channel 1; }

}

Still limited to 4 bindings, i want to achieve a combination including [i]bluealsa[/i] before expanding to 6.


pcm.stereo2all {
    type route
    slave.pcm "all"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
}

pcm.!default {
    type asym
    playback.pcm "plug:stereo2all"
    capture.pcm "plug:dsnoop:0"
}


ctl.bluealsa {
  type bluealsa




Output from aplay -l and -L
Code:
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: 92HD73E1X5 Analog [92HD73E1X5 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: 92HD73E1X5 Digital [92HD73E1X5 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Code:
null
    Discard all samples (playback) or generate zero samples (capture)
bluealsa
    Headphones
sysdefault:CARD=Intel
    HDA Intel, 92HD73E1X5 Analog
    Default Audio Device
front:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    Front speakers
surround21:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Intel,DEV=0
    HDA Intel, 92HD73E1X5 Digital
    IEC958 (S/PDIF) Digital Audio Output
hdmi:CARD=NVidia,DEV=0
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
    HDA NVidia, HDMI 1
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=2
    HDA NVidia, HDMI 2
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 3
    HDMI Audio Output


aplay output with current asound.conf
Code:
aplay mp3/Test.wav
Playing WAVE 'mp3/Test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
aplay: aplay.c:1390: set_params: Assertion `err >= 0' failed.
Aborted by signal Aborted...


Thanks
s|mon


Last edited by s|mon on Sat Apr 03, 2021 10:21 am; edited 1 time in total
Back to top
View user's profile Send private message
psycho
Guru
Guru


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

PostPosted: Thu Apr 01, 2021 7:30 am    Post subject: Reply with quote

Hey Sjmon.

You've probably long since got this sorted, but as it's unanswered I'll post my .asoundrc which is working for me with two sets of bluetooth headphones (simultaneous output to both). The below setup (though obviously with actual identifiers in place of AA:AA:AA:AA:AA:AA and BB:BB:BB:BB:BB:BB) works perfectly...alsamixer provides access to independent volume controls for each headset.
Code:
pcm.bluetooth-1 {
   type plug
   slave {
   pcm {
      type bluealsa
      device "AA:AA:AA:AA:AA:AA"
      profile "a2dp"
   }
   }
   hint {
      show on
      description "Sony WH-1000XM4 headphones (1)"
   }
}
ctl.!default {
   type bluealsa
}

defaults.bluealsa {
     interface "hci0"
     device "BB:BB:BB:BB:BB:BB"
     profile "a2dp"
}

pcm.bluetooth-2 {
   type plug
   slave {
   pcm {
      type bluealsa
      device "14:3F:A6:15:39:A6"
      profile "a2dp"
   }
   }
   hint {
      show on
      description "Sony WH-1000XM4 headphones (2)"
   }
}

pcm.both {
   type multi

   slaves.a.pcm "plug:bluetooth-1"
   slaves.a.channels 2
   slaves.b.pcm "plug:bluetooth-2"
   slaves.b.channels 2

   bindings.0 { slave a; channel 0; }
   bindings.1 { slave a; channel 1; }
   bindings.2 { slave b; channel 0; }
   bindings.3 { slave b; channel 1; }

}

pcm.stereo2both {
   type route
   slave.pcm "both"
   ttable.0.0 1
   ttable.1.1 1
   ttable.0.2 1
   ttable.1.3 1
}

pcm.!default plug:stereo2both

As you can see it's very close to yours: I'm not sure if setting up the extra plug devices (rather than using bluealsa directly) is what makes it work, but it does work. I haven't tried simultaneous output to both headphones *and* the speakers, as that's not a setup I'd ever want (I have a separate .asoundrc for the speakers and microphone and a panel menu to select between them...ditto for using one or the other, rather than both, headphones).
Back to top
View user's profile Send private message
s|mon
Apprentice
Apprentice


Joined: 04 Jul 2004
Posts: 217
Location: Bayern [de]

PostPosted: Fri Apr 02, 2021 10:35 am    Post subject: Reply with quote

Hi psycho,

thanks for your reply. No i had not but with your setup i now managed to get it somehow working but not usable yet.
with the config below i was able to get sound on bluetooth and my analogue sound output using alsa.

The following problems/challenges remain:
  • If i deactivate my bluetooth headset output is broken. Also the sound via 'sourround' is stopped
  • mpd (music player daemon) does not play with a simple alsa output using default device. So it does not play at all with this setup although e.g. audacious does.
  • no reconnect if headphones went out of reach and bluetooth disconnects. And on reconnect audio is stopped.
  • no mixer control for bluetooth device (i need to manually enter the device name in alsamixer to reach it) - this i could live with. As i anyhow solve this with scripted restore commands


So still not usable for me but i might find some time to investigate again.
I would be interested if some of these also show up in your setup.

And of course i appreciate any hints on how to solve them.
Thanks once more,
s|mon

Code:

defaults.pcm.card 1
defaults.ctl.card 1

pcm.bt1 {
        type plug   
        slave.pcm {
                type bluealsa
                device "AA:11:AA:22:AA:33"
                profile "a2dp"
        }
        hint {
                show on
                description "Sony Headphones"
        }
}

ctl.bt1
{
   type bluealsa
}

defaults.bluealsa {
     interface "hci0"            # host Bluetooth adapter
     device "AA:11:AA:22:AA:33"  # Bluetooth headset MAC address
     profile "a2dp"
}

pcm.sourround {
        type hw
        card 1
   device 0
}

ctl.sourround {
        type hw           
        card 1
   device 0
}

pcm.all {
    type multi
    slaves.a.pcm "surround40" #sourround
    slaves.a.channels 2
    slaves.b.pcm "bt1" #bluealsa
    slaves.b.channels 2
    bindings.0 { slave a; channel 0; }
    bindings.1 { slave a; channel 1; }
    bindings.2 { slave b; channel 0; }
    bindings.3 { slave b; channel 1; }
}

pcm.stereo2all {
    type route
    slave.pcm "all"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
}

ctl.bluealsa {
  type bluealsa


pcm.!default plug:stereo2all
Back to top
View user's profile Send private message
psycho
Guru
Guru


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

PostPosted: Sat Apr 03, 2021 6:37 am    Post subject: Reply with quote

Bear in mind that I'm using multiple .asoundrc configurations (i.e. .asoundrc is just a symlink to one of various possible files)...so I'm not having any problems (all my output and recording devices work perfectly) but I'm not achieving that with a single .asoundrc. I've got a range of alternatives and have set up a little yad panel menu script so I can select whichever one I want (one for speakers, one for each pair of bluetooth headphones by itself, and one for both at the same time). I guess I could automate it (have it so that the speakers are active when neither headset's connected, and then which/both headset's receiving audio is also determined by which ones are connected), but I like switching it manually...the panel indicator tells me what's active, and it means I can e.g. play something through the speakers for a while without having to disconnect the headphones.

Re the bluetooth volume control, here's an excerpt from my yad script for a volume slider:
Code:

   CURRENT_VOLUME=$(amixer get 'Sony WH-1000XM4 he #1 - A2DP Playback Volum' | tail -n 1 | cut -f 2 -d '[' | cut -f 1 -d '%')
   NEW_VOLUME=`yad --scale --max-value 100 --value $CURRENT_VOLUME --undecorated --width 300 --mouse --close-on-unfocus --skip-taskbar`
   amixer sset 'Sony WH-1000XM4 he #1 - A2DP Playback Volum' $NEW_VOLUME

If you run alsamixer while your headphones are connected you'll see the control names: you can use amixer to script volume changes however you want (link them to multimedia keys or to a GUI slider as above). Of course yad/zenity stuff is just quick and easy and isn't ideal: you don't hear the volume change (from sliding the control) until you click OK, which can mean clicking the volume control icon more than once if you're not happy with the first change. It does the job though. If anyone knows a trick to connect the normal (ALSA) panel volume slider's "Master" control to the bluealsa levels I'd be happier tweaking my bluetooth .asoundrc accordingly and ditching this separate bluetooth slider. I couldn't get it working though (ctl.!default {type bluealsa} doesn't do it) and this hack, though slightly ugly, works just fine.
Back to top
View user's profile Send private message
s|mon
Apprentice
Apprentice


Joined: 04 Jul 2004
Posts: 217
Location: Bayern [de]

PostPosted: Sat Apr 03, 2021 10:15 am    Post subject: Reply with quote

Getting closer thanks to your tips.

MPD:
I now found out that mpd can handle multiple outouts on it's own. I just need to create multiple audio_output blocks and specify not the multi-device from alsa but each device directly so in my case 'surround' and 'bt1'.

Volume:
Quote:
amixer -D bt1 sset 'WH-1000XM3 - A2DP' 99%
works as well as the volume on my headset itself.

At least mpd seems not to stop output to other devices if headphones are disconnected.
Regarding auto-reconnect i need to check - at least manually selecting 'recent connections' and then 'auto connect profiles on WH-....' seems to trigger the reconnect, although not automatically.
So i got a useful setup now i just need to script the linking for the non-mpd setup as well. Thanks a lot for the help!

One open point which is still weird. I do not see my bluetooth device in alsamixer. If i understood you correctly it shows up directly for you, does it?
Back to top
View user's profile Send private message
psycho
Guru
Guru


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

PostPosted: Sun Apr 04, 2021 4:14 am    Post subject: Reply with quote

Yes, it does (with a bluealsa .asoundrc like the one above). For me just typing alsamixer goes straight to the bluetooth levels: if I hit F6 to select a sound card I can see the other two there (the integrated Intel audio via 3.5 stereo jack and the Nvidia via HDMI, numbered as sound cards 0 and 1 respectively)...but it's already set to "default" (with just a hyphen instead of a number, for the sound card). Basically just works (though of course the headphones also need to be connected...otherwise alsamixer reports "this sound device does not have any controls").
Back to top
View user's profile Send private message
s|mon
Apprentice
Apprentice


Joined: 04 Jul 2004
Posts: 217
Location: Bayern [de]

PostPosted: Sun Apr 04, 2021 9:36 am    Post subject: Reply with quote

i got it if use the ctl.!default set to bluealsa in my setup now. But it still does not show of as seperate device if i want to cycle sound cards. Not sure if that would be supported with bluezalsa anyhow.
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