-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapclient sounds like /dev/urandom just got piped into my speaker #1170
Comments
I think the audio output from librespot is taken from stdout and it seems that librespot outputs other data as well to stdout, like a log line, which would cause exactly what you have. |
Sounds good. Is there any way to change librespot to output to a Pipe instead of STDOUT? And if so, does this mean that I need to find a Librespot container that does so? Or is there any other way I should go about fixing this |
Are you running the latest version of librespot. If so, this sounds like a bug to be fixed in librespot and should be reported to them. |
Yeah, I think 0.4.1 from my modified image, but that also seems to be the default version in the image from djmaze. I'll gather more info later, on the road for another few hours |
Don't know if this will work, but you could try to start librespot in a terminal with the |
The headline of this issue describes the problem of my snapcast installation at it's best. The attached file shows such an event. While playing music the state changes from 'playing' to 'idle' (timestamp: Oct 31 13:48:49) and back to 'playing' again (timestamp: Oct 31 13:48:50). After changing back to state 'playing' just noise is played until stopping the playing (timestamp: Oct 31 13:49:05). I'm now using the newest version of snapcast (0.27.0 - debian bookworm testing). But this problem has happened since using 0.24.0). |
Great, then you are on the same page as everyone else. We are saying the problem might be back on the snapserver, in librespot's |
You can modify the code in snapcast where librespot is launched and use
|
Hi, If I can help : I'm also facing this issue.
Very annoying and scary because
It's quite easy to reproduce, I just have to play spotify (spotify -> librespot -> snapserver -> snapclient -> etc), When this occurs, I can see the two log lines :
This stops when I manually PAUSE the track with spotify, then RUN it again. As suggested, I tried to change the librespot backend to pipe (¶ms=--backend%20pipe), and I still see the bug occur. I also ran librespot alone with backend to pipe, not revelant since librespot detects that there is not audio sink then stops. |
My suggestion involved more than that. Your change doesn't do anything. |
Yes that's something I understood after I posted ;-) |
I don't understand. There's still nothing in your post where you did what I suggested. Running librespot standalone is a good idea. Pipe the audio to VLC, or something, and try to reproduce with your recipe. Do you have to do it exactly 10 times. Or did you mean 'up to 10 times'? What if you let two tracks play through and then switch between the same two tracks many times I.e. does it have to be different tracks to cause the problem? |
I did the test you proposed (btw not easy to find the good vlc option set to read from stdout at correct rate) librespot -n "Librespot Speaker" --backend pipe | tee /tmp/file | cvlc -vvv --novideo -A alsa --demux=rawaud - I did not see any issue after I ran and ran again my recipe. Sees there is nothing STDOUTed from librespot except the audio. Could a log be emited by snapserver ?
I meant 'up to 10' yes, sometimes the first jump in one and only one track is enough to produce the bug. I'm quite sure it does not depend on what track is currenty played, or how many tracks have been played before. |
I'm not sure if it's the same problem. But I also had these problems from time to time. What helped me was the following patch. Never had any problems since then:
|
It's a patch regarding librespot, I guess. I think reducing the loglevel in the snapserver call to librespot or deactivating the logging of librespot can achieve the same ... |
Since the problem mentioned in the title occures to often, I changed my setup. Snapclient and snapserver were running on the same raspberry pi (3). At the same time a kodi was running on the pi. The pi was connected to the network via WiFi. A few days after my post above I changed the setup. I choose a dedicated pi4 as home for the snapserver, connected to the network over LAN. On the via WiFi connected pi only the snapclient is startetd. But beside the snapclient kodi is still running. |
Yes, librespot has a "quiet" logging mode switch, although I don't know if that then breaks the metadata support. Librespot is configured to log everything to stderr so it seems unlikely that changing the logging verbosity would help but worth a try. |
Thanks @rage2dev, however since guys at librespot confirmed (as well as a test I did) that nothing is emited on STDOUT, I doubt that adjusting the loglevel would fix my point. @schniefus, interesting point you mention : the bug could be related to network performances. |
The title is pure gold. I have been living with these random blasts of sound for quite some time. They don't occur as often since I usually play background music, but the issue seems to occur sometimes when I play media, skip to the next track or just move through the current track, though as I said, it doesn't happen every time. I have 3 snapclients (2x rpi wireless, 1x desktop wired) Did anyone else try custom compiling librespot with the trace->info change? Is that the only lead for now? |
Where I was going with this, is to try and determine if is's related to snapcast trying to use data that librespot hasn't provided yet (because it's still loading it). Normally librespot caches audio data, so the idea was if you let a few songs play through normally you could be sure all the data is cached and readily available. Then do your recipe of skipping between only those same few tracks and/or skipping within those tracks and see if you can trigger the issue. My guess is you won't be able to. |
I started to dig the code and TRACE logs. snapserver detects an actual librespot pause when this latter stops emitting samples on it's stdout. I think that when librespot goes back to running and starts emiting samples again, something weird happens somewhere in the AsioStream class that make it play garbage. note: A better connection could avoid librespot going to pause, thus hide the issue. |
Same issue. It seems to hit me on the first track after the system has been idle for an extended period of time like overnight. Environment details
|
This same problem has been showing up with varying frequency on both of my setups (for quite some time, with different versions of snapcast and librespot). I modified snapcast to also tee the stdout from librespot to a file. Importing this file into Audacity shows no problems with the stream after this bug has been triggered. While this noise is playing it's possible to reduce the volume in Spotify/librespot to around 10%, and the music comes back. Looking at the raw audio file with a hex editor shows that this volume level corresponds to one byte being 00/FF for all (16-bit) samples, while the full range is roughly utilised of the other byte. So I guess this suggests that the problem is with the byte order getting mixed up somehow. Adding more debug logging to posix_stream.cpp, I noticed that there often are an uneven number of bytes read so far for the current chunk when librespot stops emitting data (for whatever reason – but mostly after skips/seeks with cache disabled). And this is when the problem occurs. If I add this line to the top of the code block handling the no data from read() case the problem appears to get a lot more difficult to reproduce: If I'm onto something here, similar adjustment might also be needed when resuming from playing silence. (And 4 would maybe be a more correct number if we also have a bug where the stereo channels gets swapped.) |
After applying this patch to librespot I have not been able to reproduce this bug. It appears that Stdout in Rust's std::io is line buffered internally, even if stdout itself is set to be unbuffered or fully-buffered. This is obviously not great in our use case, as it at a minimum introduces unnecessary latency and jitter. I don't know how librespot behaves if asked to use a named pipe instead of outputting to stdout. If it avoids this buffering I guess it can be an option to update snapcast to use pipes instead, to get around this problem also for unpatched versions of librespot. Snapcast should maybe also be updated to better handle cases where "silence is detected" when the stream is in the middle of a sample, if for no other reason than as a defensive programming measure. Although I'm not sure what would be the best way to go about doing this. |
It now reappeared when librespot must have ran out of data in the middle of a song (?). Still haven't been able to trigger it from skips and seeks. |
So unfortunate but I have the same problem. |
Confirming this patch has worked for me to stop random noise on track skip |
Oddly, ever since this issue was opened, I haven't had this occur more than 2-3 times. Whereas it happened regularly during 2023. On the other hand, completely irrelevant to the topic, I wish we just had a decent replacement for Spotify. |
Can you please submit a PR to librespot? I can't think of an application where line buffered output is useful so seems reasonable to fix what appears to be a bug. |
Yes, I will take a look at it and submit a PR. I assume this isn't a problem when librespot is told to output to a named pipe instead of stdout, but that this write_bytes function is used for both. This new flush call would be redundant in that case, so a little more code might be needed to keep things performant. I guess snapserver could be made more robust by managing a byte counter for the received stream, and then discard 1-3 bytes if the stream isn't aligned on a sample boundary when starting a new chunk. Is this something that could be wanted? Should I try to write some code also for this, test it and submit a PR? The latest release of librespot (v0.4.2) was released one and a half years ago. I don't know how far away v0.5.0 is, but I suspect there will still be some time before a release is made where this bug has been patched. |
Any updates? |
Guys, Does someone know why the The code in To answer myself my above question, I just removed this method -> Works like a charm !! And I'm not able to reproduce the bug |
@cdtx Interesting finding! |
My memories are slowly coming back: the |
WoW, glad to read this ! |
This worked for me also. I have been having the problem for a few months. Tried reverting to a older setup I had and it did not fix the problem. It is definitely on the Spotify side. I did this, and now I have snapcast back! I am not sure if this is the best way to do it, but it works.
|
is this fix going to be implemented? having this issue and do not have the knowledge to build/compile from scratch |
I have a fix available which I haven't pushed yet. Will push it very soon and build Debian packages. |
thanks! Glad something is ready, was super shocked when i went to play something today and thought the antichrist was coming out of my speakers. |
The branch is here: Debian packages of the v0.28.0-beta.1 are here: I didn't test the packages yet, just a locally compiled binary. This is a draft of the changelog: Version 0.28.0-beta.1Features
Bugfixes
General
|
running in docker here. Anyone successfully built for Alpine? |
I've got a Dockerfile that builds for Alpine: https://github.com/mill1000/docker-snapcast-server/blob/main/Dockerfile |
I used @mill1000's dockerfile to compile the debug branch and so far it seems to work! I had a very severe case of /dev/random-disco going on that would start right away and switching to this newly-built image, none of this has happened for an hour or so so far. |
Thank you so much badaix! Version 0.28.0-beta.1 lowered the CPU usage compared to the fix I did with the rough removal of PosixStream do_read(). Huge positive with my rhasspy/snapcast satellites. |
any chance you can share your snapserver apk? I tried to get this working via docker on unraid and was having sha issues on the snapcast.patch step of the build |
That patch is a hack for #891. You can remove it if it gives you grief. |
now I get stuck here: `CMake Warning: ".." CMake Error: The source directory "/snapcast" does not appear to contain CMakeLists.txt. EDIT: Got this working by building directly using the github URL instead of cloning the repo and building from there. |
If you're talking about my repo its probably because it has submodules and they need to be initialized.
|
Fixed in version 0.28.0 |
Great that it's fixed. I am wondering what will happen now instead of the random noise? Would there be something like a silence, or does it playback like usual? |
Describe the bug
On occasion, all Snapclients's FIFO pipe breaks and it sounds like static at max volume.
Steps to Reproduce
Environment details
docker compose plugin
, BOTH snapclient and snapserver dockerfiles were updated and built with Snapcast 0.27.0, unlike what djmaze' repo reflectslog from Snapserver:
log from a snapclient:
The text was updated successfully, but these errors were encountered: