2024-11-09 22:34:49 +00:00
|
|
|
use rodio::source::SineWave;
|
|
|
|
use rodio::Source;
|
2015-09-10 14:38:16 +00:00
|
|
|
use std::io::BufReader;
|
2016-10-04 14:36:11 +00:00
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
2015-09-10 14:38:16 +00:00
|
|
|
|
2015-07-22 10:14:11 +00:00
|
|
|
fn main() {
|
2024-11-09 20:10:36 +00:00
|
|
|
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()
|
|
|
|
.expect("open default audio stream");
|
|
|
|
let mixer = stream_handle.mixer();
|
|
|
|
|
2024-11-09 22:34:49 +00:00
|
|
|
let beep1 = {
|
2024-11-09 20:10:36 +00:00
|
|
|
let file = std::fs::File::open("assets/beep.wav").unwrap();
|
|
|
|
let sink = rodio::play(&mixer, BufReader::new(file)).unwrap();
|
|
|
|
sink.set_volume(0.2);
|
2024-11-09 22:34:49 +00:00
|
|
|
sink
|
|
|
|
};
|
|
|
|
println!("Started beep1");
|
|
|
|
thread::sleep(Duration::from_millis(1500));
|
|
|
|
|
2024-11-09 20:10:36 +00:00
|
|
|
{
|
2024-11-09 22:34:49 +00:00
|
|
|
let wave = SineWave::new(740.0)
|
|
|
|
.amplify(0.2)
|
|
|
|
.take_duration(Duration::from_secs(3));
|
|
|
|
mixer.add(wave);
|
|
|
|
}
|
|
|
|
println!("Started beep2");
|
|
|
|
thread::sleep(Duration::from_millis(1500));
|
|
|
|
|
|
|
|
let beep3 = {
|
|
|
|
let file = std::fs::File::open("assets/beep3.ogg").unwrap();
|
2024-11-09 20:10:36 +00:00
|
|
|
let sink = rodio::play(&mixer, BufReader::new(file)).unwrap();
|
|
|
|
sink.set_volume(0.2);
|
2024-11-09 22:34:49 +00:00
|
|
|
sink
|
|
|
|
};
|
|
|
|
println!("Started beep3");
|
|
|
|
thread::sleep(Duration::from_millis(1500));
|
|
|
|
|
|
|
|
drop(beep1);
|
|
|
|
println!("Stopped beep1");
|
|
|
|
|
|
|
|
thread::sleep(Duration::from_millis(1500));
|
|
|
|
drop(beep3);
|
|
|
|
println!("Stopped beep3");
|
2024-11-09 20:10:36 +00:00
|
|
|
|
2024-11-09 22:34:49 +00:00
|
|
|
thread::sleep(Duration::from_millis(1500));
|
2015-07-22 10:14:11 +00:00
|
|
|
}
|