Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Multimedia
  • Search

[ALSA] play sound on two devices

Help with creation, editing, or playback of sounds, images, or video. Amarok, audacious, mplayer, grip, cdparanoia and anything else that makes a sound or plays a video.
Post Reply
Advanced search
13 posts • Page 1 of 1
Author
Message
Langest
n00b
n00b
Posts: 48
Joined: Fri Jan 19, 2018 9:41 pm

[ALSA] play sound on two devices

  • Quote

Post by Langest » Sun Mar 04, 2018 4:50 pm

Hello! I am trying to configure alsa to play audio on both my external dac and my built in speakers at the same time.
I found a very helpful stack overflow thread https://stackoverflow.com/questions/439 ... em-configs
The config I am using now is:

Code: Select all

pcm.quad {
    type multi
    slaves.a.pcm "hw:Intel"
    slaves.a.channels 2
    slaves.b.pcm "dmix:Schiit"
    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.stereo2quad {
    type route
    slave.pcm "quad"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
}
pcm.!default {
    type asym
    playback.pcm "plug:stereo2quad"
    capture.pcm "plug:dsnoop:Intel"
}
It almost works. The problem is that my intel card doesn't work with dmix. I need to set hw for it to work, see line 3. But this prevents applications from using the sound at the same time.
I would be glad if someone knew what to do or could point me in the right direction.

Thank you!
Top
audiodef
Watchman
Watchman
User avatar
Posts: 6656
Joined: Wed Jul 06, 2005 1:02 pm
Location: The soundosphere
Contact:
Contact audiodef
Website

  • Quote

Post by audiodef » Sun Mar 04, 2018 6:45 pm

I believe pulseaudio can do this ootb, but I'm not a pulseaudio wiz. If your audio apps are jack-aware, you can use jack with the alsa driver to accomplish multiple simultaneous outputs.
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Top
steve_v
Guru
Guru
Posts: 445
Joined: Sun Jun 20, 2004 7:39 am
Location: New Zealand

Re: [ALSA] play sound on two devices

  • Quote

Post by steve_v » Mon Mar 05, 2018 4:16 am

Langest wrote:Hello! I am trying to configure alsa to play audio on both my external dac and my built in speakers at the same time
The problem is that my intel card doesn't work with dmix.
Doesn't work with dmix at all, or doesn't work with your current config?
Can you use dmix when outputting only to the intel card?
snd_hda_intel, I assume? I have a card using that driver, and dmix works here.

Do I read it right that you are trying to make a 4-channel device from 2 2-channel cards?

I have something vaguely similar, though with only one card, to output to both analog and spdif on my hda_intel chipset:

Code: Select all

pcm.!default {
    type plug
    slave {
        pcm "duplex"
    }
}

pcm.duplex {
    type asym
    playback {
        pcm "duplicate"
    }
    capture {
        pcm "dsnoop"
    }
}


pcm.duplicate {
     type plug
     slave.pcm {
         type multi
         slaves {
             a { pcm "dmix:0,0" channels 2 }
             b { pcm "spdif_softvol" channels 2 }
         }
         bindings [
             { slave a channel 0 }
             { slave a channel 1 }
             { slave b channel 0 }
             { slave b channel 1 }
         ]
     }
     ttable [
         [ 1 0 1 0 ]
         [ 0 1 0 1 ]
     ]
}


pcm.spdif_softvol {
    type softvol
    slave {
        pcm "dmix:0,1"
    }
    control {
        name "SPDIF Playback Volume"
        card "0"
    }
    hint {
        show on
        description "SPDIF"
    }
    min_dB -60.0
    max_dB -20.0
    resolution 200
}
It is a shot in the dark (as is the poorly documented alsa config file in general), but I notice that you have no plug device to do rate/format conversion - IME this is the bear with dmix, it will only work if all streams are the same format and sample rate.
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Mon Mar 05, 2018 6:06 pm

That's not going to work unless your cards have a clock sync cable between them, dmix doesn't do drift compensation here like pulse does.
Top
Langest
n00b
n00b
Posts: 48
Joined: Fri Jan 19, 2018 9:41 pm

Re: [ALSA] play sound on two devices

  • Quote

Post by Langest » Mon Mar 05, 2018 6:46 pm

steve_v wrote:Doesn't work with dmix at all, or doesn't work with your current config?
Can you use dmix when outputting only to the intel card?
No, but works fine on the other card.

Code: Select all

$ speaker-test -D dmix:Schiit -c 2 #Works fine
$ speaker-test -D dmix:Intel -c 2 #Don't work
$ speaker-test -D hw:Intel -c 2 #Works fine
steve_v wrote:snd_hda_intel, I assume?
Yes.
steve_v wrote:Do I read it right that you are trying to make a 4-channel device from 2 2-channel cards?
I think that is the idea that is suggested in the stack overflow thread I read through. Any working solution is fine. The cards I use both are 2-channels.
I tried the proposed solution without any luck.
Ant P. wrote:That's not going to work unless your cards have a clock sync cable between them, dmix doesn't do drift compensation here like pulse does.
Do you mean there is no possibility for me to mirror the sounds on both cards at once or that the proposed solution will not be able to work?
Top
steve_v
Guru
Guru
Posts: 445
Joined: Sun Jun 20, 2004 7:39 am
Location: New Zealand

Re: [ALSA] play sound on two devices

  • Quote

Post by steve_v » Wed Mar 07, 2018 4:37 am

Langest wrote:$ speaker-test -D dmix:Intel -c 2 #Don't work
Curious. What if you explicitly define a dmix pcm in your config?
Top
Langest
n00b
n00b
Posts: 48
Joined: Fri Jan 19, 2018 9:41 pm

Re: [ALSA] play sound on two devices

  • Quote

Post by Langest » Wed Mar 07, 2018 7:32 am

steve_v wrote:Curious. What if you explicitly define a dmix pcm in your config?

Code: Select all

$ speaker-test -D dmix:Intel -c 2 
Still does not work.
If I don't put anything in my config it works to play sound through the browser and an media player at the same time but speaker-test says that the device is busy when I try to use it in combination with one of the other two.

Code: Select all

$ speaker-test -D hw:Intel -c 2
speaker-test 1.1.2
Playback device is hw:Intel
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Playback open error: -16,Device or resource busy
Do I need to do anything besides update my conf to test with the explicitly defined "dmixed" pmc?
Top
steve_v
Guru
Guru
Posts: 445
Joined: Sun Jun 20, 2004 7:39 am
Location: New Zealand

Re: [ALSA] play sound on two devices

  • Quote

Post by steve_v » Wed Mar 07, 2018 8:25 am

Langest wrote:If I don't put anything in my config it works to play sound through the browser and an media player at the same time but speaker-test says that the device is busy when I try to use it in combination with one of the other two.
You have pulseaudio installed?
Top
Langest
n00b
n00b
Posts: 48
Joined: Fri Jan 19, 2018 9:41 pm

Re: [ALSA] play sound on two devices

  • Quote

Post by Langest » Wed Mar 07, 2018 9:31 am

steve_v wrote:You have pulseaudio installed?
No, I don't have pulseaudio installed.
Top
steve_v
Guru
Guru
Posts: 445
Joined: Sun Jun 20, 2004 7:39 am
Location: New Zealand

Re: [ALSA] play sound on two devices

  • Quote

Post by steve_v » Wed Mar 07, 2018 9:40 am

Langest wrote:Do I need to do anything besides update my conf to test with the explicitly defined "dmixed" pmc?
Other than try to play something through it (-D dmixed), no.
Top
Langest
n00b
n00b
Posts: 48
Joined: Fri Jan 19, 2018 9:41 pm

Re: [ALSA] play sound on two devices

  • Quote

Post by Langest » Wed Mar 07, 2018 4:11 pm

steve_v wrote:Other than try to play something through it (-D dmixed), no.
-D dmixed works. And I am able to run multiple instances of it at the same time. This does not work with -D hw:Intel.
Is it perhaps possible to chain this dmixed in the original config I posted to get it to work?
Top
Langest
n00b
n00b
Posts: 48
Joined: Fri Jan 19, 2018 9:41 pm

  • Quote

Post by Langest » Wed Mar 07, 2018 4:13 pm

I tried changing slaves.a.pcm "hw:Intel" to slaves.a.pcm "dmixed" and it seems to work. :D

Edit:
One problem unrelated to the original problem that I noticed is that if the Schiit device is not available (my laptop is not docked), it doesn't work since it cannot find one of the devices specified in the config. Is there a way to only use it if it is available?

Edit2:

Code: Select all

$ speaker-test -c 2
speaker-test 1.1.2
Playback device is default
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/confmisc.c:767:(parse_card) cannot find card 'Schiit'
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/conf.c:4371:(_snd_config_evaluate) function snd_func_card_driver returned error: No such device
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/conf.c:4371:(_snd_config_evaluate) function snd_func_concat returned error: No such device
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/conf.c:4371:(_snd_config_evaluate) function snd_func_refer returned error: No such device
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/conf.c:4850:(snd_config_expand) Evaluate error: No such device
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.1.2/work/alsa-lib-1.1.2/src/pcm/pcm.c:2450:(snd_pcm_open_noupdate) Unknown PCM dmix:Schiit
Playback open error: -19,No such device
Top
steve_v
Guru
Guru
Posts: 445
Joined: Sun Jun 20, 2004 7:39 am
Location: New Zealand

  • Quote

Post by steve_v » Thu Mar 08, 2018 4:14 am

Langest wrote:Is there a way to only use it if it is available?
None that I am aware of via asound.conf, but I guess one could write a udev rule to modify / swap configs. Going to get a bit kludgy though.
Or just let the client application do it, mplayer & ffmpeg allow specifying more than one audio device and will use the first that works. Dunno about others.
Top
Post Reply

13 posts • Page 1 of 1

Return to “Multimedia”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic