# musicpd skips when I enable a fifo



## Greg Fitzgerald (Nov 22, 2017)

When I enable a output fifo in musicpd, wether something is reading from it or not musicpd skips every few seconds. This does not happen on my Linux box's. Its one of the things that always annoys me back to Linux as much as I want to stay on FreeBSD.

Soon as I disable the fifo output and restart musicpd it stops skipping. I have played with adding a %20 buffer to mpd config as well as adjusting the format to different levels. Nothing seems to resolve it.

I spoke to the MPD dev and he blamed the speed of FreeBSD fifo's. I don't know enough to argue the point.


```
music_directory "/mnt/storage/music"
playlist_directory "~/.mpd/playlists"
db_file "~/.mpd/mpd.db"
log_file "~/.mpd/mpd.log"
pid_file "~/.mpd/mpd.pid"
state_file "~/.mpd/state"
sticker_file "~/.mpd/sticker.sql"

# Needed for clerk --update
max_output_buffer_size "32000"

user "gregf"
group "gregf"

audio_output {
 type    "oss"
 name    "mpd"
}

audio_output {
  type "fifo"
  name "Visualizer feed"
  path "/tmp/mpd.fifo"
  format "16000:16:2"
}
```


----------



## SirDice (Nov 22, 2017)

What version of MPD and what version of FreeBSD?


----------



## Greg Fitzgerald (Nov 22, 2017)

It happened on Freebsd 10.3, 11.0, 11.1, and now 12-current (which i'm using for video drivers).

musicpd-0.20.11_2


----------



## Greg Fitzgerald (Nov 22, 2017)

Also /tmp is on a ssd. I also tried mounting it as a tmpfs just to make sure it wasn't a diskio issue for me. No difference there.


----------



## SirDice (Nov 22, 2017)

What's attached to the FIFO? It might be blocking I/O because the application that reads from the FIFO isn't able to read quickly enough.


----------



## Greg Fitzgerald (Nov 22, 2017)

I don't know? Soon as I play a song with fifo enabled in my mpd config it starts skipping. I want it to have a visualizer in ncmpcpp or using cava, but it skips if those are open or not.


----------



## SirDice (Nov 22, 2017)

It's a bit of a long shot, but try running something like `cat /tmp/mpd.fifo > /dev/null` in a separate shell. That should make sure the FIFO is continuously read and the output is sent to /dev/null.


----------



## Greg Fitzgerald (Nov 22, 2017)

That seemed to have slowed the visualization in ncmpcpp down to a slide show, and I still skipped.


----------



## SirDice (Nov 22, 2017)

Then I'm out of ideas. I don't use any of this myself so I'm hoping someone else might have some suggestions.


----------



## thebardian (Dec 4, 2017)

Here I am, reporting this, is still an issue, if anyone has any ideas. 11.1-STABLE here


----------



## tobik@ (Dec 4, 2017)

Greg Fitzgerald said:


> I don't know? Soon as I play a song with fifo enabled in my mpd config it starts skipping. I want it to have a visualizer in ncmpcpp or using cava, but it skips if those are open or not.


Both audio/musicpd and audio/cava have an sndio backend which means that using a FIFO is not a necessity here.  Build them with SNDIO=on and then enable sndiod via `sysrc sndiod_enable=YES && service sndiod start`.  By default sndiod is configured to have a monitoring sub device which you can point cava to.

Musicpd can be configured to use it by using type "sndio" instead of type "oss" in the audio_output section.  Point cava to the monitor device with `env AUDIODEVICE=snd/0.monitor cava`.

Of course a similar setup could probably also work when using their PulseAudio backends.


----------



## thebardian (Dec 7, 2017)

tobik@ said:


> Both audio/musicpd and audio/cava have an sndio backend which means that using a FIFO is not a necessity here.  Build them with SNDIO=on and then enable sndiod via `sysrc sndiod_enable=YES && service sndiod start`.  By default sndiod is configured to have a monitoring sub device which you can point cava to.
> 
> Musicpd can be configured to use it by using type "sndio" instead of type "oss" in the audio_output section.  Point cava to the monitor device with `env AUDIODEVICE=snd/0.monitor cava`.
> 
> Of course a similar setup could probably also work when using their PulseAudio backends.


I tried, sndio, and it did not work for me, cava couldn't seem to find the monitor device. I am fairly sure I had everything configured as you said, also. It led me on the right track, as I don't mind using pulseaudio, I recompiled again with musicpd pulseaudio support, enabled it within musicpd.conf and cava works without any issue.


----------



## tobik@ (Dec 7, 2017)

thebardian said:


> I tried, sndio, and it did not work for me, cava couldn't seem to find the monitor device. I am fairly sure I had everything configured as you said, also. It led me on the right track, as I don't mind using pulseaudio, I recompiled again with musicpd pulseaudio support, enabled it within musicpd.conf and cava works without any issue.


There are a couple of things that could go wrong:

If you're running musicpd and cava under different user accounts then you might have to share ~/.aucat_cookie between them, otherwise whoever gets the device first will block the other. See sndio(7):

```
AUTHENTICATION
     If a shared sndiod(8) server is running, for privacy reasons only one user
     may have connections to it at a given time (though the same user could have
     multiple connections to it).  Users are identified by their session cookie,
     which is automatically generated by audio or MIDI applications upon the
     first connection to the server.  The cookie is stored in
     $HOME/.aucat_cookie and contains 128 bits of raw random data.

     If a session needs to be shared between multiple users, they can connect to
     the server using the same cookie.
```

Setting sndiod_flags (i.e. overwriting the defaults) in /etc/rc.conf but failing to create a monitor device
 But good to hear it works fine for you with PulseAudio.


----------



## i-bsd (Jan 2, 2018)

I'm having the same problem.

Is there a fix for this (not resorting to audio/cava)?


----------



## dch (Jan 31, 2018)

what's the advantage of sndio vs oss in general?


----------



## tobik@ (Jan 31, 2018)

Sndio builds on top of OSS and they are tightly coupled on FreeBSD, so "sndio vs oss" is a false dichotomy.

Use sndio if you need networked audio/MIDI, need a monitor device to record what is played back, if your favorite application doesn't provide a working OSS or good alternative backend, or if you want something simpler to understand, configure, or hack than PulseAudio.


----------



## rsronin (Apr 17, 2018)

I have the same issue:

`amw@n54l:/usr/home/amw$ uname -r
11.1-RELEASE-p9
amw@n54l:/usr/home/amw$ ncmpcpp -v
ncmpcpp 0.8.1

optional screens compiled-in:
 - tag editor
 - tiny tag editor
 - outputs
 - visualizer
 - clock

encoding detection: enabled
built with support for: fftw ncurses taglib
amw@n54l:/usr/home/amw$`

Music is on an ext4 partition which is mounted with DSBMC.


----------



## rsronin (May 8, 2018)

Just found out by coincidence...using fifo/visualiser multiple times doesn't give the stutter, at least for 2.5 songs tested so around 10 minutes...


----------



## i-bsd (Jun 22, 2018)

Did anyone ever find a solution to this? Still trying to find a fix for it.


----------



## Greg Fitzgerald (Jun 22, 2018)

Sadly I have not.


----------



## fdnull (Jul 6, 2018)

man ncmpcpp:


> visualizer_fifo_path = PATH
> Path to mpd fifo output. This is needed to make music visualizer
> work (note that output sound format of this fifo has to be
> either *44100:16:1 or 44100:16:2*, depending on whether you want
> mono or stereo visualization)


----------



## rsronin (Jul 6, 2018)

fdnull said:


> man ncmpcpp:


I had/have this in my config file

`amw@n54l:/mnt/bsd/home/amw/.ncmpcpp$ ls
config  config.old  error.log
amw@n54l:/mnt/bsd/home/amw/.ncmpcpp$ cat config
visualizer_fifo_path = "/tmp/mpd.fifo"
visualizer_output_name = "my_fifo"
visualizer_sync_interval = "30" 
visualizer_in_stereo = "yes"
visualizer_type = "spectrum"
visualizer_look = "+

amw@n54l:/mnt/bsd/home/amw/.ncmpcpp$`

so no difference yet, also in the ttyX when moving the mouse musicpd stutters like crazy.


----------



## fdnull (Jul 7, 2018)

rsronin said:


> I had/have this in my config file
> 
> `amw@n54l:/mnt/bsd/home/amw/.ncmpcpp$ ls
> config  config.old  error.log
> ...


replace this  /usr/local/etc/musicpd.conf:


> audio_output {
> type "fifo"
> format "44100:16:*2*"
> ...
> }


with


> audio_output {
> type "fifo"
> format "44100:16:*1*"
> ...
> }


----------



## rsronin (Jul 7, 2018)

fdnull said:


> replace this  /usr/local/etc/musicpd.conf:
> 
> with



I did and also made changes to ~/.ncmpcpp/config to make sure using the same name:

visualizer_output_name = "my_fifo

as in /usr/local/etc/musicpd.conf:

name                    "my_fifo"

`audio_output {
        type            "oss"
#       name            "My OSS Device"
#       device          "/dev/dsp0.0"   # optional
#       mixer_type      "hardware"      # optional
        mixer_type      "software"
#       mixer_device    "/dev/mixer"    # optional
#       mixer_control   "PCM"           # optional
} 
# 
# An example of a FIFO output:
#
audio_output {
type                    "fifo"
name                    "my_fifo"
path                    "/tmp/mpd.fifo"
format                  "44100:16:1"
"musicpd.conf" 406 lines, 12957 characters
amw@n54l:/usr/local/etc$ smpd.sh
Starting musicpd.
amw@n54l:/usr/local/etc$ ncmpcpp
Reading configuration from /home/amw/.ncmpcpp/config...
amw@n54l:/usr/local/etc$`


----------



## fdnull (Jul 7, 2018)

rsronin said:


> I did and also made changes to ~/.ncmpcpp/config to make sure using the same name:
> 
> visualizer_output_name = "my_fifo
> 
> ...


cat /usr/local/etc/musicpd.conf|sed "/^#/d;/^ *$/d;"


> music_directory        "/mnt/media/music/"
> playlist_directory        "/var/mpd/.mpd/playlists"
> db_file            "/var/mpd/.mpd/database"
> log_file            "/var/mpd/.mpd/log"
> ...



 cat .config/ncmpcpp/config 


> mpd_host=/var/mpd/.mpd/socket
> mpd_music_dir=/mnt/media/music
> visualizer_fifo_path=/tmp/mpd.fifo


No names, no buffers, no intervals. Try to remove unnecessary lines.


----------



## i-bsd (Aug 29, 2018)

fdnull said:


> cat /usr/local/etc/musicpd.conf|sed "/^#/d;/^ *$/d;"
> 
> cat .config/ncmpcpp/config
> 
> No names, no buffers, no intervals. Try to remove unnecessary lines.



I'm still trying to find a solution to this.

fdnull's answer did not stop the skipping. 

Has anyone found a viable solution to the problem? I'm wondering if changing from unix socket to TCP/IP will make any difference?


----------



## tedbell (Nov 23, 2018)

Just incase anyone is still having a problem with this, try commenting out "visualizer_sync_interval" in your ncmpcpp config. I had little micro dropouts (skips) until I did this.


----------



## bch (Nov 24, 2018)

I am having similar issues: When attaching with ncmpcpp and showing the visualization (key 8), music skips.  Setting visualizer_sync_interval had no impact for me.  I tried:

renice ncmpcpp and mpd
ktrace and running mpd with verbose flag (nothing spurious in the output):


```
sudo ktrace musicpd --no-daemon --stderr --verbose /usr/local/etc/musicpd.conf
```


setting visualizer_sync_interval to 0, 20, 30, 60, 120 (seems to have no/little effect)
Everything works as expected when not viewing "Music visualizer" tab.

Are there other visualizers one can try?  I am not sure if its an mpd or ncmpcpp issue. 

Here is my ncmpcpp config:

```
x230:~ % grep -v "^#" ~/.ncmpcpp/config                                                                                             
ncmpcpp_directory = ~/.ncmpcpp
audio_output {
       type            "fifo"
       name            "Visualizer feed"
       path            "/tmp/mpd.fifo"
      format          "44100:16:2"
}
visualizer_fifo_path = /tmp/mpd.fifo
visualizer_in_stereo = yes
visualizer_sync_interval = 20
visualizer_type = wave
```

My musicpd.conf:


```
x230:~ % grep -v "^#" /usr/local/etc/musicpd.conf | grep -v '^$'
music_directory         "/usr/home/mpd/music"
playlist_directory              "/usr/home/mpd/playlists"
db_file                 "/usr/home/mpd/database"
log_file                        "/usr/home/mpd/log"
pid_file                        "/usr/home/mpd/pid"
state_file                      "/usr/home/mpd/state"
sticker_file                    "/usr/home/mpd/sticker.sql"
user                            "mpd"
bind_to_address         "/usr/home/mpd/socket"
input {
        plugin "curl"
}
audio_output {
        type "fifo"
        name "My FIFO"
        path "/tmp/mpd.fifo"
        format "44100:16:2"
}
audio_output {
        type            "oss"
        name            "My OSS Device"
}
audio_output {
        type            "httpd"
        name            "My HTTP Stream"
        encoder         "flac"          # optional, vorbis or lame
        port            "8000"
        bind_to_address "0.0.0.0"               # optional, IPv4 or IPv6
        bitrate         "128"                   # do not define if quality is defined
        format          "44100:16:1"
        max_clients     "0"                     # optional 0=no limit
}
```


----------



## tedbell (Nov 24, 2018)

I just tried again and I am getting skipping in spite of the change to the visualizer sync setting so disregard my post above. The problem is definitely with ncmpcpp and FIFO. Fifo is the culprit. When I cat /tmp/mpd.fifo > /dev/null then everything sounds find but my visualizer slows down to a slideshow. Disabling it outright fixes it too. Not sure what to do with ncmpcpp to get it to work.


----------



## Greg Fitzgerald (Oct 30, 2020)

Just an update to this, I noticed on FreeBSD current this works without issues. Not sure what patch could have fixed it? I still skips on 12.2.


----------

