Sound
Give the guest QEMU's sound cards, and play the sound on a Mac's speakers, in a web page through Web Audio, through your own code, or into a WAV file.
The sound cards are QEMU's, set up with QEMU's -audiodev and -audio options:
warm-system-aarch64 ... -audiodev coreaudio,id=snd -device virtio-sound-pci,audiodev=snd
# an Intel HD Audio card instead
warm-system-aarch64 ... -audiodev coreaudio,id=snd -device intel-hda -device hda-duplex,audiodev=snd
# or, in one option
warm-system-aarch64 ... -audio coreaudio,model=virtioQEMU's invocation page describes -audiodev and -audio, and -device help lists the sound cards under "Sound devices".
Where the sound goes
The audio drivers are the ones in QEMU's macOS build, and -audiodev help lists them.
-audiodev driver | Sound goes to |
|---|---|
none | Nowhere. |
wav[,path=FILE] | A WAV file, written when the machine ends (default warm.wav, where QEMU's is qemu.wav). |
coreaudio | With warm-system-aarch64 on a Mac, the default output device, as with QEMU. Elsewhere, the host's audio, which in a web page is the browser's output through Web Audio. It's also QEMU's default on macOS for a card with no -audiodev. |
dbus | QEMU's D-Bus display (-display dbus). |
In a web page
browserWARMHost() plays the sound through the Web Audio API, at the sound card's own rate and channel count. Browsers keep a page silent until the user interacts with it, so the sound starts on the page's first click, key press or touch. To start it from your own button, pass your own WebAudio and call unlock() in the button's click handler:
import { WARM, browserWARMHost, WebAudio } from "@warm-virtual/warm64";
const audio = new WebAudio();
playButton.onclick = () => audio.unlock();
const host = browserWARMHost({ audio });
const vm = await WARM.launch("... -audio coreaudio,model=virtio", host);On a cross-origin-isolated page, the samples reach the browser's audio thread through shared memory. On any other page, they're posted to it in chunks. browserWARMHost({ audio: false }) keeps the sound card silent.
Web Audio only exists on a page's main thread, not in a worker. So a machine running in a worker has no sound output of its own. Give its host an audio that posts the samples to the page, and play them there.
// in the worker
const play = (samples, rate, channels) => postMessage({ samples, rate, channels });
const host = { ...browserWARMHost(), audio: { play } };
// on the page
const audio = new WebAudio();
worker.onmessage = ({ data }) => {
if (data.samples) audio.play(data.samples, data.rate, data.channels);
};Your own output
Any object with a play(samples, rate, channels) method works as a sound output. It receives signed 16-bit interleaved samples. In your own Node code, nodeWARMHost() has no sound output (warm-system-aarch64 adds the Mac's), so an -audiodev gets a warning and the sound is dropped until you add one. If the output also has record(), it supplies what the guest's microphone captures; WebAudio doesn't record.
Recording from the monitor
QEMU's wavcapture records an audiodev's output to a file, and stopcapture stops it, by its number in info capture. QEMU has deprecated both since 10.2, and they warn just as QEMU's do. A wav audiodev is the long-term way to record.
(warm) wavcapture session.wav snd
(warm) stopcapture 0