Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 59 additions & 17 deletions packaging/pipewire/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,63 @@ remain `no_std`; the existing LV2 host shim uses `std` for non-RT loading.
All chain storage is allocated before `run()`, which chunks host callbacks
into at most 512 frames without allocation, locks, file I/O or logging.

## Built-in microphone (example)

`examples/sgv2-mic-capture.conf.example` is an example, not a generated
file: a capture filter-chain around the `#mic-{1,2,3,4}ch` plugin
(`crates/sgv2-lv2/src/mic.rs`) that publishes the processed channel as the
virtual source "Built-in Microphone" and leaves the raw capture node in
place. The plugin loads `$SGV2_MIC_PARAMS`, else
`/run/speakerguardd/mic.bin`, written by
`aurora-speaker-tuning mic-compile` from the Mac's own bundle; a blob for
another board, rate or microphone count gives silence and health 1. The
compile refuses (no blob) when a stage is not characterised;
`--allow-partial` carries the stages documented as transparent or
attenuating as identity and flags the blob partial. Session wiring,
provisioning and WirePlumber priorities are not part of this example.
The artifact is versioned and the plugin refuses another version (a
## Built-in microphone

`sgv2-mic-<machine>.conf` (and `../wireplumber/61-sgv2-mic-<machine>.conf`)
are generated by `gen.py` for every fixture whose device tree has a
microphone array (the fixture's `mic`: the AOP audio node that lists the
array's stream; `wiring.read_mic_dt`, `wiring.describe_mic`). Each holds:
- the array's capture PCM as an ALSA source of sgv2's own
(`hw:CARD=<card>,DEV=<n>`, "Microphone Array (raw channels)", priority
100): listed for applications that want the channels, never the default
while another source exists;
- a capture filter-chain around the `#mic-<n>ch` plugin
(`crates/sgv2-lv2/src/mic.rs`) that publishes the processed channel as the
source "Built-in Microphone" (priority 2005, the priority asahi-audio gives
its own microphone filter, so its headset rules still sit above it).

They are never installed statically. `speakerguardd-provision run` writes
them into `/run/speakerguardd-graph/mic/` from the live device tree and
card, after the speaker steps and apart from them, only when all of this
holds, and removes them (and the blob) otherwise:
- `aurora-speaker-tuning mic-compile` compiled this Mac's own bundle
**without** `--allow-partial` into `/var/lib/speakerguardd/mic.bin`
(bound in `mic.bind` to the board, the unit, the bundle's digest, the
compiler and the blob version; any change compiles again, so a blob of
an older version is never kept);
- the blob's header names this board, the array's rate and microphone
count, the version the plugin takes, and no partial flag;
- the packaged plugin, loaded as a host loads it, runs the blob with
health 0 (`speakerguardd-selfcheck mic`).

The blob is then published as `/run/speakerguardd/mic.bin`, where the plugin
reads it (else `$SGV2_MIC_PARAMS`). The seat user's
`speakerguardd-graph.service` links both files or neither.

**With asahi-audio.** asahi-audio attaches its microphone filter to
WirePlumber's own node for the array (`node.software-dsp.rules` matching
`api.alsa.path = "hw:<card>,<n>"`, `hide-parent`). The WirePlumber file
disables that node, so that filter is not created while sgv2's graph is
linked, and sgv2's own ALSA node (`hw:CARD=...`) matches none of its rules.
Without sgv2's files (no array, a refused or partial design, a blob the
plugin does not run, another user's session, a boot without provisioning)
nothing of this is linked and asahi-audio's microphone filter is as it was.
The states:

| state | "Built-in Microphone" | raw array |
|---|---|---|
| blob valid, files linked | sgv2's processed source (default input) | sgv2's ALSA source, priority 100 |
| mic refused / absent / not the seat user | asahi-audio's filter, as before | hidden behind it, as before |
| files linked but the filter-chain or plugin fails to load | none (the module is `nofail`) | sgv2's ALSA source becomes the default input |

`speakerguardd-selfcheck mic` (also reported by `verify`, beside the
speakers' result and never part of it) gives the verdict: `pass`, `absent`
or `refused` with the reasons. `/var/lib/speakerguardd/mic.json` is
provisioning's record.

`examples/sgv2-mic-capture.conf.example` remains a hand-editable example of
the same filter-chain for development. The
artifact is versioned and the plugin refuses another version (a
version-1 blob from the first mic release gives silence and health 1 with
the current plugin), so whatever provisions the blob must recompile it
when the plugin changes instead of keeping a stale one.
the current plugin), which is why provisioning binds the version and
compiles again when it changes.
76 changes: 76 additions & 0 deletions packaging/pipewire/sgv2-mic-j293.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by packaging/session/gen.py from fixtures/j293.json; do not edit.
# speakerguardd v2: the built-in microphone of the J293, processed with the Mac's own tuning.

context.objects = [
{ factory = adapter
flags = [ nofail ]
args = {
factory.name = api.alsa.pcm.source
node.name = "sgv2.mic.raw.j293"
node.description = "Microphone Array (raw channels)"
media.class = "Audio/Source"
# The same PCM as hw:AppleJ293HPAI,0, under the name no
# asahi-audio rule matches (WirePlumber's own node for it is
# disabled while this file is linked).
api.alsa.path = "hw:CARD=AppleJ293HPAI,DEV=0"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
# Listed, never the default while any other source exists.
priority.driver = 100
priority.session = 100
channelmix.disable = true
monitor.channel-volumes = false
device.icon-name = "audio-input-microphone"
}
}
]

context.modules = [
{ name = libpipewire-module-filter-chain
flags = [ nofail ]
args = {
node.description = "Built-in Microphone"
media.name = "Built-in Microphone"
filter.graph = {
nodes = [
{ type = lv2 name = mic plugin = "https://aurora-silicon.org/lv2/sgv2#mic-3ch" }
]
inputs = [ "mic:in_0" "mic:in_1" "mic:in_2" ]
outputs = [ "mic:out" ]
}
# The blob is for this rate only (the plugin is silent at any
# other): both streams stay at it, and their converters
# resample when the graph runs at another rate.
capture.props = {
node.name = "sgv2.mic.j293.in"
node.description = "Built-in Microphone input (internal)"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
target.object = "sgv2.mic.raw.j293"
# Only ever the array: never moved to another source.
node.dont-fallback = true
node.passive = true
stream.dont-remix = true
sgv2.stage = "mic"
sgv2.machine = "j293"
}
playback.props = {
node.name = "sgv2.mic.j293"
node.description = "Built-in Microphone"
media.class = "Audio/Source"
audio.rate = 48000
audio.channels = 1
audio.position = [ MONO ]
priority.driver = 2005
priority.session = 2005
node.passive = true
node.virtual = false
device.icon-name = "audio-input-microphone"
sgv2.stage = "mic"
sgv2.machine = "j293"
}
}
}
]
76 changes: 76 additions & 0 deletions packaging/pipewire/sgv2-mic-j313.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by packaging/session/gen.py from fixtures/j313.json; do not edit.
# speakerguardd v2: the built-in microphone of the J313, processed with the Mac's own tuning.

context.objects = [
{ factory = adapter
flags = [ nofail ]
args = {
factory.name = api.alsa.pcm.source
node.name = "sgv2.mic.raw.j313"
node.description = "Microphone Array (raw channels)"
media.class = "Audio/Source"
# The same PCM as hw:AppleJ313HPAI,0, under the name no
# asahi-audio rule matches (WirePlumber's own node for it is
# disabled while this file is linked).
api.alsa.path = "hw:CARD=AppleJ313HPAI,DEV=0"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
# Listed, never the default while any other source exists.
priority.driver = 100
priority.session = 100
channelmix.disable = true
monitor.channel-volumes = false
device.icon-name = "audio-input-microphone"
}
}
]

context.modules = [
{ name = libpipewire-module-filter-chain
flags = [ nofail ]
args = {
node.description = "Built-in Microphone"
media.name = "Built-in Microphone"
filter.graph = {
nodes = [
{ type = lv2 name = mic plugin = "https://aurora-silicon.org/lv2/sgv2#mic-3ch" }
]
inputs = [ "mic:in_0" "mic:in_1" "mic:in_2" ]
outputs = [ "mic:out" ]
}
# The blob is for this rate only (the plugin is silent at any
# other): both streams stay at it, and their converters
# resample when the graph runs at another rate.
capture.props = {
node.name = "sgv2.mic.j313.in"
node.description = "Built-in Microphone input (internal)"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
target.object = "sgv2.mic.raw.j313"
# Only ever the array: never moved to another source.
node.dont-fallback = true
node.passive = true
stream.dont-remix = true
sgv2.stage = "mic"
sgv2.machine = "j313"
}
playback.props = {
node.name = "sgv2.mic.j313"
node.description = "Built-in Microphone"
media.class = "Audio/Source"
audio.rate = 48000
audio.channels = 1
audio.position = [ MONO ]
priority.driver = 2005
priority.session = 2005
node.passive = true
node.virtual = false
device.icon-name = "audio-input-microphone"
sgv2.stage = "mic"
sgv2.machine = "j313"
}
}
}
]
76 changes: 76 additions & 0 deletions packaging/pipewire/sgv2-mic-j316.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by packaging/session/gen.py from fixtures/j316.json; do not edit.
# speakerguardd v2: the built-in microphone of the J316, processed with the Mac's own tuning.

context.objects = [
{ factory = adapter
flags = [ nofail ]
args = {
factory.name = api.alsa.pcm.source
node.name = "sgv2.mic.raw.j316"
node.description = "Microphone Array (raw channels)"
media.class = "Audio/Source"
# The same PCM as hw:AppleJ316HPAI,0, under the name no
# asahi-audio rule matches (WirePlumber's own node for it is
# disabled while this file is linked).
api.alsa.path = "hw:CARD=AppleJ316HPAI,DEV=0"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
# Listed, never the default while any other source exists.
priority.driver = 100
priority.session = 100
channelmix.disable = true
monitor.channel-volumes = false
device.icon-name = "audio-input-microphone"
}
}
]

context.modules = [
{ name = libpipewire-module-filter-chain
flags = [ nofail ]
args = {
node.description = "Built-in Microphone"
media.name = "Built-in Microphone"
filter.graph = {
nodes = [
{ type = lv2 name = mic plugin = "https://aurora-silicon.org/lv2/sgv2#mic-3ch" }
]
inputs = [ "mic:in_0" "mic:in_1" "mic:in_2" ]
outputs = [ "mic:out" ]
}
# The blob is for this rate only (the plugin is silent at any
# other): both streams stay at it, and their converters
# resample when the graph runs at another rate.
capture.props = {
node.name = "sgv2.mic.j316.in"
node.description = "Built-in Microphone input (internal)"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
target.object = "sgv2.mic.raw.j316"
# Only ever the array: never moved to another source.
node.dont-fallback = true
node.passive = true
stream.dont-remix = true
sgv2.stage = "mic"
sgv2.machine = "j316"
}
playback.props = {
node.name = "sgv2.mic.j316"
node.description = "Built-in Microphone"
media.class = "Audio/Source"
audio.rate = 48000
audio.channels = 1
audio.position = [ MONO ]
priority.driver = 2005
priority.session = 2005
node.passive = true
node.virtual = false
device.icon-name = "audio-input-microphone"
sgv2.stage = "mic"
sgv2.machine = "j316"
}
}
}
]
76 changes: 76 additions & 0 deletions packaging/pipewire/sgv2-mic-j413.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by packaging/session/gen.py from fixtures/j413.json; do not edit.
# speakerguardd v2: the built-in microphone of the J413, processed with the Mac's own tuning.

context.objects = [
{ factory = adapter
flags = [ nofail ]
args = {
factory.name = api.alsa.pcm.source
node.name = "sgv2.mic.raw.j413"
node.description = "Microphone Array (raw channels)"
media.class = "Audio/Source"
# The same PCM as hw:AppleJ413HPAI,0, under the name no
# asahi-audio rule matches (WirePlumber's own node for it is
# disabled while this file is linked).
api.alsa.path = "hw:CARD=AppleJ413HPAI,DEV=0"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
# Listed, never the default while any other source exists.
priority.driver = 100
priority.session = 100
channelmix.disable = true
monitor.channel-volumes = false
device.icon-name = "audio-input-microphone"
}
}
]

context.modules = [
{ name = libpipewire-module-filter-chain
flags = [ nofail ]
args = {
node.description = "Built-in Microphone"
media.name = "Built-in Microphone"
filter.graph = {
nodes = [
{ type = lv2 name = mic plugin = "https://aurora-silicon.org/lv2/sgv2#mic-3ch" }
]
inputs = [ "mic:in_0" "mic:in_1" "mic:in_2" ]
outputs = [ "mic:out" ]
}
# The blob is for this rate only (the plugin is silent at any
# other): both streams stay at it, and their converters
# resample when the graph runs at another rate.
capture.props = {
node.name = "sgv2.mic.j413.in"
node.description = "Built-in Microphone input (internal)"
audio.rate = 48000
audio.channels = 3
audio.position = [ AUX0 AUX1 AUX2 ]
target.object = "sgv2.mic.raw.j413"
# Only ever the array: never moved to another source.
node.dont-fallback = true
node.passive = true
stream.dont-remix = true
sgv2.stage = "mic"
sgv2.machine = "j413"
}
playback.props = {
node.name = "sgv2.mic.j413"
node.description = "Built-in Microphone"
media.class = "Audio/Source"
audio.rate = 48000
audio.channels = 1
audio.position = [ MONO ]
priority.driver = 2005
priority.session = 2005
node.passive = true
node.virtual = false
device.icon-name = "audio-input-microphone"
sgv2.stage = "mic"
sgv2.machine = "j413"
}
}
}
]
Loading
Loading