Audio output from multiple applications

Hi,

I am trying to get audio output from multiple applications. One being kodi and the other one being alexa. However one of the applications grabs hold of the alsasink and so the other one is unable to play anything. I’ve been trying with pulseaudio and also with dmix.

Everything has been failing I can’t seem to get both of them to provide output. Is there anyone who can maybe try and help me setup a working .asoundrc or any other ideas what might be causing this and how to fix it?

We have deprecated pulseaudio so any solution using that isn’t recommended. If you post your alsa conf files for the dmix solution (.asoundrc and any others you have edited) someone may be able help.

I have tried a ton of different combinations, but generally I have been trying to get default to refer to dmix. Currently my .asoundrc looks like this:

pcm.dsnooper {
type dsnoop
ipc_key 816357492
ipc_key_add_uid 0
ipc_perm 0666
slave {
pcm “hw:1,0”
channels 1
}
}
pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm “hw:0,0”
period_time 0
period_size 1024
buffer_size 8192
rate 44100
}

}

pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm “dmixer”
}
capture.pcm {
type plug
slave.pcm “dsnooper”
}

This particular config was taken from the avs sdk troubleshooting guide. But altered hw:1,0 to 0,0 because 0,0 is my audio card (hdmi)

I’ve also tried a very basic:
pcm.!default {
type plug
slave.pcm “dmix”
}

I’ve had a play with some .asoundrcs and I can’t get dmix to work even with one source. Typical response:

osmc@pi3matrix:~$ speaker-test -t wav  -l 3 -c 1

speaker-test 1.1.8

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
WAV file(s)
ALSA lib pcm_direct.c:1193:(snd1_pcm_direct_initialize_slave) requested or auto-format is not available
ALSA lib pcm_dmix.c:1120:(snd_pcm_dmix_open) unable to initialize slave
Playback open error: -22,Invalid argument

ALSA is the most frustrating system ever. There does seem to be a dmix bug reported for RaspberryPiOS Buster and someone says the sysdefault device is a dmix device which works. But that doesn’t happen on OSMC. And it’s the same on Vero so I don’t know what to suggest.

Yes it’s the same error I am receiving currently. So the only possible solution would then to use pulse audio even though it’s deprecated? The issue I had with pulse audio seemed to be that kodi would try to use alsasink instead of pulsesink. I understand if there is no support for pulseaudio, but I would love to get this working.

Any other ideas as to what I can try instead of alsa/pulseaudio?

Not really. We used to use pulse with BT audio but now @sam_nazarko’s not keen to support it. I think someone in here got it working under Buster by compiling it himself.

Okay well thanks for the info. Hopefully someone else has an idea how to get it working using alsa and in the meantime I guess I’ll try to compile pulse myself all tough I’m a bit confused why I would need to compile pulseaudio myself wouldn’t apt-get work? Or do you mean compile osmc myself to use pulseaudio?

Edit2: I’ve found the thread you were talking about and will try it myself

this is the most frustrating thing ever. With pulseaudio I’m running into:

Failed to find a working profile.
pulseaudio[9766]: Failed to load module “module-alsa-card”

I’d also rather stay simply on alsa. do you think this will be remedied by a future osmc update grahamh? Or should I just give up.

Unless we’ve both misunderstood how the alsa conf system works (entirely likely as it’s so byzantine) it seems this is a bug in alsa itself which no-one on Team OSMC is likely to be able to fix.

If you’ve got a spare SD card lying around, you could see if it works with an old OSMC version based on Debian Stretch. If so, we might stand a chance of fixing it (or getting ALSA to fix it).

Wait - I’ve found a card with an old version on.

Different problem - just hangs - that’s progress of a sort :wink:

osmc@pi2:~$ speaker-test -t wav -Ddmix -l 3 -c 2

speaker-test 1.1.3

Playback device is dmix
Stream parameters are 48000Hz, S16_LE, 2 channels
WAV file(s)
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 2048 to 16384
Period size range from 1024 to 1024
Using max buffer size 16384
Periods = 4
was set period_size = 1024
was set buffer_size = 16384
 0 - Front Left
^CWrite error: -4,Interrupted system call
xrun_recovery failed: -4,Interrupted system call
Transfer failed: Interrupted system call

I guess it’s progress but honestly I have no clue how to troubleshoot this. I am going to do another attempt using pipewire. But honestly I don’t have a lot of hope.

no dice unfortunately, although I am running into different issues trying the alsasink. Anyways I hope this is something that will be fixed in a future update (if possible) otherwise I guess I am out of luck. The only other way I can think of getting this to work is by getting kodi to use pulsesink instead of alsasink but I don’t know how to do that.

Using pipewire I am at least able to get playback from another application after kodi releases the device after 1 minute. So no simultaneous playback but at least I can do something with this :slight_smile:

FWIW, I’ve been attempting to get Jack to work, based on this:

Jack doesn’t have a built-in function similar to dmix but dmix using the Loopback as a slave seems to work. I can’t get the Jack bit of it to work, though. Getting my playbacks and captures mixed up I think.

If you’re tempted, don’t use Jack2 (needs X11). The package I’m using is jackd1.

Using Jack may be overkill but I’ve long had an idea to use it for audio plug-ins like an equaliser for my headphones.

I guess you found this:
https://www.raspberrypi.org/forums/viewtopic.php?t=262071
Since we have the same problem, and also with Vero, I guess the RPi guys can’t do much about it.

I am definitely tempted. Could you elaborate on this bit: I can’t get the Jack bit of it to work, though

Do you mean you’re not actually getting audio? Or do certain functions that jack provides not work?

While tempted I am also a little hesitant to throw away the setup I have now created as it semi functions^^

edit: ■■■■ it I’m going for it. As you probably noticed I am not very good at these things, but at the same time I love learning about some of these aspects.

I enabled the Loopback device and put stuff in .asoundrc which I thought would let me play through Loopback, thence to Jack and then to the default sink (ie I didn’t think it needed the alsa_out bit).

osmc@pi2:/usr/share/sounds/alsa$ cat ~/.asoundrc
pcm.dmixer {
        type dmix
        ipc_key 1024
        slave {
                pcm "hw:Loopback,0,0"
                channels 2
        }
}

# the capture device Jack will listen to with alsa_in
pcm.cloop {
        type dsnoop
        card Loopback
        device 1
        subdevice 0
}

Using alsa_in without sudo I got a message about permissions. Couldn’t be bothered to do what was suggested and got this:

osmc@pi2:/usr/share/sounds/alsa$ sudo alsa_in -j cloop -dcloop
connect(2) call to /tmp/jack-0/default/jack_0 failed (err=No such file or directory)
jackd 0.125.0rc1
Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.
jackd comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details

JACK compiled with System V SHM support.
loading driver ..
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
ALSA: Cannot open PCM device alsa_pcm for capture. Falling back to playback-only mode
configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods
ALSA: final selected sample format for playback: 16bit little-endian
ALSA: use 2 periods for playback
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cloop
Capture open error: No such file or directory
osmc@pi2:/usr/share/sounds/alsa$ jack main caught signal 12

Then went to bed.
Today after fixing the /etc/security thing I get this:

osmc@pi2:~$ alsa_in -j cloop -dcloop
connect(2) call to /tmp/jack-1000/default/jack_0 failed (err=No such file or directory)
jackd 0.125.0rc1
Copyright 2001-2009 Paul Davis, Stephane Letz, Jack O'Quinn, Torben Hohn and others.
jackd comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details

JACK compiled with System V SHM support.
cannot lock down memory for jackd (Cannot allocate memory)
loading driver ..
creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
ALSA: Cannot open PCM device alsa_pcm for capture. Falling back to playback-only mode
configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods
ALSA: final selected sample format for playback: 16bit little-endian
ALSA: use 2 periods for playback
JACK: unable to mlock() port buffers: Cannot allocate memory
JACK: unable to mlock() port buffers: Cannot allocate memory
ALSA lib pcm_direct.c:1765:(snd1_pcm_direct_parse_open_conf) Unknown field card
Capture open error: Invalid argument
osmc@pi2:~$ jack main caught signal 12

Oops! I changed ‘type hw’ to ‘type dsnoop’ yesterday but forgot to add a slave. Now I have:

osmc@pi2:~$ cat .asoundrc
pcm.dmixer {
        type dmix
        ipc_key 1024
        slave {
                pcm "hw:Loopback,0,0"
                channels 2
        }
}

# the capture device Jack will listen to with alsa_in
pcm.cloop {
        type dsnoop
        ipc_key 1025
        slave {
                pcm "hw:Loopback,1,0"
        }
}

Which is much more promising.

I’m already stuck much earlier. Obviously I don’t have the loopback card which was created while building snd-aloop from source. Did you build it from source? If not how did you get the loopback card in?
Because snd-aloop came with osmc

snd-aloop is there. just sudo modprobe snd-aloop

then check aplay -L

Hmmm. alsa_in is using up 30% CPU :open_mouth:

I’m not getting any errors or anything, but I’m not getting sound either haha. 30% cpu isn’t great either :frowning:

sudo modprobe snd-whatever-module-you-need 

did i miss anything here?

Success!! At least with one source at a time.

So you need:

  • sudo modprobe snd-aloop
  • the correct .asoundrc
  • alsa_in -j cloop -dcloop, which will spew out messages like delay = 991 unless you kill it and do
  • alsa_in -j cloop -dcloop -q 1 2>&1 1> /dev/null &

and finally make the jack connection:
jack_connect cloop:capture_1 system:playback_1

Nice! Now only multiple sources to go haha.
Imma have to go for a bit but thank you so much for figuring this out for me! If you have even more success please share :slight_smile:

Yes, I did two aplays to the same dmixer and they played over each other :sunglasses: