libretro / libretro/RetroArch

Built-in music player audio stuttering on Linux

Open
#10,251 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

audio bug: audio mixer/menu sounds
Dominant language
C
Stars
14.1k
Forks
2.2k
Avg merge
7h 35m
Merged PRs (30d)
51

Description

Description

Audio intermittently "pops" during playback. I'm having audio issues in all cores as well, but since the issue seems to affect all of RetroArch, it's probably easiest to troubleshoot this way.

I've had this issue on multiple machines and multiple distros, but it's never been a problem on Windows, even on the same hardware.

I've been testing with a simple 5-minute sinewave file I made in audacity (untitled.zip). Other files work as well, though. My config file is reset to default.

Expected/Actual Behavior

The exact behavior is audio latency-dependent. In my own testing, on my laptop, I observed 3 different patterns, sharply divided:

  • 24 ms and below: constant erratic pattern of pops
  • 24-48 ms: one pop every 5 seconds exactly (sometimes one will be missing, but it's rare)
  • Above 48 ms: 1-2 pops ~5 seconds after playback starts, then smooth. However, the startup pops persist even with the max audio latency setting (512 ms!).

The expected behavior, of course, is a pure sine wave. I can play the file back without these issues using VLC without issue. fplay (ffmpeg package) works as well, so the issue definitely isn't the ffmpeg core.

Relevant Settings/Troubleshooting
  • Video driver: no effect when set to null. All testing done with default value (x)
  • Audio driver: no effect (some drivers do not work, most testing done with Pulse driver)
  • Synchronize audio: leave on (default), more frequent stutters when off
  • Vsync: behavior improves when turned off (default on); pops are gone above 24 ms, 5-second timed pops from 24 to 16 ms, and random pops starting at 8 ms
  • Hard GPU Sync: causes a few random pops before falling into the same behavior pattern as normal. Sometimes causes 2-3 pops instead of just one.
  • More? I can test other settings if requested.

This has been an issue on Linux for as long as I can remember, so I can't really bisect this one. It's hard to say if it's gotten better or worse, since it's intermittent and depends on other settings.

Possible Causes

My first thought is disk access: let's say RA fetches 5 seconds at a time, but only fetches once it's completely out of samples. In that case, if the audio buffer is shorter than the filesystem access time, and we get an underflow every 5 seconds. But that doesn't explain the relation to Vsync settings. I'm also not sure how this translates to rom files.

The resampler could be to blame, but then this should affect all platforms equally.

Also possible is some type of scheduling/priority/preemption issue. Like not being able to refill the audio buffer during Vsync blocking or something. But the math doesn't add up there either; a buffer longer than 16.7 ms should be safe no matter what. Setting the video driver to null should have fixed this as well.

Maybe there's some problematic code that was reused between the Pulse/ALSA drivers?

Normal Cores

I'm having similar problems in normal emulator cores as well, which is preventing me from using RetroArch. I suspect it's the same issue, but I think troubleshooting it via the music player can cut out a lot of variables. Normal emulator cores don't have this same degree of reproducibility (the stutters are random, not timed), nor do the stutters ever fully go away at any latency setting. The music player might not be such a high priority in itself, but a fix for this could be really valuable.

I have a separate, long-dead issue open on this already (#8235).

Environment
  • RetroArch: 1.8.4 9e25601
  • OS: Kubuntu 19.10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the built-in music player on Linux and the Pulse/ALSA audio-driver paths, reproducing the sine-wave pops across the latency, Vsync, and synchronization settings described here. Done means playback is a pure sine wave without stutters, including the affected normal emulator-core scenarios, while preserving behavior on other platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
audio-video-rtc, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.