Open the recording device only when the game starts microphone capture.

The game opens two input streams while it starts and leaves both stopped through ordinary play, and each open took the system's default recording device and held it, paused, until the game ended: Windows shows the microphone as in use for the whole session, and a Bluetooth headset can drop to its call profile. An open now checks that a default input exists and prepares the stream and its bounded buffer; the device is opened at StartInputStream and released at stop or close, after which the game can still read or purge what was buffered. A start that is refused returns an input error and can be tried again.

tests/audio_input_check.py did not compile on this line (it had no stand-in for the microphone setting); with the change it builds and passes: idle streams hold no device, a refused start can be retried, a stop releases the device and keeps the unread frames, two streams are independent. Not checked with a real microphone in the game.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 22:59:02 -05:00
parent 6750e0bee1
commit 093cf949df
4 changed files with 112 additions and 22 deletions

View File

@@ -4,24 +4,27 @@ The runtime connects Ocarina's polling `nn::audio` input calls to SDL3's default
microphone or audio interface as the operating system's default input and enable the game's microphone control.
Both a hummed note and an instrument received by that input go through the game's own note recognition.
Audio capture opens when the game calls `OpenInputStream` and starts only on `StartInputStream`. The runtime does
not write recordings to disk. SDL converts the input device's format to the requested PCM format and sample rate.
At `OpenInputStream` the runtime checks that a default input exists and prepares a buffer. It opens the recording
device at `StartInputStream` and releases it at stop or close. After a stop, the game can still read or purge the
buffered frames and start capture again. Recordings stay in memory. SDL converts the input device's format to the
requested PCM format and sample rate.
The capture callback uses a bounded ring: unread overflow drops the oldest complete frames instead of retaining
an unlimited recording while the game is paused. Stop, purge and close are distinct operations. Purging an unopened
or failed stream is safe, including the null-stream path that previously crashed in `InputStreamImpl::Purge`.
This implements the non-event polling overload used by Ocarina 1.1.1. Event-based streams, per-device selection,
hot-unplug recovery and packed 24-bit PCM are not implemented. Statistics return a neutral 24-byte structure.
Unsupported formats and a denied or missing recording device return an input error rather than reporting a
successfully opened stream. Input currently follows the operating system's default recording device; there is no
new runtime menu setting.
An unsupported format or missing default device returns an error at open. If the device disappears or access is
denied when capture starts, start returns an input error and the game can retry. Input follows the operating system's
default recording device; there is no new runtime menu setting.
## Validation
`python tests/audio_input_check.py --toolchain C:/msys64/ucrt64` builds and runs headless checks using SDL's dummy
audio driver. They require no game files and do not open a physical microphone. They cover sample ordering across
ring wrap and overflow, frame counts, start/stop, repeated open/close, purge, unsupported formats and purge/read
after a failed open. On Linux, omit `--toolchain` and install SDL3's development package and pkg-config.
audio driver. They require no game files or physical microphone. They check that idle streams leave the device
closed, that a denied start can be retried, and that stopping one stream releases its device and preserves unread
frames. They also cover ring wrap and overflow, frame counts, repeated open/close, unsupported formats and
purge/read after a failed open. On Linux, omit `--toolchain` and install SDL3's development package and pkg-config.
A separate local real-device check received mono signed PCM16 at 48 kHz, verified the 4800-frame ring remained
bounded, and opened and closed the device three times. In an Ocarina 1.1.1 Windows session built from the 0.5.0