Saiyato / volumio-snapcast-plugin

Volumio 2 SnapCast plugin, to easily manage SnapCast functionality
115 stars 25 forks source link

Spotify Sample Rate not working correctly #23

Closed andrewj15 closed 7 years ago

andrewj15 commented 7 years ago

Hi, Im having an issue where the music is playing too fast and at a high pitch via spotify. I have the sample rate set in the Spotify integration settings to 44100khz and the SnapServer setttings set at 48000khz.

If i change the snapserver settings to 41000khz as well as the Spotify Integration settings at 41000khz then Spotify plays correctly at the right speed and pitch. However by doing this when playing local files or web radio it causes frequent dropouts and and plays at the wrong speed and pitch and is unlistenable.

Likewise if I set both Spotify Integration settings and Snapserver sample rates to 48000khz Spotify plays to fast and at the wrong pitch.

I'm using RPI3 for both client and server. I have the Snapcast Release from 24th September, volspotconnect2 v0.46 28th September release and Volumio 2.282

I had the same issue when using volspotconnect2 v0.40, Snapcast release 13th September and Volumio 2.246

Any help would be appreciated

Saiyato commented 7 years ago

Hi Andrew,

The topic states that the sample rate isn't working correctly, I'm pretty sure that isn't the case, but if so, it's not something I can change. I merely provide the means to use snapcast easily from within Volumio.

The volspotconnect2 plugin uses librespot and that library doesn't allow for resampling: https://github.com/plietar/librespot/blob/master/src/main.rs

The volspotconnect plugin uses spotify connect web, also unable to resample.

Meaning the resampling is done by the SnapServer component either after reading the fifo in the case of volspotconnect and spop, or on the fly when using a stand-alone librespot library. The sample rate is dependant on what Spotify is sending, I've never had to fiddle with the sampling rate for Spotify. The default sample rate for snapcast is 48000Hz @ 16 bit, so setting it to that value disables resampling by the SnapServer component.

I've also experienced drop-outs when my MPD is forced @ 44100Hz, what have you set MPD to? If you change MPD to 48000Hz, does that solve your problems?

andrewj15 commented 7 years ago

Hi,

I have the MPD sample rate set to 48000khz and it's the same issue. The only way I can get spotify to play correctly is by setting the snapserver sample rate to 41000khz. But then the drop outs occur on local files and Web radio.

What is the reason for having the spotify sample rate in the plugin if the sample rate is defined by spotify?

Saiyato commented 7 years ago

Because that's not true for the stand-alone library and it applies to the stream rather than Spotify itself.

andrewj15 commented 7 years ago

Thanks for the clarification.

I did see there was a precious bug about a similar issue that has been fixed

https://github.com/Saiyato/volumio-snapcast-plugin/issues/15

I don't know if it is related but the user seemed to be experiencing similar issues to what I am currently facing.

Saiyato commented 7 years ago

Can you post your config please?

My config is:

volumio@volumioamp:~$ cat /etc/default/snapserver
# defaults file for snapserver

# start snapserver automatically?
START_SNAPSERVER=true

# Allowed options:
#   -h, --help                          Produce help message
#   -v, --version                       Show version number
#   -p, --port arg (=1704)              Server port
#   --controlPort arg (=1705)           Remote control port
#   -s, --stream arg (=pipe:///tmp/snapfifo?name=default)
#                                       URI of the PCM input stream.
#                                       Format: TYPE://host/path?name=NAME
#                                       [&codec=CODEC]
#                                       [&sampleformat=SAMPLEFORMAT]
#   --sampleformat arg (=48000:16:2)    Default sample format
#   -c, --codec arg (=flac)             Default transport codec
#                                       (flac|ogg|pcm)[:options]
#                                       Type codec:? to get codec specific options
#   --streamBuffer arg (=20)            Default stream read buffer [ms]
#   -b, --buffer arg (=1000)            Buffer [ms]
#   -d, --daemon [=arg(=0)]             Daemonize
#                                       optional process priority [-20..19]
#   --user arg                          the user[:group] to run snapserver as when daemonized

USER_OPTS="--user snapserver:snapserver"

SNAPSERVER_OPTS="-d -s pipe:///tmp/snapfifo?name=VOLUMIO-MPD&mode=read&sampleformat=44100:16:2"

And the volspotconnect2 config:

volumio@volumioamp:~$ cat /data/plugins/music_service/volspotconnect2/startconnect.sh
#this file is generated by the plugin. You should not edit it unless you know what you do. It will be overwrite by the plugin each time a change in config is detected
cd /data/plugins/music_service/volspotconnect2
./librespot -b 320  -c /tmp  --disable-discovery -u {EMAIL} -p {PASSWORD} --name 'Volumioamp' --backend pipe --device /tmp/snapfifo
# --onstart ./onstart1.sh

I'm using a Hifiberry Amp and it doesn't matter if I edit the main pipe to 48000Hz, only MPD causes drop outs @ 44100Hz in my setup. So we're either missing something here or your setup differs in some other way completely. Are you using any other plugins maybe?

andrewj15 commented 7 years ago

Here is my config

volumio@kitchen:~$ cat /etc/default/snapserver   
# defaults file for snapserver

# start snapserver automatically?
START_SNAPSERVER=true

# Allowed options:
#   -h, --help                          Produce help message
#   -v, --version                       Show version number
#   -p, --port arg (=1704)              Server port
#   --controlPort arg (=1705)           Remote control port
#   -s, --stream arg (=pipe:///tmp/snapfifo?name=default)
#                                       URI of the PCM input stream.
#                                       Format: TYPE://host/path?name=NAME
#                                       [&codec=CODEC]
#                                       [&sampleformat=SAMPLEFORMAT]
#   --sampleformat arg (=48000:16:2)    Default sample format
#   -c, --codec arg (=flac)             Default transport codec
#                                       (flac|ogg|pcm)[:options]
#                                       Type codec:? to get codec specific options
#   --streamBuffer arg (=20)            Default stream read buffer [ms]
#   -b, --buffer arg (=1000)            Buffer [ms]
#   -d, --daemon [=arg(=0)]             Daemonize
#                                       optional process priority [-20..19]
#   --user arg                          the user[:group] to run snapserver as when daemonized

USER_OPTS="--user snapserver:snapserver"

SNAPSERVER_OPTS="-d -s pipe:///tmp/snapfifo?name=VOLUMIO-MPD&mode=read"

Here is the volspotconnect config

volumio@kitchen:~$ cat /data/plugins/music_service/volspotconnect2/startconnect.sh
#this file is generated by the plugin. You should not edit it unless you know what you do. It will be overwrite by the plugin each time a change in config is detected
cd /data/plugins/music_service/volspotconnect2
./librespot -b 320  -c /tmp  --name 'kitchen' --backend pipe --device /tmp/snapfifo
andrewj15 commented 7 years ago

I have the following plugins installed

Spotify (one included with Volumio Plugins in Web UI) Volspotconnect2 Snapcast Backup and Restore

Saiyato commented 7 years ago

Ok those plugins shouldn't interfere.

Your config is 48000Hz for snapserver and as mentioned native for Spotify. If you change your MPD config to 48000Hz as opposed to 44100 you should be fine.

Just to get things clear, because the story confuses me:

SnapServer @ 48kHz + Spotify = high pitching noise SnapServer @ 44.1kHz + Spotify = working

SnapServer @ 48kHz + MPD @ 48kHz = ? SnapServer @ 44.1kHz + MPD @ 44.1Hz = ? SnapServer @ 48kHz + MPD @ 44.1kHz = ? SnapServer @ 44.1kHz + MPD @ 48kHz = ?

For clarity; the Spotify integration settings apply to:

  1. A stand-alone librespot library
  2. A dedicated Spotify stream; resampling is done by SnapServer

The SnapServer settings will determine the SnapServer main stream resampling options.

The MPD settings will determine the MPD resampling prior to sending it to SnapServer.

andrewj15 commented 7 years ago

SnapServer @ 48kHz + MPD @ 48kHz = Spotify high pitch and plays too fast SnapServer @ 44.1kHz + MPD @ 44.1Hz = So far, this is looking like it is playing correctly on both local / web radio and spotify!! SnapServer @ 48kHz + MPD @ 44.1kHz = Local and web radio dropouts occur, spotify plays too fast and high pitch SnapServer @ 44.1kHz + MPD @ 48kHz = Spotify Works correctly, dropouts on local files and web radio

Previously I had been altering the Spotify sample rate as well as the Snapcast Server sample rate. I hadn't changed the MPD sample rate until you mentioned it today. I think the 44.1kHz setting on both MPD and Snapserver, for both the client and server is what i need for my configuration. I will keep testing but the local files / web radio but so far so good without dropouts!

yayabobo commented 7 years ago

I can confirm SnapServer @ 44.1kHz + MPD @ 44.1Hz works perfectly... strange, but it works :)

Thanks!

Saiyato commented 7 years ago

This is probably because MPD natively plays @ 44.1kHz for your files; so any other settings than 44.1kHz will cause resampling to be done. I think the rPi isn't really made for intensive resampling.

So the combo of both MPD and snapserver on the same page is most beneficial for the microprocessor. In which case (for MPD at least) 44.1kHz or 48kHz should be fine.

The dropouts should not occur on a more powerful machine, but I'm not having the luxury of time to test that right now ;)