Directories | |
| capture | |
| music_analysis | |
The audio controller provides a common interface for controlling system audio output.
Audio applications and input components can use the audio controller without depending directly on a specific operating system audio implementation.
| Component | Description |
|---|---|
| AudioControllerIf | Defines the common audio control interface. |
| PipewireAudioController | Controls PipeWire audio output using wpctl. |
| PactlAudioController | Controls a Linux development host through pactl. |
| AudioControllerStub | Provides deterministic in-memory audio state. |
| UnconfiguredAudioController | Reports unavailable audio configuration. |
The audio controller provides:
AudioControllerIf defines the common audio control interface.
Implementations provide:
Higher-level components should depend on AudioControllerIf rather than a specific audio implementation.
AudioControllerStub is intended for demos and UI development. It keeps volume and mute state in memory without accessing host audio.
UnconfiguredAudioController reports is_available == False, exposes a configuration reason through status_message, and raises RuntimeError for audio operations rather than returning fabricated system state.
Example:
PipewireAudioController controls the default PipeWire audio sink using wpctl.
Car UI selects the implementation at runtime. Native Raspberry Pi 4 and Pi 5 targets use PipewireAudioController; linux-dev hosts use PactlAudioController. Set OPENROAD_RUNTIME_TARGET to linux-dev, rpi4, or rpi5 only when an explicit override is needed for testing or deployment. With audio.output = "auto", Pi 4 prefers its onboard analog sink and Pi 5 prefers a USB audio sink. Set audio.device_match in config/runtime.toml to select a particular adapter by a stable portion of its PipeWire description.
The controller operates on:
This allows the operating system to determine the active audio output device. Relative volume increases pass a 1.0 limit to wpctl, preventing software amplification above 100%.
Example:
The PipeWire controller exposes system volume as discrete levels.
By default:
This produces levels from:
where:
Volume-up operations clamp at 100%; further clockwise encoder steps leave the system at level 20 rather than enabling PipeWire amplification.
Mute is controlled with wpctl set-mute ... toggle. toggle_mute() returns the resulting state so application widgets can update immediately.
The number of levels can be configured:
adjust_volume() changes the current volume by a number of discrete steps.
Example:
Increase volume by one level.
Decrease volume by one level.
Multiple steps may be applied at once:
This is useful for input devices that report relative movement, such as rotary encoders.
Example:
The PipeWire implementation requires wpctl.
Verify that wpctl is available:
The active audio sink can be inspected using:
Current volume can be read using:
A CLI component test is provided.
Run from the project root:
Available commands:
Example session:
The Car UI reserves one configured rotary encoder for global system volume. The input router depends on RotaryEncoderIf and invokes the audio controller's volume_up() or volume_down() operation for each signed encoder step:
The encoder driver and volume device index are configured in config/runtime.toml. Neither AudioControllerIf nor PipewireAudioController depends on Seesaw addresses or GPIO pins.
Test the real configured volume knob and default PipeWire sink with:
This test starts only the configured volume device. Other configured encoders may be disconnected without preventing the volume test from running. It reports 20 levels by default, matching the controller's 5% PipeWire step. The Car UI theme's eight volume bars are a visual scale rather than the audio controller's native resolution.
VolumeManager maps the controller range proportionally onto that visual scale:
Positive nonzero audio levels display at least one bar. Encoder events and top-bar volume buttons use the same mapping.
Pressing the configured volume encoder calls AudioControllerIf.toggle_mute(). While muted, the top bar renders all eight bars in red. The underlying volume level is retained and displayed again when the encoder is pressed to unmute.
The audio controller represents system audio control behavior.
Higher-level components interact with AudioControllerIf and do not need to know how system volume is controlled.
Concrete implementations are responsible for interacting with the underlying audio system.
For example:
This allows additional audio controller implementations to be added without changing components that use audio control.
Possible implementations may include:
Operating system and audio-system-specific behavior remains inside the concrete audio controller implementation.