Skip to content

[Audio] Implement Windows-native audio backend (follow-up to #71) #75

@DecampsRenan

Description

@DecampsRenan

Why

#71 introduced an internal audio.backend interface and split the implementation behind build tags, but on Windows the package currently uses backend_stub.go (a silent no-op). --vibes and --notify therefore do nothing on Windows builds. This issue tracks wiring a real Windows backend so audio reaches parity with macOS/Linux.

Where

  • internal/audio/backend.go — interface to implement (available, playLoop, fadeOut, stop, playSound)
  • internal/audio/backend_stub.go — current Windows fallback; has a TODO(#71) pointing at this work
  • internal/audio/backend_beep.go — reference implementation (gopxl/beep) for macOS / CGO-enabled builds

Library candidates

  • github.com/hajimehoshi/oto/v2 — pure-Go on Windows (DirectSound), CGO-free; same maintainer as ebitengine. Could also replace beep on Linux later if we want a single backend everywhere.
  • winmm via golang.org/x/sys/windows — call PlaySound / waveOutWrite directly. Smallest dependency footprint, most code to write (we'd own the decoder + mixing + fade ramp).
  • powershell -c (New-Object Media.SoundPlayer …).PlaySync() shim — easiest, but only WAV, no looping/fade, one process per sound. Probably not viable for --vibes.

Recommendation: try oto/v2 first. The beep mp3.Decode decoder is decoupled from the speaker and can be reused — the Windows backend would decode the embedded MP3s the same way and push samples to oto. Keeping the option open to consolidate to a single backend later.

Acceptance

  • internal/audio/backend_windows.go (build tag windows) implements the backend interface
  • backend_stub.go constrained to its remaining cases (or removed entirely if every supported target has a real backend)
  • --vibes plays the looping track on Windows with fade-in / fade-out
  • --notify plays success / error / ding sounds on Windows
  • Audio init failure on Windows falls back silently with a warning, does not crash the command (parity with macOS/Linux)
  • CI cross-compiles CGO_ENABLED=0 GOOS=windows go build ./... cleanly

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions