Skip to content

Add ALSA loopback audio bridge for native_sim ↔ QEMU integration #30

Description

@peterus

Context

We can now run the full station stack on a single PC:

  • QEMU x64 — Yocto image with Station Agent (A/B rootfs, GRUB, read-only)
  • native_sim — Zephyr firmware running as Linux process (SA818 driver, GPIO/ADC emulators, UART PTY)

Serial communication (Shell, AT commands) works via UART PTY → QEMU USB-Serial. Audio is the missing link.

Goal

Station Agent in QEMU captures/plays audio from a virtual USB soundcard, and the audio data flows to/from native_sim's audio pipeline — just like on real hardware where the STM32 presents as a USB Audio Class device.

Architecture

native_sim (Zephyr)          Host Kernel            QEMU Guest (Yocto)
┌──────────────┐           ┌─────────────┐        ┌──────────────────┐
│ RX Audio ────┼─► play ──►│  snd-aloop   │►─ cap ─┼► Station Agent   │
│ (DAC write)  │  hw:L,0,0 │  (loopback)  │ hw:L,1 │  (ALSA capture)  │
│              │           │              │        │                  │
│ TX Audio ◄───┼─◄ cap ───◄│              │◄─play ─┼◄ Station Agent   │
│ (ADC read)   │  hw:L,1,1 │              │ hw:L,0 │  (ALSA playback) │
└──────────────┘           └─────────────┘        └──────────────────┘

Implementation steps

Zephyr side (this repo)

  • New DAC backend: dac_alsa — similar to existing dac_wav but writes PCM to an ALSA device instead of a WAV file. Config: CONFIG_DAC_ALSA=y, device tree property output-device = "hw:Loopback,0,0".
  • ADC ALSA source (optional) — capture from hw:Loopback,1,1 to feed TX audio into the radio pipeline. Lower priority since TX testing is less common.
  • native_sim overlay update — add native_sim_native_64.conf entries for CONFIG_DAC_ALSA=y and update the DT overlay to use alsa-dac instead of wav-dac.

QEMU/run.sh side (linux-image repo)

  • Add to run.sh:
    -audiodev alsa,id=snd0,in.dev=hw:Loopback,1,0,out.dev=hw:Loopback,0,1 \
    -device usb-audio,audiodev=snd0
  • Document: sudo modprobe snd-aloop as prerequisite.

Station Agent side (station-manager repo)

  • Implement ALSA capture/playback for audio streaming to/from server.
  • The agent code should be identical to production (ALSA device, not mocks).

Host prerequisites

sudo modprobe snd-aloop
# Verify: aplay -l should show "Loopback" card

Acceptance criteria

  • native_sim RX audio (e.g., sine tone) appears as capture data on QEMU guest's ALSA device
  • QEMU guest playback reaches native_sim ADC input
  • Full duplex works simultaneously
  • Station Agent can stream audio to Station Manager server via WebSocket (once server is deployed)

Not in scope

  • USB Audio Class emulation in native_sim (real STM32 USB stack not needed for simulation)
  • DFU over USB (separate ticket if needed)
  • Real-time latency guarantees (best-effort is fine for testing)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions