From b805af0fdcbda54df657ca9e53a94a04e8b9e2dd Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 29 Apr 2021 00:22:17 -0600 Subject: audio test --- src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e7a11a9..8a3395a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,18 @@ +use std::time::Duration; + +use rodio::{source::SineWave, OutputStream, Sink, Source}; + fn main() { - println!("Hello, world!"); + let (_stream, stream_handle) = OutputStream::try_default().unwrap(); + let sink = Sink::try_new(&stream_handle).unwrap(); + + // Add a dummy source of the sake of the example. + let source = SineWave::new(440) + .take_duration(Duration::from_secs_f32(0.25)) + .amplify(0.20); + sink.append(source); + + // The sound plays in a separate thread. This call will block the current thread until the sink + // has finished playing all its queued sounds. + sink.sleep_until_end(); } -- cgit v1.2.3