- Kotlin 98.6%
- Shell 1.4%
AudioSBC started as a fork of AirheadWaves (MIT). The upstream notice stays as it is, as the licence requires; this adds one for the changes made here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|---|---|---|
| .idea | ||
| app | ||
| fastlane/metadata/android/en-US | ||
| gradle | ||
| .gitignore | ||
| .gitlab-ci.yml | ||
| build.gradle.kts | ||
| create_release.sh | ||
| gradle.properties | ||
| gradlew | ||
| gradlew.bat | ||
| LICENSE | ||
| README.md | ||
| run_on_device.sh | ||
| settings.gradle.kts | ||
AudioSBC for Android
Streams your phone's audio to the STM32MP157 whole-house audio board, and drives the board's MQTT control surface: which rooms play it, their volume and mute, plus a tap-to-talk intercom.
It is the Android counterpart of the AudioSBC desktop app, and behaves the same way. It configures itself: room names, volume ceilings, the board's address, the RTP format and which UDP port to send to are all discovered from the board at runtime. The only thing you have to supply is how to reach the MQTT broker.
This repository started as a fork of AirheadWaves. Its TCP/AAC sender and receive mode are gone; see the git history if you need them.
What it does
apps playing ──► screen-capture audio ──► Opus ──► RTP ──► board:50xx
│
MQTT ◄── rooms, volume, mute, health, receiver slot ─────────┘
- Self-configuring. Subscribes to the board's topic tree and builds its whole picture from retained state.
- Claims a receiver. The board keeps a pool of five receivers. The app claims one on connect and gives it back when you leave - or, if the phone drops off the network, via an MQTT last will, so a slot is never stranded.
- Captures what the phone plays. Android has no virtual sink to route to; instead it lets an app capture other apps' media and game audio through screen capture, which is why Android asks to "share your screen" when you tap Stream. Only audio is taken. Apps that opt out of capture (some DRM'd streaming apps) are not heard, and the phone keeps playing through its own speaker too, so turn that down.
- Opus without native code. Encoding uses the platform's own Opus encoder, present on every phone since Android 10. It picks 20 ms frames; the RTP clock is read from each packet, so the board's receiver is told exactly.
- Survives a board restart. If the board forgets our receiver, the app claims a new one and carries on streaming into it without asking for capture permission again.
- Buffer for WiFi. A phone is always on WiFi, so this matters more here than on the desktop: it asks the board to buffer this phone's receiver for 800 ms instead of 20, which rides out the radio dropping out at the cost of that much delay. The board remembers it per device. Switching restarts the receiver, so expect a short gap.
- Intercom. Pick a room, tap Talk, speak, tap again. The button latches and turns red while the microphone is open. Music in the rooms you are streaming to ducks while you speak and returns to exactly its previous level. The microphone closes if you leave the app, so a latched button can never leave a hot mic behind the lock screen. Turn the whole feature off in Settings, which also stops the app claiming a second receiver slot.
First run
The app opens on Settings. Fill in the broker host, port, username and password, and save. Everything else has a working default.
The password is stored in the app's private storage in the clear, matching
how the board's own homeaudio.yml treats it, and the app opts out of
Android backups so it does not leave the phone. Scope that account to the
homeaudio/# tree and do not reuse the password.
Set Name to something you will recognise: the board names your receiver
after it, so it is what shows up in hactl slots and in everyone else's copy
of the app. It defaults to the phone's own name.
Settings
| Setting | Default | What it does |
|---|---|---|
| Host / Port | - / 1883 |
the MQTT broker |
| Username / Password | - | broker credentials |
| Name | phone name | becomes the device id on the board |
| Offer the intercom | on | off hides it and never claims a second slot |
| Lower the music while talking | on, by 10 |
ducking, in volume points |
| Topic prefix | homeaudio |
advanced |
| Music bitrate | 500000 |
Opus bit/s; the platform encoder tops out at 512000 |
| Board buffer, normal | 20 ms |
jitter buffer without "Buffer for WiFi" |
| Board buffer, Buffer for WiFi | 800 ms |
jitter buffer with it ticked |
| Intercom bitrate | 64000 |
voice needs far less than music |
Volume, and why the sliders stop early
Each room has a max_volume ceiling on the board and the board silently
clamps anything above it. The sliders stop at the discovered ceiling
instead, so a control never looks like it is being ignored. The scale is
steeply non-linear - see the desktop app's README for the curve.
Building
./run_on_device.sh # build, install, launch, follow the log
or ./gradlew assembleDebug testDebugUnitTest. Gradle 8.13 will not run on
the Java 25 bundled with current Android Studio; use a JDK 17 or 21
(JAVA_HOME=/usr/lib/jvm/java-21-openjdk). Release builds are signed by CI.
Needs Android 10 (API 29) or newer.
How it talks to the board
Exactly as the desktop app does; the claim protocol and every topic are documented in the board repository's docs/mqtt.md.
client/{uuid}/status retained presence, and the connection's LAST WILL
client/{uuid}/claim {"name": ..., "roles": ["stream", "intercom"]}
client/{uuid}/grant {"stream": {"device": ..., "udp_port": ..., "slot": ...}}
device/{id}/zones the rooms to play into - a replace, not an add
device/{id}/start "1" / "0"
device/{id}/latency jitter buffer in ms
zone/{id}/volume a bare integer
zone/{id}/mute "1" / "0"
Commands are never retained. Presence is republished every 30 s, because the board's janitor reclaims a slot whose client has been quiet for 90.
Code map
| File | Role |
|---|---|
board/Topics.kt |
topic construction and parsing |
board/BoardState.kt |
the board's state, folded from retained topics |
board/MqttLink.kt |
the connection: last will, presence, reconnects |
HouseAudio.kt |
the brain: claiming, slot recovery, routing, intercom, ducking |
MusicService.kt |
foreground service owning the capture |
audio/OpusSender.kt |
PCM → MediaCodec Opus → RTP over UDP |
audio/Rtp.kt |
RTP framing and Opus packet durations |
ui/ |
Compose screens |
License
See LICENSE.