39 lines
1.3 KiB
Plaintext
39 lines
1.3 KiB
Plaintext
#! Contains the tests of `audio_output`: one of no device, mixed as the test
|
|
#! asks, and the system's default device, where there is one.
|
|
|
|
import std::testing;
|
|
import std::thread;
|
|
import std::time;
|
|
import malunal::audio;
|
|
|
|
@test def mixes_for_no_device_as_asked(t: &mut tester): void {
|
|
var out := audio_output::headless(44100);
|
|
t.expects(!out.has_device && out.rate() == 44100);
|
|
val id := out.add(sound::tone(440, 0.1, 44100));
|
|
val v := out.play(id, playback{ pan = -1 });
|
|
var frames := vector::<f32>::new();
|
|
frames.resize(2 * 441);
|
|
out.render(frames.slice());
|
|
t.expects(out.played == 441 && frames[2 * 200] != 0 && frames[2 * 200 + 1] == 0);
|
|
t.expects(out.playing(v));
|
|
out.stop(v);
|
|
t.expects(!out.playing(v));
|
|
}
|
|
|
|
@test def plays_to_the_default_device_where_there_is_one(t: &mut tester): void {
|
|
var out := audio_output::open() else (e) {
|
|
# A machine of no audio device, as a build server, passes.
|
|
t.expects(e == audio_error::no_device);
|
|
return;
|
|
};
|
|
t.expects(out.has_device && out.rate() >= 8000);
|
|
# Silent, so the test isn't heard.
|
|
val id := out.add(sound::tone(440, 0.05, out.rate(), 0));
|
|
_ = out.play(id);
|
|
val started := time::instant::now();
|
|
while out.played < 2000 && started.elapsed().compare(&time::seconds(2)) < 0 {
|
|
thread::sleep(time::milliseconds(10));
|
|
}
|
|
t.expects(out.played >= 2000);
|
|
}
|