Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/dev/hal2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ mod host_tests {
let started = Instant::now();
h.apply_dma_enable(0, DMA_EN_CODECA);
std::thread::sleep(Duration::from_millis(800));
let st = h.ca_state.lock().out.as_ref().map(|o| o.stats()).expect("codec A has a host stream");
Device::stop(&h);
let wall = started.elapsed().as_secs_f64();
let moved = dma.at.load(Ordering::Relaxed) as u64 / 2;
Expand All @@ -1284,7 +1285,13 @@ mod host_tests {
// Half at least: a timer held up by a busy host holds the clock back.
assert!(moved as f64 >= 0.5 * wall * 48000.0, "the clock ran: {moved} frames in {wall:.3} s");
let heard = sounding(&pcm, 2);
assert!((heard.len() / 2) as u64 + 9600 >= moved, "{} of {moved} frames reached the file", heard.len() / 2);
// A file thread held up by a busy host (a loaded CI runner) lets the
// queue pass its ceiling, and the stream skips ahead rather than
// play late. Those frames reached the host and were let go on
// purpose; the 200 ms is what was still queued at the stop.
let skipped = st.overruns + st.dropped;
assert!((heard.len() / 2) as u64 + skipped + 9600 >= moved,
"{} of {moved} frames reached the file ({skipped} skipped by the host stream)", heard.len() / 2);
assert_tones(&heard, 2, 48000, left, right, 15000);
}

Expand Down
8 changes: 7 additions & 1 deletion src/dev/mace_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,11 @@ mod tests {
run(300);
let wall = started.elapsed().as_secs_f64();
let moved = a.msc_ust(1) >> 32;
// A file thread held up by a busy host (a loaded CI runner) lets the
// queue pass its ceiling, and the stream skips ahead rather than
// play late. Those pairs reached the host and were let go on
// purpose.
let skipped: u64 = a.player.lock().out.iter().flatten().map(|o| { let s = o.stats(); s.overruns + s.dropped }).sum();
// Dropping the output completes the file.
*a.player.lock() = Player::default();
let (rate, channels, pcm) = read_wav(&path.0);
Expand All @@ -1107,7 +1112,8 @@ mod tests {
// this test from refilling the ring in time.
// The stream also follows the card's clock, by up to 0.5% slower.
let most = loud + loud / 200 + 48 * bursts(&pcm, 2) as u64;
assert!(frames + 9600 >= loud && frames <= most, "{frames} pairs heard of {loud} played before the mute");
assert!(frames + skipped + 9600 >= loud && frames <= most,
"{frames} pairs heard of {loud} played before the mute ({skipped} skipped by the host stream)");
assert_tones(&heard, 2, 48000, left, right, 15000);
}

Expand Down
8 changes: 7 additions & 1 deletion src/dev/rad1/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,10 @@ fn a_tone_in_guest_memory_reaches_the_host_on_the_real_clock() {
Device::stop(&r);
let wall = started.elapsed().as_secs_f64();
let moved = r.state.lock().chan[CH_OUT].frames;
// A file thread held up by a busy host (a loaded CI runner) lets the
// queue pass its ceiling, and the stream skips ahead rather than play
// late. Those frames reached the host and were let go on purpose.
let skipped = r.sink.lock().as_ref().and_then(|sk| sk.host.as_ref()).map_or(0, |o| { let s = o.stats(); s.overruns + s.dropped });
r.sink.lock().take();
let (rate, channels, pcm) = read_wav(&path.0);
assert_eq!((rate, channels), (crate::host_audio::FILE_RATE, 2));
Expand All @@ -1560,7 +1564,9 @@ fn a_tone_in_guest_memory_reaches_the_host_on_the_real_clock() {
// of a stretch of sound: one, or more where a busy host held the card up.
let expect = loud as f64 * 48000.0 / 44100.0;
let most = expect * 1.005 + 48.0 * bursts(&pcm, 2) as f64;
assert!((heard.len() / 2) as f64 >= expect - 9600.0 && (heard.len() / 2) as f64 <= most, "{} frames heard, {expect:.0} played", heard.len() / 2);
let least = expect - skipped as f64 * 48000.0 / 44100.0 - 9600.0;
assert!((heard.len() / 2) as f64 >= least && (heard.len() / 2) as f64 <= most,
"{} frames heard, {expect:.0} played ({skipped} card frames skipped by the host stream)", heard.len() / 2);
assert_tones(&heard, 2, rate, left, right, 15000);
}

Expand Down