gimesketvirtadieni / slimstreamer

SlimStreamer is an audio streaming software for Linux with multi-room functionality. SlimStreamer captures audio playback from ALSA and broadcasts it to connected Squeezebox devices (real or ‘virtual’ like squeezelite).
The Unlicense
63 stars 5 forks source link

Audio lag with Mopidy #5

Open dhtek opened 6 years ago

dhtek commented 6 years ago

Hello,

First of all, thanks for your job ! It's really great what are you doing...

By the way, I got an lag when I listen to music from mopidy (tunein, soundcloud, and local media) but if I listen to using the library mpg123, it's working well !

I suppose that the problem comes the interaction between Mopidy and SlimStreamer. In the configuration of Mopidy, I redirect output audio to alsa and install alsamixer as well and changed the buffer_time to high value but still lagging; sound disappears during a few milliseconds or seconds, sound comes back.

Raspberry Pi 2, Mopidy 2.10

Mopidy configuration:

[audio] output = alsasink mixer_volume = 85 mixer = alsamixer buffer_time = 100000

[alsamixer] control = PCM min_volume = 0 max_volume = 100 volume_scale = cubic

Thanks for your help.

gimesketvirtadieni commented 6 years ago

Hi Thanks for your feedback; it's great to see people find my work relevant :) Definitely I will try to help you out... First, I suggest to rule out latency caused by using source from the Internet. Could you confirm that playing local music is causing a similar lag? One more curious thing is that you are using alsamixer plugin in your PCM path (BTW alsamixer plugin spoils bit-perfect playback). Could you post your ALSA asound.conf file? P.S. Apart from this lag, does SlimStreamer work as expected for you?

dhtek commented 6 years ago

Yes local music is causing a similar lag.

About alsamixer, I don't know if I had to install it and used it.

Also, I remember when I compiled SlimPlexor with my raspbery PI 2, I got some warning.

image

Yes I have another problem, but I'll create another one ticket when this one will be resolved. It's about synchronisation problem between my squeezelite on my raspberry and another one on windows after the second song is started (songs are out of sync).

Thanks

gimesketvirtadieni commented 6 years ago

Thanks for the details. I will setup Mopidy and get back to you. Playback synchronization 'works' only by 'accident' ;) I am still working on sync functionality so it is not an error. Coordinated playback start is almost finished and 'drift' correction is work in progress ;)

dhtek commented 6 years ago

Cool, thanks !

gimesketvirtadieni commented 6 years ago

Hi I am still experimenting with Mopidy (trying to reproduce your issue)... When I use your provided Mopidy config details, I am getting following error in Mopidy log file (default location is /var/log/mopidy/mopidy.log):

pi@raspberrypi:/etc/mopidy $ more /var/log/mopidy/mopidy.log 
2018-08-21 19:02:09,937 INFO [7027:MainThread] mopidy.__main__: Starting Mopidy 2.1.0
2018-08-21 19:02:11,252 INFO [7027:MainThread] mopidy.config: Loading config from builtin defaults
2018-08-21 19:02:11,312 INFO [7027:MainThread] mopidy.config: Loading config from /etc/mopidy/mopidy.conf
2018-08-21 19:02:11,352 INFO [7027:MainThread] mopidy.config: Loading config from command line options
2018-08-21 19:02:12,045 INFO [7027:MainThread] mopidy.__main__: Enabled extensions: mpd, http, stream, m3u, softwaremixer, file, local
2018-08-21 19:02:12,053 INFO [7027:MainThread] mopidy.__main__: Disabled extensions: none
2018-08-21 19:02:14,863 ERROR [7027:MainThread] mopidy.commands: Did not find unique mixer "alsamixer". Alternatives are: software, none

Could you past your mopidy log entries when you start mopidy service? I will play with various mixer options to check if it is related to this issue...

Thanks in advance for the details ;)

dhtek commented 6 years ago

I installed the following plugin https://github.com/mopidy/mopidy-alsamixer

Otherwise with software mixer, I have also the bug.

I forgot to tell you :

gimesketvirtadieni commented 6 years ago

Hi I was playing with various scenarios to reproduce the lag you have mentioned. Definitely delay is present, however it is ~1 sec. which is more-or-less expected. The thing is, before sending PCM data over the network, it has to be buffered on both ends to compensate network variable latency (think of these buffers as about shock absorbers used in cars). However I did experienced sound shuttering and in some cases playback did not restore. It was mostly when I played MP3's. So there is more to explore for me and work on reliability. Could you try playing any FLAC or WAV and check if you experience the same lag? Also I wonder how long the lag is in your case (subjectively)? Is it around 1 sec or more? Thanks in advance ;)

dhtek commented 6 years ago

Hi, Sorry for the delay... I try with a flac, it's better but it's not perfect. I uploaded on wetransfer a record when I was playing mp3 with mopidy https://we.tl/t-IzB1DfNgdT

gimesketvirtadieni commented 6 years ago

Hello dhtek

I am sorry, did not have enough time to work on this issue as much I would like for a good reason - I got a son!!!. However I was able to reproduce this problem on my environment. The thing is a host running SlimPlexor and SlimStreamer is not just serving audio stream, but also transcoding its content. It works like this:

  1. Arbitrary app that plays music decode MP3, FLAC, ... or any other format to raw PCM and submit to ALSA (ALSA does not understand anything else but raw PCM)
  2. SlimPlexor captures that stream and delivers it to SlimStreamer
  3. SlimStreamer encodes raw PCM stream to FLAC (configurable via command line options) and sends to all slim clients.

Long story short, a host running SlimPlexor and SlimStreamer has to have enough capacity. Could you provide details about capacity you are using? I do work on optimizing SlimStreamer internals, which will decrease required capacity and it will be part of the next version, so stay tuned ;)