Comment 35 for bug 188567

Revision history for this message
Jordan Callicoat (monkeesage) wrote : Re: [hardy] soundproblems with zsnes

@all:

As explained by the creator of OSS3 (and 4): "Level of latencies [depend on] buffer size."[1]

So, to fix stuttering sound (from SDL or elsewhere) on pulseaudio + alsa, increase the number of buffers (default: 12) and the buffer sizes (default: 1024). Edit /etc/pulse/default.pa as superuser, and add the following lines anywhere BEFORE the line ".ifexists module-hal-detect.so":

load-module module-alsa-sink sink_name=output device=hw:0 fragments=24 fragment_size=2048
load-module module-alsa-source source_name=input device=hw:0 fragments=24 fragment_size=2048

Be sure to restart pulseaudio for the settings to take effect:

pulseaudio -k ; pulseaudio --daemonize

After this, the unpatched zsnes 1.51 with -ad sdl switch, or other apps that use SDL sound, should play smoothly (if you're not running all kinds of audio filters and what-not, see below).

For me, on 32-bit hardy, this works great with zsnes + libsdl1.2debian-pulseaudio + alsa + pulseaudio. Not stuttering or popping during gameplay (though zsnes does still make strange r2d2 sounds when it first starts).

Also, for even lower latencies, you can add yourself to the pulse-rt group (sudo gpasswd -a <username> pulse-rt), then add the following lines at the bottom of /etc/pulse/daemon.conf

high-priority = yes
nice-level = -11
realtime-priority = 5
default-fragments = 8
default-fragment-size-msec = 15

Then after a logout and re-login to X, pulse should run with a higher system priority and be more greedy for samples, which should also improve latency. On my system (athlon 1.8GHz, 1gig ram), using the settings above for default.pa and these in daemon.conf, I can run zsnes with simulate surround, 48000 sample rate, cubic spline interpolation and hi quality lowpass filter, with very minor twitches. At 44100 sample rate it is perfectly smooth.

Heh, yeah...just thought of something else as well. You can also pass a command line option to pulseaudio called --resample-method (or set it in /etc/pulse/daemon.conf for permenant use), which lets you choose which resampler to use. Some are faster and some sound better. I think the ffmpeg resampler has a good balance of speed and quality, but YMMV. There are a bunch to play with (list them with pulseaudio --dump-resample-methods).

[1] http://4front-tech.com/hannublog/?p=5#comment-422