hex/src/audio
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Dax d8159610dd
audio: keep overload reporting off CoreAudio's real-time thread (#1643)
* audio: count microphone overloads on the realtime thread, log them coalesced

CoreAudio reports kAudioDeviceProcessorOverload as ErrorKind::Xrun from its
real-time thread. Hex's handler ran tracing::warn! there (formatting plus a
blocking write to stderr and process.log behind a mutex) and locked
STREAM_GLITCHED_AT, once per overload, hundreds of times a day, on a thread
that had already missed its cycle.

The error callback now only moves atomics (a total, a refused real-time
promotion count, and the last overload time against a clock taken before the
stream runs). AudioInput::recv_timeout, the poll that drains the stream for
dictation and meetings, reports them: one line per burst with count and
realtime_denied, at most every 10 s, and the count a throttled poll holds back
is taken by the next one rather than lost. since_last_stream_glitch keeps its
signature and semantics from the same counters.

On macOS the first chunk of each open also logs the callback's frames and
period, since cpal exposes no readback for BufferSize::Default and overloads
arrive sooner on a smaller hardware period. No FFI or unsafe was added.

Moved the counters into audio/overloads.rs to keep audio.rs under the
1,500-line shape limit.

* audio: write a closing stream's leftover overloads, and stop calling them CoreAudio's

Review follow-ups to the coalesced overload log:

- impl Drop for AudioInput drops the stream first, so no callback races, then
  overloads::flush writes any count the 10 s window still held. Without it, a
  burst left over at close surfaced on the next open, hours later, next to
  "microphone stream opened" and read as a cold-start burst. Flush is
  swap-based and skips the rate limit; nothing pending costs one atomic load,
  and the fixture and test inputs (no stream) drop as before.
- cpal 0.18 emits RealtimeDenied only from the aaudio and jack hosts, so the
  separate REALTIME_DENIED counter and the realtime_denied log field are gone:
  record() takes no argument and both kinds just count. Comments and docs no
  longer call these CoreAudio's overloads, since the poll reports any host's.
- now_nanos reads the clock cell before Instant::now, so a first-ever record
  cannot land on the 0 that means never.
- report_period skips HEX_AUDIO_FIXTURE, whose chunks are the file's rather
  than a device's, and says so.

docs/features/recovery.md gains the close-time flush and uses the "Changed
after dev" heading; the unsupported "hundreds a day" claim is gone.

* audio: clamp the overload clock reading to at least one

get_or_init(Instant::now) and the next Instant::now() can return the same
tick on Apple Silicon and Windows, so a first-ever reading could still be 0,
the sentinel for "never". now_nanos returns at least 1, and the GLITCHED_AT
doc says the reading is clamped rather than merely later than the clock.
2026-11-10 13:17:35 -05:00
..
hex_microphone Extract macos_hal and pipewire_source from audio/hex_microphone.rs 2026-10-31 18:57:51 -07:00
recording_environment Fold audio and recording-environment modules into audio/ 2026-10-31 16:12:40 -07:00
browser_media.rs Fold audio and recording-environment modules into audio/ 2026-10-31 16:12:40 -07:00
call_input.rs Meetings: record the input the call app uses (#1086) (#1091) 2026-11-03 00:14:23 -05:00
fixture.rs audio: keep overload reporting off CoreAudio's real-time thread (#1643) 2026-11-10 13:17:35 -05:00
hex_microphone.rs Extract macos_hal and pipewire_source from audio/hex_microphone.rs 2026-10-31 18:57:51 -07:00
idle_sleep.rs Fold audio and recording-environment modules into audio/ 2026-10-31 16:12:40 -07:00
input_format.rs windows: go back to cpal first, with the direct wasapi paths as fallback (revert #1279) (#1365) 2026-11-05 03:14:15 -05:00
input_level.rs fix: ignore microphone dc offset in level meters (#1560) 2026-11-08 17:41:24 -05:00
instant.rs Extract instant and lid from audio.rs 2026-10-31 18:57:51 -07:00
lid.rs Extract instant and lid from audio.rs 2026-10-31 18:57:51 -07:00
mix_format.rs windows: try iaudioclient3, interface activation and auto-convert wasapi paths (#1270) 2026-11-04 08:49:05 -05:00
output_ducking.rs lower audio faster and drop duck pre-roll (#1482) 2026-11-07 05:11:08 -05:00
output_route.rs labs: apply While dictating only on speakers (#1610) 2026-11-09 20:24:42 -05:00
overloads.rs audio: keep overload reporting off CoreAudio's real-time thread (#1643) 2026-11-10 13:17:35 -05:00
recording_environment.rs labs: apply While dictating only on speakers (#1610) 2026-11-09 20:24:42 -05:00
transport.rs Fix #1100: automatic microphone fallback selection (#1184) 2026-11-03 14:56:13 -05:00
voice_filter.rs Fold audio and recording-environment modules into audio/ 2026-10-31 16:12:40 -07:00
wasapi_capture.rs windows: go back to cpal first, with the direct wasapi paths as fallback (revert #1279) (#1365) 2026-11-05 03:14:15 -05:00