Skip to content

Repository files navigation

GoGPU Logo

audio

Pure Go audio engine for Windows, macOS, and Linux
Zero CGO. PCM output. WAV decoding. Mixing. Platform-native drivers.

CIGo ReferenceGo Report CardLicenseZero CGO


Overview

audio is a Pure Go audio engine for the gogpu ecosystem. It provides low-latency PCM audio output, WAV decoding, and multi-channel mixing using platform-native APIs — without CGO.

Part of the gogpu GPU computing ecosystem (~800K+ LOC Pure Go).

Features

  • Pure Go — zero CGO on all platforms. Uses goffi/syscall for platform calls
  • Platform-native drivers — WASAPI (Windows), CoreAudio (macOS), PulseAudio (Linux)
  • WAV decoder — Pure Go WAV file parsing and playback
  • Mixer — multi-channel audio mixing with per-channel volume
  • io.Reader streams — composable audio pipeline (decoder → mixer → driver)
  • Non-blocking — audio runs in background goroutine, never blocks rendering

Status

Windows audio output working (WASAPI). macOS and Linux drivers planned.

Architecture

User Code
│
▼
audio.Context (singleton, manages audio device)
│
├── WAV Decoder (Pure Go)
├── Mixer (multi-channel, volume control)
│ ↑ ReadFloat32er (pull model)
▼
Platform Driver (background goroutine → hardware)
├── WASAPI (Windows) ✅ — COM vtable via syscall.SyscallN
├── CoreAudio (macOS) — planned
└── PulseAudio (Linux) — planned

API

package audio
// Create audio context (one per application)ctx, err:=audio.NewContext()
deferctx.Close()
// Play a WAV fileplayer, err:=ctx.PlayWAV(wavData)
player.SetVolume(0.8)
// Play from io.Reader streamplayer, err:=ctx.NewPlayer(pcmReader)
player.Play()

Examples

# Play 440Hz sine wave
go run ./examples/play_wav
# Play Mozart's "Eine Kleine Nachtmusik" (Casio watch style)
go run ./examples/mozart

Platform Support

PlatformDriverStatus
WindowsWASAPI (COM vtable via syscall)✅ Working
macOSCoreAudio (AudioQueue via goffi)Planned
LinuxPulseAudio (libpulse-simple via dlopen)Planned

Ecosystem

PackageDescription
gogpuApplication framework, windowing
gogpu/soundUI system sounds (clicks, alerts)
gogpu/audioFull audio engine (this package)
wgpuPure Go WebGPU
gg2D graphics
uiGUI toolkit

Related: gogpu/sound (UI System Sounds)

For simple UI feedback sounds (button clicks, notifications), use gogpu/sound — a thin platform delegation layer (~500 LOC) that plays OS system sounds via winmm.dll (Windows), NSSound (macOS), and PulseAudio (Linux).

gogpu/audio is for games, media apps, and audio visualization that need full PCM playback, mixing, and streaming.

Star History

Star History Chart

License

MIT License — see LICENSE.

About

Pure Go audio engine — WASAPI, CoreAudio, PulseAudio. Zero CGO.

Resources

Code of conduct

Contributing

Security policy

Stars

8 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages