badaix / snapcast

Synchronous multiroom audio player
GNU General Public License v3.0
6.1k stars 452 forks source link

ALSA Resample Input - Use more Player with Snapcast #45

Closed bjwelker closed 4 years ago

bjwelker commented 8 years ago

Hi someone get snapcast runnig with the spotify-connect-web client ? https://github.com/Fornoth/spotify-connect-web

I try to route the alsa output to the fifo but i didn´t get it working ...

pfink commented 8 years ago

If you explain us exactly what you did (preferebly all commands and config file changes), we may can help you...

bjwelker commented 8 years ago

Hi, i create a /ets/asound.conf with this input pcm.!default { type file # File PCM slave.pcm "hw:0,0" # This should match the playback device at /proc/asound/devices file /tmp/snapfifo # Output filename format raw # File format ("raw" or "wav") perm 0666 # Output file permission (octal, def. 0600) }

Now the sound from the raspberry card should also routed to the snapcast fifo. The spotify connect client is startet with ./spotify-connect-web.sh --username 12345678 --password xyz123 --bitrate 320 so it uses the default alsa card. I can´t get sound to the snapcast client. The test with sudo cat /dev/urandom > /tmp/snapfifo is working fine. You can use --device on the spotify client i try that with --device default but nothing :( I think it´s a alsa routing problem ...

pfink commented 8 years ago

First of all, directly piping the audio stream to your hardware device via alsa doesn't make any sense because you'll loose synchronicity (your other devices will have ~1 second delay). Did you get snapclients on other devices working?

If yes, you should remove

slave.pcm "hw:0,0" # This should match the playback device at /proc/asound/devices

and also install snapclient on your device with spotify connect web client. Because you configured the file plugin as your default alsa device, it'll not work out of the box (this would be a loop because snapclient would also stream to the file). So you would have to stop snapclient

service snapclient stop

and then list your pcm devices with /usr/sbin/snapclient -l. Then, find out the number of your hardware pcm device and start snapclient with /usr/sbin/snapclient -s <DEVICE_NO>. Good luck!

bjwelker commented 8 years ago

Ok but the first problem is that no sound is comming to the snapcast clients. i think some of the alsa stuff is wrong here so the sound issn´t put to the fifo from snapcast ...

pfink commented 8 years ago

I don't know if snapcast is working with the alsa file plugin, obviously it's not listed in the docs atm. First step is to remove the line I mentioned above, then you should debug your alsa configuration and snapserver/snapclients with a simple .wav audio file and aplay. As soon as this works, you can go ahead with Spotify-Connect-Web.

Furthermore, I would recommend to change the title of this issue. This is nothing specific to spotify connect webclient - if you manage to get it working with the alsa file plugin, this solution would work for nearly every linux audio player software out there. Normally, the pipe is like this:

audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa

What you try to achieve is this:

audio player software -> alsa -> alsa file plugin -> snapfifo -> snapserver -> network -> snapclient -> alsa

This would remove the requirement that the audio player should support streaming audio to a file (and we currently have this requirement according to the docs: The only requirement is that the player's audio can be redirected into the Snapserver's fifo).

bjwelker commented 8 years ago

Ok with this asound.conf i have it perfect running now :) Spotify Connect Multiroom :+1:

pcm.!default { type plug slave { pcm rate48000Hz # Direct default output to the below converter } } pcm.rate48000Hz { type rate slave { pcm writeFile # Direct to the plugin which will write to a file format S16_LE

channels 2

    rate 48000
}
#route_policy copy

}

pcm.writeFile { type file slave {

pcm card0 # Now write to the actual sound card

    pcm null
}
file "/tmp/snapfifo"
format "raw"

}

pcm.card0 { type hw card 0 }

ctl.card0 { type hw card 0 }

pfink commented 8 years ago

I don't get it. What is the purpose of this?

slave {
#pcm card0 # Now write to the actual sound card
pcm null
}
bjwelker commented 8 years ago

you need the slave {

pcm card0 # Now write to the actual sound card

pcm null } for the file output and the pcm null doesn´t make an output so snapclient can do that. you can´t remove slave from there

bjwelker commented 8 years ago

a cleaner version

pcm.!default { type plug slave { pcm rate48000Hz # Direct default output to the below converter } } pcm.rate48000Hz { type rate slave { pcm writeFile # Direct to the plugin which will write to a file format S16_LE rate 48000 } }

pcm.writeFile { type file slave.pcm null file "/tmp/snapfifo" format "raw" }

pcm.card0 { type hw card 0 }

ctl.card0 { type hw card 0 }

pfink commented 8 years ago

Even cleaner should be:

pcm.!default {
    type plug
    slave.pcm rate48000Hz
}

pcm.rate48000Hz {
    type rate
    slave {
        pcm writeFile # Direct to the plugin which will write to a file
        format S16_LE
        rate 48000
    }
}

pcm.writeFile {
    type file
    slave.pcm null
    file "/tmp/snapfifo"
    format "raw"
}

@badaix: I think it would be a good idea to take this into the documentation because it opens up much more use cases for snapcast :)

bjwelker commented 8 years ago

You´re right. just test this about 30 min with 3 clients works so perfect! Now i need to get that in combination with volumio and bye bye sonos ;)

renearts commented 8 years ago

^ That would be great. Especially with the new, more modular setup of Volumio 2 (RC1 released a few days ago!) it would be awesome to integrate snapcast. Finally a true open source hard and software multiroom audio system :)

badaix commented 8 years ago

Nice discussion :smile: and cool to see what people are doing with Snapcast. @pfink yep, I will add the alsa hack to the README.md

Edit: done

From my point of view are two things missing:

bjwelker commented 8 years ago

I have the spotify-connect and volumio running :)

bjwelker commented 8 years ago

@badaix is the json api of the client documentet somewhere? So you can start stop the stream via python an gpio buttons

bjwelker commented 8 years ago

I just install voumio2 and there is the snapcast entry already in the mpd.conf with label multiroom so maybe it´s in when the release comes

badaix commented 8 years ago

@bjwelker the missing specification is a known issue #22 There is a spec.md with real life server messages, but it's not a specification yet. I guess control.py is out of date. Best example for requests might currently be the java code

renearts commented 8 years ago

I have just been fiddling with Volumio2 RC1, really starts to be something. Maybe the best part: snapcast was already installed (both client and server) and present in the mpd config. Though I should mention it was version 2.6.xxx But hey, it is a (good) start at least :)

Anjerlaan commented 8 years ago

Hi bjwelker,

I am curious how your setup with spotify-connect and volumio is? I have 2 Rpi's (RPi 1b & RPi 2b) running with Volumio 1.55 and both have the fornoth spotify-connect running.

  1. RPi 2B is connected with with wired LAN and audio out HDMI to my AV Yamaha Receiver. This would be my snapcast server.
  2. RPi 1B runs wireless has a Behringer DAC attached. This would be my snapcast Client

My goal is to use them both seperatedly but also in multiroom option. Is this possible, and if so do you have a kind of tutorial to follow?

bjwelker commented 8 years ago

@Anjerlaan you need the settings if postet for alsa. then you need to install the snapcast server AND the client on the server raspberry. On the client raspberry you need to install the snapcast client only. Then you can use spotify-connect and volumio on the server and client both as multiroom and both as single. I play on my kitchen radio something for the kids and on the livingroom spotify connect.

vdbee commented 8 years ago

Maybe the asound.conf that I posted in #43 is off value here as well. It enables snapcast in combination with other players that all share the same USB -DAC.

Anjerlaan commented 8 years ago

@bjwelker how do you install snapcast on volumio 1.55, by source or by .deb package? By source i have some difficulties with the client. If i follow the by source steps soms errors occur during installation and if i follow the steps on the volumio forum too. A combination of both did install stuff, but i only get audio from the 3.5mm plug. But i have a behringer uac202 USB dac, which i can't get sound from anymore. Snapcast.git is placed in the /root folder just like Spot. Connect. If I list the PCM devices i get 21 devices, i tried the sysdefault USB dac with -s 12 ( which i think is the dac) in the snapclient settings but the sound keeps comming only from the 3.5mm plug. And i can't find the snapclient.service file in that directory as badaix explained on the volumio forum.

bjwelker commented 8 years ago

@Anjerlaan just take the .deb for armhf and install it. Did you want the Volumio Server output the audio to your dac AND snapcast fifo ? Or only to the fifo and you take some snapclient raspberrys ?

Anjerlaan commented 8 years ago

Server is Rpi2b with hdmi audio to AV receiver and client is Rpi1b wireless with behringer dac. I wan't Server/Client on Rpi2b and Client on Rpi1b, but Client must also work standalone without snapcast.

bjwelker commented 8 years ago

If the client should also work with and without snapcast i think you need a special alsa.conf so the device is not blocked.

Anjerlaan commented 8 years ago

Mmmm...maybe not nessecary with my setup. I will only use the (mobile) Rpi Client in my garden. if I don't want music in the livingroom I turn of the AV receiver or switch to another HDMI channel (to watch TV for instance). And if i don't wan't music in the garden I turn off the Rpi.

Anjerlaan commented 8 years ago

Okay install went smoothly on both devices, with no errors. Changed the mpd.conf on the server according to the example. Also created/modified the asound.conf for Spotify Connect re-routing.

Started webradio stream on volumio server/client: No sound (via HDMI) on the Server/Client Crackling sound on the Client, more like noise

DLNA stream to volumio Server/Client: No sound (via HDMI) on the Server/Client Crackling sound on the Client, more like noise

Spotify Connect on Server/Client Sound (via HDMI) on the Server/Client!! No sound on the Client

What am i doing wrong?

bjwelker commented 8 years ago

Did you Switch to hdmi Sound out?

Anjerlaan commented 8 years ago

Working!....figuring out which audio device the clients use with snapcast -l then editing both /etc/default/snapclient files with -s and Audio Device ID number

Only Spotify Connect is not yet working... I only created the Alsa config /etc/asound.conf on the server...or do I need to do that on both?

bjwelker commented 8 years ago

@Anjerlaan you need to make a asound.conf in the spotify-connect chroot dir. spotify-connect don´t use the /etc/asound.conf

bjwelker commented 8 years ago

@badaix can you route the snapclient output in the alsaequal or is a alsa output not possible ?

Anjerlaan commented 8 years ago

@bjwelker aha, now I understand why it didn't work! When I created the /etc/asound.conf and afterwards I listed the (snapserver) snapclient -l, I noticed that the asound.conf chain was integrated in the snapclient list like this: 1 Default 2 rate48000hz 3 WriteFile 4 was my default Alsa HDMI Audio Device

So that's why the Audio Device of the (Server) Client didn't work out of the box. However after deleting the asound.conf chain and a RPi reboot, the Audio Device list did not change....is that stored in some cache file?

1337sup3rh4x0r commented 8 years ago

@bjwelker, does pausing playback via the Spotify app work for you? As explained in #75, whenever I pause, the snapserver just starts playback over again at the beginning of the snapfifo file that spotify-connect-web wrote. So if I start a fresh session of spotify-connect-web and play a song for 5 seconds and then pause, all snapcast clients will loop this 5 second part endlessly. I have no clue what's wrong with my setup

lakeconstance78 commented 8 years ago

Hello,

regarding to the post:

bjwelker commented on 22 Apr • edited

@Anjerlaan` you need to make a asound.conf in the spotify-connect chroot dir. spotify-connect don´t use the /etc/asound.conf

Spotify-connect-web works perfectly in /etc/asound.conf if you don't use the variable default. If you use for example snapcast it works perfectly.

When you start spotify-connect-web you can use the parameter -o snapcast e.g. ./spotify-connect-web --username 11111111 --password qwertz --name SpotRasp -o snapcast

pcm.!snapcast {
type plug
slave {
pcm rate48000Hz # Direct default output to the below converter
}
}

pcm.rate48000Hz {
type rate
slave {
pcm writeFile # Direct to the plugin which will write to a file
format S16_LE
rate 48000
}
}

pcm.writeFile {
type file
slave.pcm null
file "/tmp/snapfifo"
format "raw"
}

B.

djidji73 commented 7 years ago

Hello everyone! I need some help I've been stuck for two days , I have :
-a RPI 3 with volumio and spotify connect web installed working perfectly, on which I installed both snapserver and snapclient -a RPI 1 with raspbian and snapclient installed

-I created a asound.conf file in the RPI 3 /etc directory following the clean version from @pfink -when i start the snapclient on my RPI1 it connects to the snapserver on my RPI3 but then tells me their are NO CHUNKS AVALAIBLE even though RPI 3 is playing music

of course I am missing something but I don't know what, As anybody some help to offer???, Thanks!

s1lvester commented 7 years ago

@djidji73 Are you sure your Client is connected to your Server (RPI 3 logs the HELLO-Command)? Sometimes for some weird reason they don't actually see each other (zeroconf / avahi can be a bit bitchy).

I usually set the servers hostname in the clinet's parameters, e.g.: snapclient -h serverhostname

djidji73 commented 7 years ago

@s1lvester Thank you for your reply!

Yes I've checked and my RPI1 connects to the snapserver perfectly, I think I'm missing something around the ALSA and asound.conf because playing noise via sudo cat /dev/urandom > /tmp/snapfifo i've got sound on both RPI1 & RPI3

What I can't understand : I tried to play a .wav on the RPI3 and I hear it only on the RPI1, but when I play a song on spotify on RPI3, I hear it only on RPI3 not on RPI1

Any advice is welcome!

B3NG commented 7 years ago

Hi @djidji73, the problem seems not to be the snapcast-Config, because you're getting sound from the sudo cat /dev/urandom > /tmp/snapfifo-Test... It looks like the typical spotify-alsa-resample-problem.

Where did you create the asound.conf? In /etc/ or in the spotify-connect-chroot <chroot>/etc/ ? You have to create the asound.conf in the <chroot>/etc/-directory ! (like in the post of @breadstuff)

<chroot>/etc/asound.conf:

pcm.!snapcast {
    type plug
    slave {
        pcm rate48000Hz # Direct default output to the below converter
    }
}

pcm.rate48000Hz {
     type rate
     slave {
          pcm writeFile # Direct to the plugin which will write to a file
          format S16_LE
          rate 48000
     }
}

pcm.writeFile {
    type file
    slave.pcm null
    file "/tmp/snapfifo-spotify"
    format "raw"
}

Important is that the file "/tmp/snapfifo-spotify"-Line in the pcm.writeFile {-section: It's the relative path in the chroot. The real path to the pipe is: <chroot>/tmp/snapfifo-spotify. You have to specify it in the /etc/default/snapserver as an absolute path:

SNAPSERVER_OPTS="-d -s pipe://<chroot>/tmp/snapfifo-spotify?name=<SPOTIFY-FOO-BAR>&mode=read"

In my setup I did also a bind-mount from /tmp/ to <chroot>/tmp/ - so I don't have to care about absolute and relative paths in the snapserver-config and the <chroot>/tmp/ is also in the RAM. ;)

Another important thing is, that you have to specify the <ALSA-DEVICE> when you run spotify-connect (which you configured in <chroot>/etc/asound.conf). Here it's the snapcast-device, named in the pcm.!snapcast {-section.

When you run spotify-connect-web.sh then you have to add the -o <ALSA-DEVICE>-Option (here -o snapcast):

spotify-connect-web.sh --username <NAME> --password <SECRET> --bitrate 320 --name <CHANNELNAME> -o snapcast
ncsufan8628 commented 8 months ago

just wanted to say thank you for the great instructions. This worked perfectly implementing plexamp-headless via docker and allowing me to direct its audio output to a snapcast pipe.