agrippa-stereocam

Focus Audio

The focus command includes an operator-feedback audio path built on SDL2’s procedural audio support.

Purpose

The audio path exists so an operator can align lenses without continuously watching the screen.

Operating modes

There are two modes:

  1. Convergence mode while left and right focus scores differ
  2. Locked mode once the mismatch remains below threshold for a stable interval

Convergence mode

The design uses a stereo beating tone:

This creates audible beating that slows as alignment improves.

Frequency offset mapping

Map focus mismatch to frequency difference:

float normalized_delta = clamp(delta / delta_scale, -1.0f, 1.0f);
float freq_offset = normalized_delta * 30.0f;  // +/-30 Hz max

Optional amplitude scaling

float convergence = 1.0f - fabs(normalized_delta);
float amplitude = base_amp * (0.5f + 0.5f * convergence);

Keep subtle. Beating clarity is more important than loudness variation.


Lock detection

Lock when:

fabs(normalized_delta) < 0.03f

The threshold must hold continuously for >= 1.0 seconds. Reset the timer immediately if the threshold is exceeded.


Locked mode

When locked:

Beep characteristics

This produces a clean metrology-style confirmation cue.


SDL2 audio implementation

Audio format

Architecture

Use SDL2 procedural audio via callback:

Shared state

Main thread:

Audio thread:

Frequency smoothing

To avoid zipper noise:

current_offset += 0.02f * (target_offset - current_offset);

UX goals

The sound should be:


Implementation

The logic is encapsulated in focus_audio.c / focus_audio.h, exposing:

focus_audio_init()
focus_audio_update_delta(float normalized_delta)
focus_audio_shutdown()

This keeps the focus command logic clean and readable.