feat(audio): capture transactional fixed-rate stereo samples

This commit is contained in:
0xrsydn 2026-10-07 07:16:42 +07:00
commit 902c892d3f
11 changed files with 382 additions and 15 deletions

View file

@ -1,5 +1,7 @@
use std::{cell::Cell, error::Error, fmt};
#[cfg(test)]
mod audio_capture_tests;
#[cfg(test)]
mod audio_step_tests;
#[cfg(test)]
@ -279,6 +281,28 @@ impl Memory {
self.io.audio.level()
}
/// Enable optional 32768 Hz stereo capture. A toggle clears queued frames,
/// resets its synthetic phase/drop counter, and does not reset sound hardware.
/// Call between machine steps. Repeating the current setting preserves state.
pub fn set_audio_capture(&mut self, enabled: bool) {
assert!(
self.timer_step.get().is_none(),
"audio capture configuration during a step"
);
self.io.audio_capture.set_enabled(enabled);
}
/// Drain committed frames, oldest first. Failed steps never publish samples.
/// Each sample is a signed ten-bit digital level, not normalized host PCM.
pub fn drain_audio_samples(&mut self, output: &mut [StereoLevel]) -> usize {
self.io.audio_capture.drain(output)
}
/// Frames discarded because the bounded capture buffers were full.
pub fn audio_dropped_samples(&self) -> u64 {
self.io.audio_capture.dropped
}
fn serial_state(&self) -> Serial {
self.timer_step
.get()