Audio output from multiple applications

Nice! Would you share the asoundrc you ended up using?

Just scroll up.

Next we need to make dmixer the !default and dig into Jack a bit more to see about minimising latency.

Alright! Almost there :smiley:

The dmixer device shows up in Kodi settings as ALSA:Loopback(). If I choose that I can play something else (with aplay) at the same time as Iā€™m watching TV. Lipsync is OK but sound keeps dropping out so I think we need bigger buffers somewhere.

1 Like

I am not as far along as you are. Iā€™ve done the same steps but I am not getting: ALSA:loopback()

Instead I have loopback loopback PCM

Which provides no audio.

I also have the same error as you had before: connect(2) call to /tmp/jack-1000/default/jack_0 failed (err=No such file or directory)
jackd 0.125.0rc1

Not sure if this is something to be ignored.

alsa_in -j cloop -dcloop sometimes works but sometimes does not.

Furthermore jack_connect cloop:capture_1 system:playback_1

Does not return anything which I am not sure is a problem?

To be exact, mine says ALSA:Loopback(),Loopback PCM

I think that means Jack isnā€™t doing what it should.

Iā€™m getting that even though itā€™s working.

Did you add the line to /etc/security/limits.conf? I was prompted to do that when I ran alsa_in as osmc. (I had declined it when installing jackd1). Should be:

@audio - rtprio 99

Iā€™m a bit worried that by trying pipewire you have messed something up. Have you removed it with --purge to get rid of any conf files? I believe itā€™s Jack-compatible (ie itā€™s a Jack substitute).

Doesnā€™t return anything here but still working.

I had accepted it during jackd installation but will look at the file tomorrow. Also I have started with a fresh osmc installation so no pipewire.

About the buffer isnā€™t that something we can specify in .asoundrc relatively easy? (In so far as any of this is easy)

Ps. I donā€™t have to do anything with jackd apart from the aforementioned things right? Like I donā€™t have to start it in some other way?

It just seemed to start by itself, here, but I did reboot after changing that file. Jackd1 doesnā€™t use systemd to start and I canā€™t find it in rcS.d either. Parameters are passed to it when you start it. It doesnā€™t have the equivalent of jack2ā€™s jack_control.

Still learning.

I am still having trouble getting any sound. My cat .asoundrc is the same as yours. Did you do anything with /etc/modprobe.d/sound.conf ?

Lsmod | grep aloop gives me the following

osmc@osmc:~$ lsmod | grep aloop
snd_aloop 32768 8
snd_pcm 139264 10 snd_usb_audio,vc4,snd_compress,snd_soc_core,snd_aloop,snd_pcm_dmaengine
snd_timer 40960 4 snd_aloop,snd_pcm
snd 106496 28 snd_seq_device,snd_hwdep,snd_usb_audio,snd_usbmidi_lib,snd_timer,snd_compress,snd_soc_core,snd_aloop,snd_pcm,snd_rawmidi

just to be clear my .asoundrc is:

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"
    }
}

had some trouble with the makeup of the quote but the idents etc are correct.

alsa_in -j cloop -dcloop works fine.

It seems to go wrong somewhere here:

  • 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

as if its not connecting. if i run: speaker-test -t wav -Ddmix -l 3 -c 2
it doesnā€™t give errors but doesnt give sound either. In kodi I can select multiple loopback audio devices. none work.

Hmmm. Iā€™ve just realised I was doing all my stuff on a rather old Kodi, Stretch and kernel 4.19. Apologies. Iā€™ll try again on Matrix/Buster/5.x later but I have to go out shortly.

Alright thanks :slight_smile:

Got this far. More later ā€¦

osmc@pi3matrix:~$ alsa_in -j cloop -dcloop
connect(2) call to /dev/shm/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.
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
Sorry. The audio interface "hw:0" doesn't support any of the hardware sample formats that JACK's alsa-driver can use.
ALSA: cannot configure playback channel
cannot load driver module alsa
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
jack server not running?

Iā€™m getting past that but still no audio. Running out of ideas.

Maybe I could simply solve this by getting audio out through analogue (3.5 jack) all tough the same dmix issues are likely to arrise I think.

NOTE: For ALSA 1.0.9rc2 and higher you donā€™t need to setup dmix for analogue output. Dmix is enabled by default for soundcards which donā€™t support hardware mixing. You still need to set it up for digital outputs.

Iā€™m stumped. By using pulseaudio I can play multiple sound files at the same time using aplay piano2.wav for example.

however as soon as that happens kodi loses audio. When the files finish playing kodi starts playing audio again. If I select keep audio device alive = no in kodi settings kodi loses all audio output. I feel the fix to this is very close if I can just get kodi to use pulseaudio. But as osmc deprecated pulseaudio I donā€™t know if anyone can/will tell me how to do this.

CAESinkALSA::Initialize - Attempting to open device ā€œsysdefault:CARD=vc4hdmi0ā€
INFO : CAESinkALSA - Unable to open device ā€œsysdefault:CARD=vc4hdmi0ā€ for playback

it wants to open sysdefault which apparantly pulse doesnt pick up?

Iā€™m also still open to the jackd1 idea but I donā€™t know how to continue there either.

FWIW, Iā€™ve been bashing away at the Jack solution, but just canā€™t get Jack to output to the RPiā€™s audio device which is IEC958. Alsa can convert from LPCM to IEC958 with a standard plug, and I can get Jack to talk to that plug if I specify it when starting jackd. But alsa_in always fails. It seems to be bypassing the setting you put in the jackd call and always trying to connect to hw:0.

I imagine all you need for pulse is a suitable alsa.conf. IIRC Buster automatically puts a conf file for pulse in /usr/share/alsa somewhere and I think Kodi was recognising it until we took it out.

In other distros, pulse just muscles in and sets itself up as the default sink. It should be possible. All that should be required is a !default to override the vc4-hdmi.pcm.default in the cards directory.

yes i have a alsa.conf and a pulse-alsa.conf in there, but I am not sure where to move them to. the pulse-alsa.conf looks like a .asoundrc file but putting the contents in there doesnā€™t seem to do the trick.

Doesnā€™t matter where they are really but I think alsa reads them from the many places you can put them in a certain order. Iā€™m sure .asoundrc must take precedence. That is, it only matters if you have ! override.

what should be the default this doesnt seem to work which is the pulse-alsa.conf:

pcm.!default {
type pulse
hint {
show on
description ā€œPlayback/recording through the PulseAudio sound serverā€
}
}

ctl.!default {
type pulse
}

to expand:

default
Playback/recording through the PulseAudio sound server

this is my aplay -L however kodi still uses sysdefault

Also I really want to thank you for your patience and trying to help me out. A lot of this stuff is really difficult for me to grasp.

more kodi log:

INFO : CAESinkALSA - Unable to open device ā€œpulseā€ for playback
INFO : CAESinkALSA::EnumerateDevice - device sysdefault:CARD=vc4hdmi0 description vc4-hdmi-0, MAI PCM vc4-hdmi-hifi-0
Default Audio Device
INFO : CAESinkALSA::EnumerateDevice - device hdmi:CARD=vc4hdmi0,DEV=0 description vc4-hdmi-0, MAI PCM vc4-hdmi-hifi-0
HDMI Audio Output

It chooses the sysdefault one not sure if it would help if it would take the second one.

edit:
INFO : CAESinkALSA - Unable to open device ā€œdefaultā€ for playback

this would seem to be the culprit as that is the pulse audio server. No clue why it canā€™t open it though

This may be the same problem Iā€™m having. I donā€™t know how to address that vc4-hdmi.pcm.default (plug) device specified in /usr/share/alsa/cards/vc4-hdmi.conf. Certainly if you have a !default definition, alsa, kodi or pulse will never find it by the name default. What Iā€™ve been attempting is making a copy of it with another name, something like this (and you can see things Iā€™ve tried!)

# plug needed for default hw:0,0
pcm.jackdefault {
#        @args [ CARD ]
#        @args.CARD {
#                type string
#        }
        type plug
#       slave.pcm "hdmi:0"
        slave.pcm "default:vc4-hdmi"
#       slave.CARD "vc4hdmi"
}

But thereā€™s something about the args I donā€™t get. Is CARD 0 or vc4-hdmi or vc4hdmi?? Probably pulse and kodi work the same way - they look at all the alsa sinks on offer and try to open them. If successful they are listed.

Youā€™re very welcome. A pleasure to work with someone whoā€™s prepared to put some work in to solve a problem. As I say, I can see other uses for the Jack connection if we can get it going. the problem with both Jack and pulse is 99% of users have X11 or some other desktop and thereā€™s not much advice on command line operation.

Iā€™ve made progress with pulseaudio. I can now have playback on kodi and simultaneously play another audio file i.e. piano2.wav however it only works if i use sudo aplay piano2.wav

aplay piano2.wav cannot play simultaneously. This leads me to a permission issue

osmc@osmc:~$ aplay piano2.wav
Playing WAVE ā€˜piano2.wavā€™ : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
osmc@osmc:~$ sudo aplay piano2.wav
Playing WAVE ā€˜piano2.wavā€™ : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
osmc@osmc:~$

the first one doesnt actually produce sound while kodi is playing audio. The second one however does

I donā€™t know what permission to fix though the entire home folder is already owned by osmc.

Though for my initial goal of having alexa side by side with osmc kodi I can say that my problem is now resolved. I can run alexa with sudo and have simultaneous audio.

Now at some point I want audio to go through the 3.5 mm jack but for now Iā€™m happy with it working through hdmi :slight_smile:

1 Like