Can Shairport coexist with LMS+Squeezelite?

I have installed all three (LMS, squeezelite and Shairport) on the same raspberry pi, but I can’t seem to make Shairport work: I can connect to it but I have no audio output.
The RPi is equipped with a USB sound card, which is correctly configured (via asound.conf) and it works correctly with squeezelite.
Any suggestions? :slight_smile:
Thanks

ALSA with ‘hw’ is only capable of playing 1 output stream at a time, unless, you enable software mixing (dmix) for the soundcard. See here for asound.conf:
http://www.alsa-project.org/main/index.php/Asoundrc#dmix

I know that, but I am not playing two output streams at the same time.
Unless squeezelite sort of “seizes” the sound card for itself.
I’ll try disabling squeezelite and see if this way shairport works.
I’ll report my findings :slight_smile:

Ok, disabling squeezelite makes shairport work.
I’m not savvy enough to set up dmix, so I guess I’ll just stay with squeezelite.
It would have been a good way to stream Spotify though.

I have the same problem.

Shairport can nicely coexist with Roon bridge and play successfully when Roon is not streaming, but not with Squeezelite.

Can be Squeezelite configured to release the ALSA hw, when not playing?

Is there other more smart alternative to Squeezelite to play Squeezebox on DietPi?

As Fourdee explained above, it can be done by enabling software mixing in ALSA.
I will look into it as soon as I find the time, hoping it is not beyond my skills/capabilities.

Another way to achieve this is by installing MPD server / Mopidy and Shairport… I have tried and it works, but with some limitations that make me prefer LMS / Squeezelite over this solution because:

  • I couldn’t find a way to make MPDroid (the Android app to manage the MPD server) work properly.
  • Overall the system is too slow
  • TuneIn radio stations cannot be set as favorites for easy access to them

I might try to optimize the system in order to check if it becomes more responsive and to overcome those limitations (there are lots of plugins that might help), but it seems to me that LMS is a much better project overall.

Asound.conf for dmix as default device.
Make sure you remove any custom soundcard definitions you have added in squeezelite and shairport.
Copy and paste all, then reboot:

cat << _EOF_ > /etc/asound.conf
pcm.!default {
    type plug
    slave.pcm "dmixer"
}

pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}

ctl.!default {
    type hw
    card 0
}
_EOF_

Above is for card 0, so, if your card is 1 (eg: Odroid HiFi Shield), use this one:

cat << _EOF_ > /etc/asound.conf
pcm.!default {
    type plug
    slave.pcm "dmixer"
}

pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:1,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}

ctl.!default {
    type hw
    card 1
}
_EOF_

Since I am using a USB sound card, I used the second version, but it’s not working.
Squeezelite player does not show up as an available player connected to the LMS server.
Also, shairport won’t play any music.

Here is my /etc/asound.conf

pcm.!default {
    type plug
    slave.pcm "dmixer"
}
 
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:1,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}
 
ctl.!default {
    type hw
    card 1
}

I have also tried adding “device 0” at the end, but the result hasn’t changed.

Whats the result of?:

aplay -l

Does the following sound test work? (ctrl+c to stop):

speaker-test -c 2 -D hw:1,0

Result of ‘aplay -l’:

card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

I can’t post the results of the speaker test because at the moment I’m not physically present where the Raspberry Pi is. :slight_smile:

Yep, thats definitely card 1. Should be working fine, bizarre.

Think we’ll need to wait for speaker-test results on this one. :slight_smile:

Here you go… it seems like the hardware is kept hostage :smiley:

root@DietRasPi:~# speaker-test -c 2 -D hw:1,0

speaker-test 1.0.28

Playback device is hw:1,0
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Playback open error: -16,Device or resource busy

EDIT: wait a sec… the speaker-test is not working, but somehow now both shairport and squeezelite are working at the same time!! I managed to stream Spotify from my phone to the Pi. The only problem is that it’s not a good stream: it’s choppy (it works intermittently for a few seconds).

  1. SW mixing is degradation audio quality.
  2. I think this solution is wrong path, as it doesn’t address the root cause.

In my opinion the Squeezelite behaviour should be fixed - why it is blocking for exclusive use the sound card while not playing?, and with this not permitting Shairport to play on it?
Isn’t this is root cause of the problem.

FYI, I’m running two other RPIs with Roon Bridge plus Shairport nicely coexisting in same RPI and allowing reach other to play when not playing itself. Root RAAT protocol is high performing, and great tool.
https://roonlabs.com

Only problem I have is RPI Zero with old ARM6, where Roon is not compiled, and I have to use Squeezelite workaround…

FYI, DietPi is highly popular among Roon community. Thank you for great job you guys are doing!

Janis

I agree that ‘freeing’ the sound card when not in use would be the right path to follow, but I have no idea how this could be achieved.

Well I guess the issue should be documents and fix requested to guys that created Squeezelite?

I was searching Squeezelite set-up on found on its site following
https://github.com/ralph-irving/squeezelite

Squeezelite v1.8, Copyright 2012-2015 Adrian Smith, 2015-2016 Ralph Irving.
Usage: squeezelite [options]
-C Close output device when idle after timeout seconds, default is to keep it open while player is ‘on’

So, with this option, if I understand correctly, we should be able to release the sound card after lest say 5 sec of not being used by squeezelite

The problems I have on DietPi though:

  1. -C option doesn’t show up in the installed squeezelite option - don’t understand why?
  2. Also I don’t know where are autolaunch script of squeezelite to change its default launch configuration?

Janis

Default options are stored in /etc/defaults/squeezelite, I think.

With v138 update, now it is fixed - both squeezelte and shairport nicely coexist and play one after other on the same Raspberry Pi.

THANK YOU Fourdee for getting it fixed so prompt !

No worries, good to hear :slight_smile:

That’s great news!
Is upgrading enough to enjoy the fixes or do we need to reinstall squeezelite and/or shairport?
And what about the edits to asound.conf? Do we bring the file back to its original state (no dmix)?
Thanks!