# Blink Qt — AG Podcast Mixer as a sound device: jamming and live interviews

Status as of 2026-11-18: working on Linux (PipeWire) with AG CuteMusic (`~/work/ag-cute-music`): 1-to-1 SIP calls
tested end to end (Blink Qt to Blink for macOS), WebRTC rooms written, not yet tested. The design and the macOS side:
python3-sipsimple `docs/PodcastMixerLink.md`.

## Who it is for

- **Musicians jamming together over a call:** each one hears the others in their headset, mixed with their own
  instrument or voice and, if they like, a backing track, and sends their part at music quality, not voice quality.
- **Hosts of live interviews and podcasts:** the host's microphone, jingles and music beds go out as one
  programme, and the guests come back on their own fader, never fed back to themselves.
- **Karaoke with friends:** a backing track with VOCAL CUT, the singer's microphone with echo.

All three are the same set-up. The person mixing uses AG CuteMusic and Blink; the others join with any SIP client or
from a video room.

## What it does

- AG CuteMusic's mixer is one sound device in Blink, **AG Podcast Mixer**, for both input and output, in the Devices
  menu's combined section (never in the Input, Output or Alert sections; alerts never go to it). It is there whether
  AG CuteMusic runs or not: silent while its mixer is off. Chosen once, left so.
- Every call (1-to-1 SIP, SIP conference, WebRTC video room) then:
  - sends the mix: the microphone or instrument (the MIC strip, with echo if wanted), plus the music, backing track
    or jingles while TO CALLS is on, at the levels of their faders;
  - plays the others in the call (bandmates, guests) into the mixer's **BLINK** strip, heard in the headset with
    its own fader;
  - is set up for music: echo cancelling off, 48 kHz and stereo Opus (music mode) for SIP; stereo, untouched, Opus
    at 128 kbit/s in rooms.
- The others never get their own sound back: what Blink plays never goes into what it sends.
- AG CuteMusic's BLINK strip shows who is in the calls (dialing, ringing, connected since, round trip and loss); its
  END and REDIAL act in Blink.
- Blink's mute mutes the whole mix (it is Blink's microphone); to mute only the voice, mute the MIC strip.

## Audio flow

```
                         AG CuteMusic                                          PipeWire
 mic (pulsesrc) ──► tee ──► the headset (TO AMPLIFIER)
                     └────► LinkSender ─┐ mixed, 5 ms quanta
 music (playbin) ─► volume ─► tee ──► the headset
     (TO CALLS on)            └────► LinkSender ─┤
                                                 ▼ pipewiresink
                                    ag_podcast_mixer_feed (sink)
                                          │ loopback
                                    ag_podcast_mixer (source) ──► Blink records ("AG Podcast Mixer": ALSA PCM
                                                                  ag_cutemusic_mixer for SIP, pipewiresrc in rooms)
                                    ag_podcast_mixer_call (sink) ◄── Blink plays
                                          │ .monitor
 BLINK strip (pulsesrc ! volume ! level) ◄┘ ──► the headset
```

## AG CuteMusic side

- `pipewire/ag-podcast-mixer.conf`, installed in `/usr/share/pipewire/pipewire.conf.d/`: the three nodes, always there
  (read at the next login, or `systemctl --user restart pipewire`).
- `alsa/60-ag-cute-music.conf`, installed in `/etc/alsa/conf.d/`: the ALSA PCM Blink's SIP engine sees (pjmedia has
  only ALSA on Linux), PipeWire's ALSA plugin on `ag_podcast_mixer` and `ag_podcast_mixer_call`, described "AG Podcast
  Mixer" for both directions. Run from the source tree, AG CuteMusic sets the same up in the user's ALSA
  configuration.
- `cutemusic/link.py`: the mix into the Feed (LinkSender, NodeOutput). `cutemusic/bus.py`: the control channel on the
  session bus, `org.agprojects.PodcastMixer` (SetCalls, GetCalls, ShowMixer, the Request signal).

## Blink side

`blink/cutemusic.py`:

- **`running()` / `visible()`:** the device is listed while AG CuteMusic's PipeWire nodes are there (asked of `pactl`,
  at most once a second); `separate()` keeps it out of the separate Input / Output / Alert lists. **`Watcher`:** every
  2 s; when the nodes come or go the device menus are rebuilt.
- **`apply_music_mode()`:** runs when the input device changes. The mixer becomes the input: the current
  echo-cancelling, sample-rate and stereo settings are kept (in `<data>/cutemusic.json`), then echo cancelling off,
  48 kHz, stereo. Another input: they are put back. Preferences show what is in effect.
- **`CallPublisher`:** Blink's calls and rooms to AG CuteMusic (`SetCalls`, the same json as Blink for macOS) on every
  call event and every 2 s; its END (hangup) and REDIAL (`Request`) done here.
- **`open_mixer()`:** the notice's icon: AG CuteMusic's `ShowMixer`, or AG CuteMusic started with `--mixer`.

`blink/webrtc/videoroom.py`: with the mixer chosen, the room records from `pipewiresrc` on `ag_podcast_mixer` and
plays to `pipewiresink` into `ag_podcast_mixer_call`, by node name; otherwise `autoaudiosrc` / `autoaudiosink`. Echo
cancelling and bitrate follow the setting (off: stereo, no `webrtcdsp`, Opus at 128 kbit/s). The room's devices are
chosen when it is joined.

## Setting up a session

1. Put on a headset. With echo cancelling off, speakers would let the others hear themselves through the mic.
2. In AG CuteMusic, View → Mixer, POWER on: choose the headset microphone in INPUT, turn TO CALLS on to send the music.
3. In Blink, Devices → AG Podcast Mixer (once).
4. Call, or join the room. Balance the MIC, BLINK and MUSIC faders.
5. Afterwards, choose the headset (or System default) in Blink again: echo cancelling and the sample rate come back.

## Requirements

- PipeWire with pipewire-pulse, PipeWire's ALSA plugin (`pipewire-alsa`), `pactl` (pulseaudio-utils).
- GStreamer: `pipewiresrc` / `pipewiresink` (gstreamer1.0-pipewire), `pulsesrc`, `audiokaraoke`, `audioecho`, `level`
  (gst-plugins-good).
- PyQt6's QtDBus (python3-pyqt6) on both sides, for the BLINK strip's calls and buttons.

## Known limits and open points

- **Latency, for jamming:** the round trip (network, jitter buffer, 20 ms Opus frames, PipeWire's buffers) is usually
  well over the 25–30 ms musicians can play tightly against. It suits a soloist over a groove or taking turns;
  playing in lockstep needs smaller Opus frames (an SDK change: the conference bridge's ptime), a smaller jitter
  buffer, peers on the same network.
- **Music quality in SIP calls:** stereo Opus in music mode only when the other side asks for stereo
  (`stereo=1`); otherwise mono, speech-tuned.
- **Clipping:** the mix is summed without a limiter; keep the faders so the BLINK strip's party does not hear it
  clip.
- **Qt Multimedia warnings:** "No sample format supported found for device ag_podcast_mixer" in Blink's console: the
  voice-note recorder's device listing, harmless.
- **Single music level:** the music level sent is the local volume. There is no separate send level.
