plat/win_audio.rs (Windows)#
Source: lib/plat/win_audio.rs
win_audio -- (audio.rs) WASAPI in shared mode: one thread per stream, event-driven
open(feed, name) -> Dev the thread (COM multithreaded, "Audio" MMCSS class) opens the
default render device (IMMDeviceEnumerator, eRender / eConsole),
IAudioClient::Initialize in f32 with the stream's rate and
channels (AUTOCONVERTPCM + SRC_DEFAULT_QUALITY: the engine
converts to its mix format), a buffer of Core::dev_ms; open waits
for that first answer (no device: Unavailable)
the loop waits for the buffer event or a kick; tops the buffer up from
the Feed (GetCurrentPadding / GetBuffer / ReleaseBuffer); pause:
Stop, stop(): Stop + Reset, the end: drained, then Stop
default device an IMMNotificationClient of the thread: OnDefaultDeviceChanged
(render, console) reopens on the new device; an invalidated
device (unplugged) the same; none at all: State::Lost, retried
every second and on the next change
system_sound(kind) PlaySoundW(alias, SND_ALIAS | SND_ASYNC | SND_NODEFAULT |
SND_SYSTEM): the sound scheme's own sound (none assigned: false)
Loopback (tests) the default render device's mix captured
(AUDCLNT_STREAMFLAGS_LOOPBACK) on a thread of its own
COM objects are used through their vtable slots (as win_spell.rs, win_taskbar.rs). The
stream's name is not shown: the volume mixer names the program.
struct Loopback(tests) the default render device's mix captured while it runs (WASAPI loopback)
impl Loopback
fn start() -> Result<Loopback, AudioError>start capturing -> Err(Unavailable): no render devicefn finish(mut self) -> (u32, u16, Vec<f32>)stop -> (frames per second, channels, interleaved samples)