Skip to content

Audio playback on macOS (OS X) lags/skips and is unlistenable with Bluetooth audio devices #72

Closed

Description

@srubin

Copying from my bug (4638) in Mantis:

Category: MPD
Tags: mpd, output, playback
Reproducibility: always
Severity: major
Priority: high
Status: assigned (to jacobvosmaer)

When I have my AirPods or my UE Mini Boom connected to my MacBook Pro via Bluetooth, MPD audio skips/lags - there's a pause in the audio every half second or so. Other audio sources (e.g., iTunes, Spotify, Safari) don't do this, so it doesn't appear to be a systemwide Bluetooth audio issue. I've played around with the buffer size settings in my mpd config file, to no avail.

If I kick the samplerate down, e.g., audio_output_format "22050:*:*", the problem is mostly (but not completely) fixed.

I used to be able to fix this by changing the mixer_type to "hardware" for my audio_output:

audio_output {
             type "osx"
             name "macOS"
             mixer_type "hardware"
}

but this fix isn't working for me anymore.

Steps to Reproduce:
Connect AirPods or other Bluetooth Audio device to MacBook Pro. Play music in MPD. Hear skips.

Current solution:
Use mpd 0.19.x instead of 0.20.x.

Activity

  1. ykelvis commented on Jul 7, 2017

    @ykelvis

    Hi, I was playing with my bluetooth stereo just now, and noticed same problem.
    After trying legacy versions, I noticed the problem may not be in mpd itself.

    Using Music Player Daemon 0.20.9(latest):
    when 1) using brew services start mpd, exactly same lag occurs.
    2) using mpd ~/.config/mpd/mpd.conf, no more lag at all.

    I noticed there is a "--no-daemon" in default plist file, but after trying mpd --no-daemon ~/.config/mpd/mpd.conf directly in console, there is also no lag as it is like with brew service.

    my mpd audio_output as below:

    audio_output {
      type                  "osx"
      name                  "CoreAudio"
      mixer_type            "software"
    }
    
  2. MaxKellermann commented on Jul 31, 2017

    @MaxKellermann
    Member

    Unfortunately, there is no MPD developer with OS X, thus the OS X plugin is unmaintained and unsupported.

  3. thumphries commented on Oct 13, 2017

    @thumphries

    As @ykelvis suggests, this seems to be a problem with the service definition in homebrew. By default, launchd applies some kind of resource limits. Bluetooth appears to cause MPD to blow its IO budget, or something like that.

    I fixed this locally by setting ProcessType to Interactive in my MPD plist, lifting all resource limits. I'll head over to homebrew and try to make this the default. You should be able to replicate like so:

    $ brew services stop mpd
    $ vi ~/Library/LaunchAgents/thumphries.mpd.plist
    <copy plist below>
    $ launchctl load ~/Library/LaunchAgents/thumphries.mpd.plist
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>homebrew.mxcl.mpd</string>
        <key>WorkingDirectory</key>
        <string>/usr/local</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/opt/mpd/bin/mpd</string>
            <string>--no-daemon</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
        <key>ProcessType</key>
        <string>Interactive</string>
    </dict>
    </plist>
  4. MaxKellermann commented on Oct 13, 2017

    @MaxKellermann
    Member

    Thanks, @thumphries. Is there something this project can do to get better defaults for macOS users? Like ship this file in the source tarball and install it with make install?

  5. thumphries commented on Oct 13, 2017

    @thumphries

    Is there something this project can do to get better defaults for macOS users?

    I've been using MPD since 2010 (thanks Max!) and on macOS since 2012. The process to get MPD running is easier than it has ever been, Homebrew handles everything, as simple as:

    brew install mpd
    brew services start mpd
    

    As long as we keep those Homebrew service definitions up to date, I wouldn't worry too much. It's pretty good. This is the first bug I've encountered in 5 years. Perhaps some users are still compiling from source or using Macports, I can't comment on what they may prefer.

  6. thumphries commented on Oct 13, 2017

    @thumphries

    It's possible the extra work being done by MPD when Bluetooth is enabled is a bug, mind you. I'm just sweeping it under the rug!

  7. jaredculp commented on Oct 25, 2017

    @jaredculp

    FWIW these settings are working pretty well for me (I was consistently having 1 second or so buffering, or pauses)

    audio_output {
      name "default"
      type "ao"
      mixer_type "software"
    
      audio_buffer_size "8192"
      buffer_before_play "25%"
    }
    

    Installed mpd via brew install mpd --with-libao. My setup is a raspberry pi with an external HD of FLAC files which I mount on my laptop using sshfs.

  8. MaxKellermann commented on Dec 21, 2017

    @MaxKellermann
    Member

    Was there an improvement with MPD 0.20.13?

  9. lopter commented on Jan 3, 2018

    @lopter

    @MaxKellermann I ran into this exact issue this week using MPD 0.20.13 on macOS Sierra (10.12). I run mpd as a service (using launchd) and my plist has the patch from homebrew-core#19410.

    I play files locally and I don't have an audio_output configured (mpd defaults to coreaudio automatically). mpd works fine when using the headphone jack of my macbook but is completely unusable with a bluetooth device.

  10. MaxKellermann commented on Jan 3, 2018

    @MaxKellermann
    Member

    Thanks for the feedback. @Wang-Yue submitted OS X improvements, and I hoped that would have solved the problem. Unfortunately, I cannot help with this (persisting) problem because I have no Mac, and there is no other (regular) volunteer to work on OS X specific MPD issues.

  11. lopter commented on Jan 3, 2018

    @lopter

    I understand, thank you so much for the follow-up!

  12. lopter commented on Jan 3, 2018

    @lopter

    One more detail I forgot to add: I don't have this issue with mpv, I guess it could be interesting to look at their coreaudio implementation.

  13. MaxKellermann commented on Jan 3, 2018

    @MaxKellermann
    Member

    Actually, looking at mpv source code may not be necessary; this sounds like a rather simple problem, because it appears to be trivial to reproduce. Once reproduced, the solution may be obvious. The problem is that the guy who reproduces this and comes up with said simple solution doesn't exist. It will stay that way until such a guy emerges and sends me his patch.

  14. coroner21 commented on Feb 28, 2018

    @coroner21
    Contributor

    Is this still a problem? I tried it today using latest git master with a bluetooth headset and with a JBL Flip 2 on macOS High Sierra. Playback was completely flawless for both a 44.1khz CD rip and some hires 24 bit 96khz file (ALAC).

  15. shrx commented on Mar 1, 2018

    @shrx

    @coroner21 do you experience any lag if you enable spectrum visualization?

  16. Wang-Yue commented on Mar 1, 2018

    @Wang-Yue
    Contributor

    @shrx don't use spectrum visualization on OSX. The socket is not as performant as it is on Linux.

  17. coroner21 commented on Mar 1, 2018

    @coroner21
    Contributor

    I never used spectrum visualization. Just gave it a go and yes, there are skips and hiccups even with the default built-in output device. It is interesting that playback is stable in case the visualizer is not shown in ncmpdcpp.

    I do not see however how this is related to playback on bluetooth devices which is the issue here.

  18. MaxKellermann commented on Mar 1, 2018

    @MaxKellermann
    Member

    Any setup which uses the "fifo" or "pipe" output plugin is unsupported. But the original bug reported did not mention that he used it. I think this bug report has become pretty confusing now that people started posting irrelevant pieces of information.
    I suggest closing this issue (because the original reporter never gave feedback), and people who still have problems on OS X shall write new bug reports with complete information.

  19. szalishchuk commented on Jun 4, 2018

    @szalishchuk
  20. mbhangui commented on Jun 20, 2022

    @mbhangui

    I had this issue with coreaudio. Running mpd in the foreground or background didn't solve my problem. Changing type "osx" to type "ao" fixes the issue with choppy audio. Ultimately what fixed the issue completely, without having to change the type to "ao" was to use mpd to bypass coreaudio by using the dac device name.

    audio_output {
        type            "osx"
        name            "xonar Essenceone"
        device          "Speaker"
        format          "*:32:2"
        mixer_type      "software"
        dop             "yes"
     }
    

    To get the DAC device name run the system_profiler SPAudioDataType command

    $ system_profiler SPAudioDataType
    Audio:
    
        Devices:
    
            Built-in Input:
    
              Default Input Device: Yes
              Input Channels: 2
              Manufacturer: Apple Inc.
              Current SampleRate: 44100
              Transport: Built-in
              Input Source: Line In
    
            Built-in Output:
    
              Manufacturer: Apple Inc.
              Output Channels: 2
              Current SampleRate: 44100
              Transport: Built-in
              Output Source: Digital Out
    
            HDMI:
    
              Manufacturer: Apple Inc.
              Output Channels: 8
              Current SampleRate: 96000
              Transport: HDMI
              Output Source: RX-V667
    
            Speaker:
    
              Default Output Device: Yes
              Default System Output Device: Yes
              Manufacturer: ASUS
              Output Channels: 2
              Current SampleRate: 44100
              Transport: USB
              Output Source: Default
    
  21. dhocker commented on Jun 20, 2022

    @dhocker
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    osxMac/Apple-specific.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions