Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[ALSA] play sound on two devices
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
Langest
n00b
n00b


Joined: 19 Jan 2018
Posts: 48

PostPosted: Sun Mar 04, 2018 4:50 pm    Post subject: [ALSA] play sound on two devices Reply with quote

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/43939191/alsa-how-to-duplicate-a-stream-on-2-outputs-and-save-system-configs
The config I am using now is:
Code:
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!
Back to top
View user's profile Send private message
audiodef
Watchman
Watchman


Joined: 06 Jul 2005
Posts: 6639
Location: The soundosphere

PostPosted: Sun Mar 04, 2018 6:45 pm    Post subject: Reply with quote

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
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 05, 2018 4:16 am    Post subject: Re: [ALSA] play sound on two devices Reply with quote

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:
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.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Mon Mar 05, 2018 6:06 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Langest
n00b
n00b


Joined: 19 Jan 2018
Posts: 48

PostPosted: Mon Mar 05, 2018 6:46 pm    Post subject: Re: [ALSA] play sound on two devices Reply with quote

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:
$ 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?
Back to top
View user's profile Send private message
steve_v
Guru
Guru


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

PostPosted: Wed Mar 07, 2018 4:37 am    Post subject: Re: [ALSA] play sound on two devices Reply with quote

Langest wrote:
$ speaker-test -D dmix:Intel -c 2 #Don't work
Curious. What if you explicitly define a dmix pcm in your config?
Back to top
View user's profile Send private message
Langest
n00b
n00b


Joined: 19 Jan 2018
Posts: 48

PostPosted: Wed Mar 07, 2018 7:32 am    Post subject: Re: [ALSA] play sound on two devices Reply with quote

steve_v wrote:
Curious. What if you explicitly define a dmix pcm in your config?
Code:
$ 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:
$ 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?
Back to top
View user's profile Send private message
steve_v
Guru
Guru


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

PostPosted: Wed Mar 07, 2018 8:25 am    Post subject: Re: [ALSA] play sound on two devices Reply with quote

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?
Back to top
View user's profile Send private message
Langest
n00b
n00b


Joined: 19 Jan 2018
Posts: 48

PostPosted: Wed Mar 07, 2018 9:31 am    Post subject: Re: [ALSA] play sound on two devices Reply with quote

steve_v wrote:
You have pulseaudio installed?
No, I don't have pulseaudio installed.
Back to top
View user's profile Send private message
steve_v
Guru
Guru


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

PostPosted: Wed Mar 07, 2018 9:40 am    Post subject: Re: [ALSA] play sound on two devices Reply with quote

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.
Back to top
View user's profile Send private message
Langest
n00b
n00b


Joined: 19 Jan 2018
Posts: 48

PostPosted: Wed Mar 07, 2018 4:11 pm    Post subject: Re: [ALSA] play sound on two devices Reply with quote

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?
Back to top
View user's profile Send private message
Langest
n00b
n00b


Joined: 19 Jan 2018
Posts: 48

PostPosted: Wed Mar 07, 2018 4:13 pm    Post subject: Reply with quote

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:
$ 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
Back to top
View user's profile Send private message
steve_v
Guru
Guru


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

PostPosted: Thu Mar 08, 2018 4:14 am    Post subject: Reply with quote

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.
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