Add Samples::convert_samples()

This commit is contained in:
Pierre Krieger 2017-05-01 11:05:00 +02:00
parent cbecbc8093
commit 634d6bafaa
2 changed files with 13 additions and 1 deletions

View file

@ -10,17 +10,21 @@
//! [`get_default_endpoint`](fn.get_default_endpoint.html) functions.
//! - Call [`play_raw(output, source)`](fn.play_raw.html).
//!
//! The `play_raw` function expects the source to produce `f32`s, which may not be the case. If you
//! get a compilation error, try calling `.convert_samples()` on the source to fix it.
//!
//! For example, here is how you would play an audio file:
//!
//! ```no_run
//! use std::fs::File;
//! use std::io::BufReader;
//! use rodio::Source;
//!
//! let endpoint = rodio::get_default_endpoint().unwrap();
//!
//! let file = File::open("sound.ogg").unwrap();
//! let source = rodio::Decoder::new(BufReader::new(file)).unwrap();
//! rodio::play_raw(&endpoint, source);
//! rodio::play_raw(&endpoint, source.convert_samples());
//! ```
//!
//! ## Sink

View file

@ -218,4 +218,12 @@ pub trait Source: Iterator
let echo = self.clone().amplify(amplitude).delay(duration);
self.mix(echo)
}
/// Converts the samples of this source to another type.
#[inline]
fn convert_samples<D>(self) -> SamplesConverter<Self, D>
where Self: Sized, D: Sample
{
SamplesConverter::new(self)
}
}