From f73dbe317da029f2131e43ea7a2288da583b70e5 Mon Sep 17 00:00:00 2001 From: ugochukwu-850 Date: Wed, 9 Oct 2024 13:14:23 +0100 Subject: [PATCH] Resolved comments --- src/source/speed.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/source/speed.rs b/src/source/speed.rs index 05383f4b..f4ece9b8 100644 --- a/src/source/speed.rs +++ b/src/source/speed.rs @@ -6,15 +6,15 @@ //! In order to speed up a sink, the speed struct: //! - Increases the current sample rate by the given factor //! - Updates the total duration function to cover for the new factor by dividing by the factor -//! - Update the pos function by multiplying the position by the factor +//! - Updates the try_seek function by multiplying the audio position by the factor //! //! To speed up a source from sink all you need to do is call the `set_speed(factor: f32)` function //! For example, here is how you speed up your sound by using sink or playing raw //! //! ```no_run -//! use std::fs::File; -//! use std::io::BufReader; -//! use rodio::{Decoder, Sink, OutputStream, source::{Source, SineWave}}; +//!# use std::fs::File; +//!# use std::io::BufReader; +//!# use rodio::{Decoder, Sink, OutputStream, source::{Source, SineWave}}; //! //! // Get an output stream handle to the default physical sound device. //! // Note that no sound will be played if _stream is dropped @@ -25,25 +25,23 @@ //! let source = Decoder::new(file).unwrap(); //! // Play the sound directly on the device 2x faster //! stream_handle.play_raw(source.convert_samples().speed(2.0)); -//! -//! // The sound plays in a separate audio thread, -//! // so we need to keep the main thread alive while it's playing. -//! std::thread::sleep(std::time::Duration::from_secs(5)); -//! -//! // here is how you would do it using the sink -//! +//! std::thread::sleep(std::time::Duration::from_secs(5)); +//! ``` +//! here is how you would do it using the sink +//! ``` //! let source = SineWave::new(440.0) //! .take_duration(Duration::from_secs_f32(20.25)) //! .amplify(0.20); //! -//! //! let sink = Sink::try_new(&stream_handle)?; +//! let sink = Sink::try_new(&stream_handle)?; //! sink.set_speed(2.0); //! sink.append(source); //! std::thread::sleep(std::time::Duration::from_secs(5)); //! ``` //! Notice the increase in pitch as the factor increases -//! This is due to the higher audio data stream increasing the frequency +//! +//! Since the samples are played faster the audio wave get shorter increasing their frequencies use std::time::Duration;