Skip to content
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

FR: snapclient as a source (output raw samples to stdout/pipe) #681

Closed
zopieux opened this issue Sep 1, 2020 · 7 comments
Closed

FR: snapclient as a source (output raw samples to stdout/pipe) #681

zopieux opened this issue Sep 1, 2020 · 7 comments
Labels
feature request next release fixed in develop branch and will be part of the next release

Comments

@zopieux
Copy link
Contributor

zopieux commented Sep 1, 2020

Hello,

I've just learned about Snapcast, and this project is already running on my home server, phones & computers. This works just fine, thanks for developing this.

Here is a feature request: I need to read the audio stream, as snapclient would do, but then output the raw samples to stdout (instead of a sound card) so I can pipe it to another audio processing pipeline (say ffmpeg), with the end-goal of streaming to devices not supported by Snapcast today. One example that comes to mind is

snapserver → snapclient "raw mode" → ffmpeg/gstreamer with hls sink → <any HLS-enabled device>

As you can see, the missing element is snapclient "raw mode", a snapclient that would output S16LE samples directly to stdout so I could pipe them. Could this be added to snapclient as one of the (currently undocumented) --player? I've seen file_player.cpp but couldn't get it to output samples that ffmpeg could read (distorted audio).

@badaix
Copy link
Owner

badaix commented Sep 1, 2020

It should work to write the buffer_.data() to stdout (this is undocumented, because it's not finished, PRs are welcome ;)). Maybe the distortion comes from logging (going to stdout by default). You can use a different log sink with --logsink, e.g. null or stderr.
Or you play the audio into an alsa loopback device, and record the looped audio in gstreamer (the idea is described here: https://github.com/badaix/snapcast/blob/master/doc/configuration.md#alsa)

@zopieux
Copy link
Contributor Author

zopieux commented Sep 1, 2020

Thanks for the quick reply. I did exactly what you mentioned, aka. output data() to stdout & remove stdout clutter (I didn't bother with --logsink, I just hacked the code) and piping to ffplay -f u16le -ar 44100 -ac 2 (also tried signed & big-endian). I tried with and without calling adjustVolume. Sadly all my attempts resulted in basically noise garbage.

@badaix, I'd be happy to contribute a PR, but may I suggest you give it a try too and share the changes & format flags you used for playback, because at this point I'm not sure what to try next for this to work. Thanks for your help.

@badaix
Copy link
Owner

badaix commented Sep 1, 2020

I've added this line fwrite(buffer_.data(), 1, needed, stdout); to master dcd8ddb
When I pipe the output to aplay, I can hear cristal clear audio:

snapclient -h 192.168.0.3 --logsink null --player file |aplay -f dat

@zopieux
Copy link
Contributor Author

zopieux commented Sep 1, 2020

Amazing thanks! Not sure what I did wrong, but ffplay -f s16le -ac 2 -ar 44100 - works flawlessly now. I guess --player file covers my FR for now. This could use some documentation though.

@zopieux zopieux closed this as completed Sep 1, 2020
@badaix badaix added the next release fixed in develop branch and will be part of the next release label Oct 5, 2020
@badaix badaix reopened this Oct 5, 2020
@badaix badaix closed this as completed Oct 15, 2020
@daniel-j
Copy link

I just tried it and I get bad stdout data from snapclient, compared to using a file or fifo. Snapclient prints PCM device "default" not found before the actual PCM data.
This line is the issue:

cout << "PCM device \"" << pcm_device << "\" not found\n";

Tested with snapclient --logsink stderr --player file > file.raw
I tried using -s null but still got the extra output.
A quick workaround I found was to pipe it through tail -n +2, which skips the first line of output.

@badaix badaix reopened this Mar 19, 2021
@badaix
Copy link
Owner

badaix commented Apr 30, 2021

Fixed with commit c88b2d1

@zopieux
Copy link
Contributor Author

zopieux commented Apr 30, 2021

Thanks, that cout gone lgtm. For your information @daniel-j.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request next release fixed in develop branch and will be part of the next release
Projects
None yet
Development

No branches or pull requests

3 participants