No description
  • Rust 72.6%
  • Python 27.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-06-15 11:22:12 +00:00
docs Update docs/future.md 2026-06-15 11:16:12 +00:00
src better latency logging 2026-06-15 09:45:07 +08:00
tools better latency logging 2026-06-15 09:45:07 +08:00
.gitignore use mimalloc 2026-06-14 15:40:57 +08:00
Cargo.lock use mimalloc 2026-06-14 15:40:57 +08:00
Cargo.toml Merge branch 'main' into dev 2026-06-14 09:48:44 +00:00
README.md Update README.md 2026-06-15 11:22:12 +00:00

AudioBridge

Streams your PC's audio to your phone over Wi-Fi.


Why this exists

I wanted to listen to music and audiobooks on my phone while using my PC — but the audio was on the PC. Yes, I know that's backward. The obvious fix is a browser tab or a sharing app, but everything I tried sat in the background using 150–200 MB of RAM just to forward some audio. That felt insane for what is essentially "copy these bytes over Wi-Fi."

AudioBridge does the same thing in about 5 MB of RAM (and only ~100 KB of that is actual audio buffers — the rest is just the process existing). CPU sits under 1%. It lives in the system tray and gets out of the way.


What it does

  • Captures everything your PC plays — games, music, browser tabs, whatever
  • Encodes it with Opus at 96 kbps and fires it over UDP to your phone
  • End-to-end latency is around 25–35 ms, which is better than Bluetooth

That's it. No accounts, no cloud, no installer. LAN only, trusted network, no encryption.


Getting started

Requires Rust and Visual Studio Build Tools:

cargo build --release
.\target\release\audiobridge.exe

A green icon appears in your system tray. It starts streaming immediately.

Receiving the audio — I wrote a companion Android app for my own phone, but honestly the easiest starting point for anyone else is the Python mock client included in tools/:

pip install opuslib sounddevice numpy
python tools/mock_client.py --play

That'll decode and play the audio on whatever machine you run it on. From there you can look at the source and build your own receiver — the protocol is simple enough that mock_client.py is a reasonable reference.


Config

First run creates %APPDATA%\audiobridge\config.toml:

target_ip         = "192.168.1.55"   # your phone's IP — find it in Settings > Wi-Fi
port              = 9876             # UDP audio port
control_port      = 9877             # discovery port (clients send HELLO here)
bitrate_kbps      = 96              # 32 = usable, 64 = good, 96 = default, 128 = great
silence_threshold = 0.001           # skips sending when nothing is playing; 0.0 to disable

Restart after editing. If your client sends a HELLO packet on startup, target_ip is only used as a fallback — the sender will auto-discover the client's IP.


Troubleshooting

Problem Fix
Phone gets nothing Set target_ip to your phone's exact IP. Most routers and phones block UDP broadcast.
Audio cuts out or clicks Try silence_threshold = 0.0 — the silence gate can clip the start of sounds
Wrong audio source AudioBridge captures the default output device. Change it in Windows Sound settings.
High latency Make sure your receiver uses a small playback buffer — the sender's side is only ~12 ms

Structure

Four threads, each with one job:

┌──────────────────────────────────────────────────────┐
│  Thread 1 — WASAPI capture                           │
│  Woken by audio hardware every 10ms                  │
│  Grabs PCM frames and pushes them to a ring buffer   │
└─────────────────────┬────────────────────────────────┘
                      │  lock-free ring buffer (8 slots, ~31 KB, fixed)
┌─────────────────────▼────────────────────────────────┐
│  Thread 2 — Encode + send                            │
│  Parks at 0% CPU until audio arrives                 │
│  Opus-encodes each 10ms frame (complexity 3)         │
│  Sends a UDP packet to every registered client       │
└─────────────────────┬────────────────────────────────┘
                      │  UDP on port 9876
                   📱 phone / mock_client.py

┌──────────────────────────────────────────────────────┐
│  Thread 3 — Tray UI  (main thread)                   │
│  Win32 message pump, start/stop, live stats          │
│  Sleeps 50ms per tick                                │
└──────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────┐
│  Thread 4 — Control listener  (UDP port 9877)        │
│  Clients send HELLO on startup, ALIVE every 5s       │
│  Sender auto-discovers their IPs and streams to them │
│  Evicts clients after 30s of silence                 │
└──────────────────────────────────────────────────────┘

The threads barely talk to each other. PCM moves through a lock-free ring buffer. Stats are four atomics. The client list is a mutex held for a few microseconds per packet. When nothing is playing, Thread 2 is parked and the whole thing uses effectively 0% CPU.


Why so little RAM

Everything AudioBridge will ever need is allocated once at startup:

  • Ring buffer: 8 slots × ~3.8 KB = ~31 KB, fixed forever
  • Accumulation buffer: ~31 KB, allocated once
  • Encode/decode/packet buffers: stack-allocated, zero heap traffic on the hot path

Total audio buffer heap: ~70–100 KB. The process RSS lands around 5 MB once you add the Rust runtime, Windows handles, and the tray icon — but the actual audio work happens in under a hundred kilobytes. A single browser tab thumbnail is bigger.

During silence (reading, coding, etc.) the silence gate means nothing is encoded or sent at all — bandwidth drops to zero, not just low.


Protocol (for client implementors)

Each UDP packet on port 9876 is a 20-byte header followed by a raw Opus frame:

Bytes  0–3   magic "ABRH"
Bytes  4–7   sequence number (u32 LE, wraps at 0xFFFFFFFF)
Bytes  8–15  capture timestamp (u64 µs since sender start, monotonic)
Bytes 16–19  sender pipeline latency (u32 µs, capture→send, typically 1–3 ms)
Bytes 20+    Opus frame — 10ms, 48kHz, stereo, ~130 bytes at 96 kbps

Sequence numbers skip during silence (silent frames aren't transmitted and don't increment the counter), so gaps in seq are normal and don't mean packet loss. Use modular u32 arithmetic when comparing.

Full spec with jitter buffer design, control protocol (HELLO/ALIVE/PING/PONG), and reference parsers in C, Python, Rust, Kotlin, and Swift: docs/client-spec.md.