Skip to content

Commit

Permalink
Resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ugochukwu-850 committed Oct 9, 2024
1 parent 5c893cf commit f73dbe3
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/source/speed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit f73dbe3

Please sign in to comment.