QEMU audio
Not logged in

Audio support in the QEMU has two dimensions:

  1. Emulated audio devices in the virtual machine
  2. Connecting QEMU audio with outer world

Emulated audio devices

List of audio devices is controlled via QEMU commandline option -soundhw. It should also have equivalent in the QEMU config, but as of version 2.1 hardware support in the config is incomplete and we do not use configs.

You can list possible emulated devices via

qemu-system-i386 -soundhw help

You can add to virtual machine multiple devices at once, separating them by comma

qemu-system-i386 -soundhw sb16,adlib

Adds sound blaster 16 and adlib cards to the virtual machine.

Most of QEMU-emulated sound card are very-very outdated, from XX century. For relatively new operation systems I recommend always use hda.

Connecting QEMU with real sound device

It is not enough to add virtual sound card to virtual machine. If you want to really hear sounds, you'll have also tell QEMU how to connect, and probably some other options.

These options are set via environment variables, which are not documented in the QEMU user guide. You have to start

qemu-system-i386 -audio-help

To get brief list of those variables.

Main variable is QEMU_AUDIO_DRV, which allows to specify driver, which would be used to input/output sound from QEMU.

Useful drivers are:

  • spice - redirects audio to your spice client. Has one playback and one capture channel. Supports no options.

  • pa - uses pulseaudio. Supports following variables QEMU_PA_SAMPLES (size of buffer), QEMU_PA_SERVER - address of pulseaudio server, if non-default, QEMU_PA_SINK - name of audio output sink, QEMU_PA_SOURCE name of audio input source.

  • alsa talks directly with linux kernel drivers. There is horde of options which I don't understand

Less useful drivers:

  • sdl - use sdl library to output audio. Doesn't support sound input.

  • oss - talks to oss kernel drivers. Anybody uses OSS in 2015?

  • none - disable sound altogether.

  • wav - write all sound output to the wav file specified by QEMU_WAV_PATH variable. You can set frequency format (i.e. bit per sample and signed unsigned) and number of channels. No support for sound input. You can get same functionality with any of other drivers, if you use vws record (or wavcapture command in the QEMU monitor)

Recording sound from QEMU

QEMU provides ability to record sound into file. There is wavcapture command in the monitor which start recording into specified file and stopcapture respectively. You can start several captures into different files and stop them by their ids, found via info capture.

You need to specify full path to the capture file, otherwise it would be written into some strange place, if you got enough rights to write there.