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

Mopidy HiRes Audio #592

Closed
lealoureiro opened this issue Apr 21, 2020 · 18 comments
Closed

Mopidy HiRes Audio #592

lealoureiro opened this issue Apr 21, 2020 · 18 comments

Comments

@lealoureiro
Copy link

Hello,

I'm having an issue trying to connect Mopidy Server + Snapcast with HiRes audio 96Khz/24Bit

Mopidy Configuration:
[audio]
mixer = software
mixer_volume = 100
output = audioconvert ! audio/x-raw,rate=96000,channels=2,format=S24LE ! wavenc ! filesink location=/data/mopidy/fifo/snapfifo

Snapserver Configuration:
stream = pipe:///data/mopidy/fifo/snapfifo?name=MopidyPlayer&sampleformat:96000:24:2
codec = pcm

With this I'm listen sound very wrong like radio cannot catch anything.

Thanks,
Leandro

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

try with sampleformat=96000:24:2:
stream = pipe:///data/mopidy/fifo/snapfifo?name=MopidyPlayer&sampleformat=96000:24:2

@lealoureiro
Copy link
Author

same issue :(

But I'm able to play HiRes Audio directly on device where snapclient is installed:

play Sample_BeeMoved_96kHz24bit.flac:
play WARN alsa: can't encode 0-bit Unknown or not applicable

Sample_BeeMoved_96kHz24bit.flac:

File Size: 16.7M Bit Rate: 3.34M
Encoding: FLAC
Channels: 2 @ 24-bit
Samplerate: 96000Hz Album: Bee Moved
Replaygain: off Artist: Blue Monday FM
Duration: 00:00:39.88 Title: Bee Moved

In:25.7% 00:00:10.24 [00:00:29.64] Out:983k [!=====|=====!] Hd:0.0 Clip:0

cat /proc/asound/card0/pcm0p/sub0/hw_params:
access: RW_INTERLEAVED
format: S24_LE
subformat: STD
channels: 2
rate: 96000 (96000/1)
period_size: 1024
buffer_size: 8192

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

can you paste the client log?

@lealoureiro
Copy link
Author

-- Logs begin at Thu 2020-04-16 12:22:38 BST. --
Apr 21 11:16:11 music-player snapclient[10280]: Connected to 192.168.178.2
Apr 21 11:17:19 music-player snapclient[10280]: Received signal 15: Terminated
Apr 21 11:17:19 music-player snapclient[10280]: Stopping controller
Apr 21 11:17:19 music-player systemd[1]: Stopping Snapcast client...
Apr 21 11:17:19 music-player snapclient[10280]: Exception in Controller::worker(): Invalid argument
Apr 21 11:17:19 music-player snapclient[10280]: daemon terminated.
Apr 21 11:17:19 music-player systemd[1]: snapclient.service: Succeeded.
Apr 21 11:17:19 music-player systemd[1]: Stopped Snapcast client.
Apr 21 11:23:27 music-player systemd[1]: Started Snapcast client.
Apr 21 11:23:27 music-player snapclient[10368]: Connected to 192.168.178.2
Apr 21 11:25:43 music-player snapclient[10368]: Exception in Controller::worker(): read_some: End of file
Apr 21 11:25:44 music-player snapclient[10368]: Connected to 192.168.178.2

I guess does not say too much... Only is re-connecting to the server when i restart with new configuration. Maybe i can increase verbosity? Does client need special configuration?

Anyway, not sure if having stream over 96Khz is the best solution, because most of flac files are 44.1Khz, i guess re-sampling might lose some quality, even if for higher.

But on other hand i believe YotuTube and Soundclound are 48Khz... So not sure what would be the best

@lealoureiro
Copy link
Author

Also tried 44100:24:2 (S24LE) also the sound is wrong, seems to be related with 24bit...

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

I need a log from the startup. You can start snapclient on command line.
Regarding hi-res audio: 96kHz 24bit is good for mastering and for marketing, but no one will be able to notice a difference to 48kHz 16bit. If the source signal is upsampled, it will lower the quality and waste bandwidth.
Did you restart the server after the config changes?

@lealoureiro
Copy link
Author

mopidy.conf:

[audio]
mixer = software
mixer_volume = 100
output = audioconvert ! audio/x-raw,rate=96000,channels=2,format=S24LE ! wavenc ! filesink location=/data/mopidy/fifo/snapfifo

snapserver.conf:
stream = pipe:///data/mopidy/fifo/snapfifo?name=MopidyPlayer&sampleformat=96000:24:2

snapclient -h 192.168.178.2:

2020-04-21 12-56-44 [Info] (main) Latency: 0
2020-04-21 12-56-44 [Notice] (start) Connected to 192.168.178.2
2020-04-21 12-56-44 [Info] (getMacAddress) My MAC: "b8:27:eb:43:cb:9f", socket: 6
2020-04-21 12-56-45 [Info] (onMessageReceived) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0
metadata:{"STREAM":"MopidyPlayer"}
2020-04-21 12-56-45 [Info] (onMessageReceived) Codec: pcm
2020-04-21 12-56-45 [Notice] (state) sampleformat: 96000:24:2
2020-04-21 12-56-45 [Info] (Alsa) frames: 2880
2020-04-21 12-56-45 [Info] (Alsa) Resizing buffer from 0 to 92160
2020-04-21 12-56-45 [Info] (Stream) no chunks available
2020-04-21 12-56-45 [Info] (Alsa) Failed to get chunk
2020-04-21 12-56-45 [Info] (worker) diff to server [ms]: 2.60881e+09
2020-04-21 12-56-50 [Notice] (Alsa) No chunk received for 5000ms. Closing ALSA.
2020-04-21 12-56-59 [Info] (Alsa) frames: 2880
2020-04-21 12-57-00 [Info] (Stream) Chunk: 0	0	0	0	1	60	0
2020-04-21 12-57-01 [Info] (Stream) Chunk: 0	0	0	0	11	60	0
2020-04-21 12-57-02 [Info] (Stream) Chunk: 0	0	0	0	28	60	0
2020-04-21 12-57-03 [Info] (Stream) Chunk: 0	0	0	0	45	60	0
2020-04-21 12-57-04 [Info] (Stream) Chunk: 0	0	0	0	61	60	0
2020-04-21 12-57-05 [Info] (Stream) Chunk: 0	0	0	0	78	60	0
2020-04-21 12-57-06 [Info] (Stream) Chunk: 0	0	0	0	95	60	0
2020-04-21 12-57-07 [Info] (Stream) Chunk: 0	0	0	0	111	60	0
2020-04-21 12-57-08 [Info] (Stream) Chunk: 0	0	0	0	128	60	0
2020-04-21 12-57-09 [Info] (Stream) Chunk: 0	0	0	0	145	60	0
2020-04-21 12-57-10 [Info] (Stream) Chunk: 0	0	0	0	161	60	0
2020-04-21 12-57-11 [Info] (Stream) Chunk: 0	0	0	0	178	60	0
^C2020-04-21 12-57-11 [Info] (operator()) Received signal 2: Interrupt
2020-04-21 12-57-11 [Info] (operator()) Stopping controller
2020-04-21 12-57-11 [Error] (worker) Exception in Controller::worker(): Invalid argument
2020-04-21 12-57-11 [Error] (onException) Controller::onException
2020-04-21 12-57-11 [Error] (stop) Error in socket shutdown: Bad file descriptor
2020-04-21 12-57-11 [Notice] (main) daemon terminated.

@lealoureiro
Copy link
Author

I've changed the mopidy.conf to:
output = audioconvert ! audioresample ! audio/x-raw,rate=96000,channels=2,format=S24LE ! wavenc ! filesink location=/data/mopidy/fifo/snapfifo

And now i can hear a bit of original music in the middle of loud noise. The source of the sound is a flac file 44.1Khz 16bit

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

Mine looks like this:

/etc/mpd.conf:

audio_output {
    type            "fifo"
    name            "my pipe"
    path            "/tmp/snapfifo"
    format          "96000:24:2"
    mixer_type      "software"
}

snapserver.conf:

[stream]
stream = pipe:///tmp/snapfifo?name=default&sampleformat=96000:24:2

client log:

2020-04-21 14-03-41.625 [Info] (main) Latency: 0
2020-04-21 14-03-41.626 [Notice] (start) Connected to 192.168.0.31
2020-04-21 14-03-41.626 [Info] (getMacAddress) My MAC: "00:21:6a:7d:74:fc", socket: 6
2020-04-21 14-03-41.713 [Info] (onMessageReceived) ServerSettings - buffer: 1000, latency: 10, volume: 68, muted: 0
metadata:{"STREAM":"default"}
2020-04-21 14-03-41.714 [Info] (onMessageReceived) Codec: flac
2020-04-21 14-03-41.714 [Notice] (state) sampleformat: 96000:24:2
2020-04-21 14-03-41.730 [Info] (Alsa) frames: 2880
2020-04-21 14-03-41.736 [Info] (Alsa) Resizing buffer from 0 to 92160
2020-04-21 14-03-41.755 [Info] (worker) diff to server [ms]: 0.013
2020-04-21 14-03-42.595 [Debug] (Stats) Chunk: 0	0	0	0	1	115	0
2020-04-21 14-03-43.021 [Debug] (Stats) Chunk: -5	-2	-2	-2	13	115	0
2020-04-21 14-03-44.012 [Debug] (Stats) Chunk: -11	-10	-8	-8	41	114	0
2020-04-21 14-03-45.037 [Debug] (Stats) Chunk: -14	-11	-10	-10	70	113	0
2020-04-21 14-03-46.027 [Debug] (Stats) Chunk: -14	-14	-11	-11	98	114	0
2020-04-21 14-03-47.019 [Debug] (Stats) Chunk: -8	-10	-11	-11	126	114	42
^C2020-04-21 14-03-47.412 [Info] (operator()) Received signal 2: Interrupt
2020-04-21 14-03-47.412 [Info] (operator()) Stopping controller
2020-04-21 14-03-47.412 [Error] (worker) Exception in Controller::worker(): Invalid argument
2020-04-21 14-03-47.413 [Error] (onException) Controller::onException
2020-04-21 14-03-47.592 [Error] (stop) Error in socket shutdown: Bad file descriptor
2020-04-21 14-03-47.593 [Notice] (main) daemon terminated.

It's working, but as you can see, I'm using mpd and not mopidy.

@lealoureiro
Copy link
Author

yeap I'm seeing

Mopidy uses gstreamer audioconvert which you can specify a lot of formats:

audio/x-raw:
         format: { S8, U8, S16LE, S16BE, U16LE, U16BE, S24_32LE, S24_32BE, U24_32LE, U24_32BE, S32LE, S32BE, U32LE, U32BE, S24LE, S24BE, U24LE, U24BE, S20LE, S20BE, U20LE, U20BE, S18LE, S18BE, U18LE, U18BE, F32LE, F32BE, F64LE, F64BE }
           rate: [ 1, 2147483647 ]
       channels: [ 1, 2147483647 ]
         layout: { (string)interleaved, (string)non-interleaved }

Maybe S24LE is not the correct one...

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

Can you configure gstreamer to directly play the audio to an alsa sink or something?
Also there is an issue mopidy/mopidy#1858 that might be related

@lealoureiro
Copy link
Author

Can you configure gstreamer to directly play the audio to an alsa sink or something?
Also there is an issue mopidy/mopidy#1858 that might be related

I don't dont have mopidy server in raspberry pi where i have the sound card :(

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

try this: S24_32LE
Snapcast is using 32bits for 24 bit as well as for 32 bit

@lealoureiro
Copy link
Author

I have now an exception in Mopidy saying not found in the middle of big stack trace.

Looks like it cant find the format, strange

@lealoureiro
Copy link
Author

i guess wavenc does not support S24_32LE

https://gstreamer.freedesktop.org/documentation/wavenc/index.html?gi-language=python

@badaix
Copy link
Owner

badaix commented Apr 21, 2020

Is wavenc really needed? After audioresample the signal might be PCM already.

@lealoureiro
Copy link
Author

lealoureiro commented Apr 21, 2020

Damm you the hero!!! it works!

Even if is not super important, good to have the knowledge! Thanks a lot!!!

mopidy.conf

[audio]
mixer = software
mixer_volume = 100
output = audioconvert ! audioresample ! audio/x-raw,rate=96000,channels=2,format=S24_32LE ! filesink location=/data/mopidy/fifo/snapfifo

snapserver.conf
stream = pipe:///data/mopidy/fifo/snapfifo?name=MopidyPlayer&sampleformat=96000:24:2

@badaix
Copy link
Owner

badaix commented May 2, 2020

I've removed wavenc from the docs, I hope it's generally not needed once, audio is converted to audio/x-raw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants