Latency and choppy sound with PC Speaker on QEMU on WSL
Posted: Sat Aug 16, 2025 3:36 pm
I'm running my own home brew OS in QEMU on Ubuntu on WSL on Windows 11. I have code that sends a repeating scale of notes to the PC speaker (port 0x61). When I play a scale, it starts out fine, but the latency gets greater and greater until the sound starts to break up into short fragments. The fragmented sounds start 10-20 seconds after starting the scale. I expected some delay due to QEMU/WSL/Windows, but I wasn't expecting the increasing latency or the breaking up.
I run qemu as:
qemu-system-i386 -drive file=myos_disk.fat,index=0,media=disk,format=raw -debugcon stdio -audiodev pa,id=pcspkr -machine pcspk-audiodev=pcspkr
qemu: 8.2.2 (same result with 10.0.3 compiled from source)
Ubuntu: 24.04.3 LTS
WSL: 2.5.10.0
I don't understand how qemu uses pulseaudio. I don't have pulseaudio installed and yet I get the scale sounds. I did install pulseaudio-utils so I could use
pactl set-sink-volume RDPSink 25%
which does change the volume of the scale notes.
There is one sink
$ pactl list sinks
Sink #1
State: SUSPENDED
Name: RDPSink
Description: RDP Sink
Driver: module-rdp-sink.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 19
Mute: no
Volume: front-left: 16384 / 25% / -36.12 dB, front-right: 16384 / 25% / -36.12 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: RDPSink.monitor
Latency: 0 usec, configured 0 usec
Flags: DECIBEL_VOLUME LATENCY
Properties:
device.description = "RDP Sink"
device.class = "abstract"
device.icon_name = "audio-card"
Formats:
pcm
$ pulseaudio --version
Command 'pulseaudio' not found, but can be installed with:
sudo apt install pulseaudio
Can someone please explain how qemu uses pulseaudio to play port 0x61 speaker sounds without pulseaudio being installed and how to fix the latency/breakup issues? I'm wondering about a sample rate mismatch, but I don't know where they are set.
Thanks,
Mark
I run qemu as:
qemu-system-i386 -drive file=myos_disk.fat,index=0,media=disk,format=raw -debugcon stdio -audiodev pa,id=pcspkr -machine pcspk-audiodev=pcspkr
qemu: 8.2.2 (same result with 10.0.3 compiled from source)
Ubuntu: 24.04.3 LTS
WSL: 2.5.10.0
I don't understand how qemu uses pulseaudio. I don't have pulseaudio installed and yet I get the scale sounds. I did install pulseaudio-utils so I could use
pactl set-sink-volume RDPSink 25%
which does change the volume of the scale notes.
There is one sink
$ pactl list sinks
Sink #1
State: SUSPENDED
Name: RDPSink
Description: RDP Sink
Driver: module-rdp-sink.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 19
Mute: no
Volume: front-left: 16384 / 25% / -36.12 dB, front-right: 16384 / 25% / -36.12 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: RDPSink.monitor
Latency: 0 usec, configured 0 usec
Flags: DECIBEL_VOLUME LATENCY
Properties:
device.description = "RDP Sink"
device.class = "abstract"
device.icon_name = "audio-card"
Formats:
pcm
$ pulseaudio --version
Command 'pulseaudio' not found, but can be installed with:
sudo apt install pulseaudio
Can someone please explain how qemu uses pulseaudio to play port 0x61 speaker sounds without pulseaudio being installed and how to fix the latency/breakup issues? I'm wondering about a sample rate mismatch, but I don't know where they are set.
Thanks,
Mark