-
Notifications
You must be signed in to change notification settings - Fork 236
/
basic.rs
54 lines (46 loc) · 1.38 KB
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use rodio::source::SineWave;
use rodio::Source;
use std::error::Error;
use std::io::BufReader;
use std::thread;
use std::time::Duration;
#[cfg(feature = "tracing")]
use tracing;
fn main() -> Result<(), Box<dyn Error>> {
let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?;
let mixer = stream_handle.mixer();
let beep1 = {
// Play a WAV file.
let file = std::fs::File::open("assets/beep.wav")?;
let sink = rodio::play(&mixer, BufReader::new(file))?;
sink.set_volume(0.2);
sink
};
println!("Started beep1");
thread::sleep(Duration::from_millis(1500));
{
// Generate sine wave.
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 = {
// Play an OGG file.
let file = std::fs::File::open("assets/beep3.ogg")?;
let sink = rodio::play(&mixer, BufReader::new(file))?;
sink.set_volume(0.2);
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");
thread::sleep(Duration::from_millis(1500));
Ok(())
}