Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Reducing delays when moving from one track to another
#1
Being good, I have checked for other posts here and found the settings in Configuration / MPD / Resource allocation..

.. am I right to think that setting the input cache to 128 MB from its default of zero will help minimise gaps when getting a new file? The help line talks about older data being removed if it gets full, but presumably it's smart enough not to get track 2, 3, 4, 5 of a queue and then go 'Oh, I'm full, I will get rid of 2 so I can get 6..' before track 2 is actually played.

Is the cache in RAM (in which case, what's the best way to see how much spare there is?) or on the SD card?
Reply
#2
There is no documentation that explains how the MPD input cache works, there is only the source code. From what Ive seen it's a RAM cache.

You can use moodeutl -m to monitor RAM usage.

Noticeable delays when switching between tracks suggests slow SDCard, network or some other resource bottleneck.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
I get the impression from the MPD documentation (https://mpd.readthedocs.io/en/stable/use...nput-cache) that a primary motivation for the input cache was to overcome delays imposed by slow hard drives.

Quote:The input cache prefetches queued song files before they are going to be played. This has several advantages:
  • risk of buffer underruns during playback is reduced because this decouples playback from disk (or network) I/O
  • bulk transfers may be faster and more energy efficient than loading small chunks on-the-fly
  • by prefetching several songs at a time, the hard disk can spin down for longer periods of time
This comes at a cost:
  • memory usage
  • bulk transfers may reduce the performance of other applications which also want to access the disk (if the kernel’s I/O scheduler isn’t doing its job properly)

I never bothered to read the C++ source code in MPD/src/input/cache in the MusicPlayerDaemon github repo, brrrr.

Regards,
Kent
Reply
#4
It's not a fast network, talking to not a fast disk at the other end...
Reply
#5
You might want to try copying the remote files to a USB stick and using that as local storage on the Pi but I don't know whether that would fit your usage scenario.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
(01-07-2023, 09:45 PM)Tim Curtis Wrote: You might want to try copying the remote files to a USB stick and using that as local storage on the Pi but I don't know whether that would fit your usage scenario.

Alas, genuine 1TB USB sticks aren't cheap - even more than a Pi 4B! Smile - and I'd need several of them.
Reply
#7
In my experience the MPD pre-fetch doesn't actually work. Rather then getting track ahead of playback until the cache is full, it gets tracks as they start to play just the same as normal, but just leaves played ones in the cache until it's full. Almost exactly the opposite of what it needs to do. I confess I've not tried it on the more recent versions of MPD, it was probably a year ago I last looked.
----------------
Robert
Reply
#8
I did a little testing with locally attached USB drive and also remote NAS and it looks like MPD is in fact prefetching into RAM the track following the currently playing track.

Below is a verbose log edited for readability that shows the prefetch actions as tracks are being played. Input cache was set to 1 GB. Note that if Input cache is set to Disabled then no prefetch commands show up in the log.

Code:
# Queue order

LRMonoPhase4.flac
In The Blue Of The Evening.flac
You Got To My Head.flac
Velvet Moon.flac
Come Sunday.flac

pi@moode:~ $ tail -f /var/log/mpd/log

# Start Play: LRMonoPhase4.flac
Jan 09 09:39 : playlist: play         "LRMonoPhase4.flac"
Jan 09 09:39 : playlist: queue song     "In The Blue Of The Evening.flac"
Jan 09 09:39 : cache: Prefetch         "In The Blue Of The Evening.flac"
Jan 09 09:40 : player: played         "LRMonoPhase4.flac"

# Playing: In The Blue Of The Evening.flac
Jan 09 09:40 : playlist: queue song     "You Got To My Head.flac"
Jan 09 09:40 : cache: Prefetch         "You Got To My Head.flac"
Jan 09 09:44 : player: played         "In The Blue Of The Evening.flac"

# Playing: You Got To My Head.flac
Jan 09 09:44 : playlist: queue song     "Velvet Moon.flac"
Jan 09 09:44 : cache: Prefetch         "Velvet Moon.flac"
Jan 09 09:48 : player: played         "You Got To My Head.flac"

# Playing: Velvet Moon.flac
Jan 09 09:48 : playlist: queue song     "Come Sunday.flac"
Jan 09 09:48 : cache: Prefetch         "Come Sunday.flac"
.
.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#9
(01-09-2023, 03:29 PM)Tim Curtis Wrote: I did a little testing with locally attached USB drive and also remote NAS and it looks like MPD is in fact prefetching into RAM the track following the currently playing track.

Below is a verbose log edited for readability that shows the prefetch actions as tracks are being played. Input cache was set to 1 GB. Note that if Input cache is set to Disabled then no prefetch commands show up in the log.

Code:
# Queue order

LRMonoPhase4.flac
In The Blue Of The Evening.flac
You Got To My Head.flac
Velvet Moon.flac
Come Sunday.flac

pi@moode:~ $ tail -f /var/log/mpd/log

# Start Play: LRMonoPhase4.flac
Jan 09 09:39 : playlist: play         "LRMonoPhase4.flac"
Jan 09 09:39 : playlist: queue song     "In The Blue Of The Evening.flac"
Jan 09 09:39 : cache: Prefetch         "In The Blue Of The Evening.flac"
Jan 09 09:40 : player: played         "LRMonoPhase4.flac"

# Playing: In The Blue Of The Evening.flac
Jan 09 09:40 : playlist: queue song     "You Got To My Head.flac"
Jan 09 09:40 : cache: Prefetch         "You Got To My Head.flac"
Jan 09 09:44 : player: played         "In The Blue Of The Evening.flac"

# Playing: You Got To My Head.flac
Jan 09 09:44 : playlist: queue song     "Velvet Moon.flac"
Jan 09 09:44 : cache: Prefetch         "Velvet Moon.flac"
Jan 09 09:48 : player: played         "You Got To My Head.flac"

# Playing: Velvet Moon.flac
Jan 09 09:48 : playlist: queue song     "Come Sunday.flac"
Jan 09 09:48 : cache: Prefetch         "Come Sunday.flac"
.
.

... runs off to enable the input cache on his players again...
----------------
Robert
Reply
#10
I have mine set to max, 2GB on a 4GB Pi4b. I know it's subjective but there's definitely a sound quality bump. The UI gets a slight delay displaying art and track info but the trade off is fine with me.
Reply


Forum Jump: