From 094dbef0e47a2eceb9d74678aa4dc1f8722c833d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 17 Dec 2014 09:13:58 +0100 Subject: [PATCH] Add some documentation --- src/lib.rs | 14 +++++++++----- src/samples_formats.rs | 8 +++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1786d8d..c5337b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![feature(macro_rules)] #![feature(unsafe_destructor)] +#![unstable] #[cfg(all(not(windows), not(unix)))] use this_platform_is_not_supported; @@ -11,15 +12,17 @@ mod samples_formats; #[cfg(unix)] #[path="alsa/mod.rs"] -pub mod cpal_impl; +mod cpal_impl; #[cfg(windows)] #[path="wasapi/mod.rs"] -pub mod cpal_impl; +mod cpal_impl; -/// A `Channel` represents a sound output. +/// Controls a sound output. /// -/// A channel must be periodically filled with new data, or the sound will -/// stop playing. +/// Create one `Channel` for each sound that you want to play. +/// +/// A channel must be periodically filled with new data by calling `append_data`, or the sound +/// will stop playing. pub struct Channel(cpal_impl::Channel); /// Number of channels. @@ -50,6 +53,7 @@ struct RequiredConversion { } impl Channel { + /// Builds a new channel. pub fn new() -> Channel { let channel = cpal_impl::Channel::new(); Channel(channel) diff --git a/src/samples_formats.rs b/src/samples_formats.rs index 63d5950..dd4c6f1 100644 --- a/src/samples_formats.rs +++ b/src/samples_formats.rs @@ -8,10 +8,12 @@ pub enum SampleFormat { I16, /// The value 0 corresponds to 32768. U16, + /// The boundaries are (-1.0, 1.0). F32, } impl SampleFormat { + /// Returns the size in bytes of a sample of this format. pub fn get_sample_size(&self) -> uint { match self { &SampleFormat::I16 => mem::size_of::(), @@ -26,11 +28,11 @@ impl SampleFormat { pub trait Sample: Copy { fn get_format(Option) -> SampleFormat; - /// Turns the data into a `Vec` where each element is a sample. + /// Turns the data into samples of type `I16`. fn to_vec_i16(&[Self]) -> Cow, [i16]>; - /// Turns the data into a `Vec` where each element is a sample. + /// Turns the data into samples of type `U16`. fn to_vec_u16(&[Self]) -> Cow, [u16]>; - /// Turns the data into a `Vec` where each element is a sample. + /// Turns the data into samples of type `F32`. fn to_vec_f32(&[Self]) -> Cow, [f32]>; }