Skip to content

Commit 22d90e7

Browse files
Docs: Added where missing corrected where wrong
Specifically the documentation for - UniformSourceIterator was incomplete it did not mention that it can change the sample type
1 parent 70c236c commit 22d90e7

17 files changed

+98
-44
lines changed

src/decoder/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod mp3;
2323
#[cfg(feature = "symphonia")]
2424
mod read_seek_source;
2525
#[cfg(feature = "symphonia")]
26+
/// Symphonia decoders types
2627
pub mod symphonia;
2728
#[cfg(all(feature = "vorbis", not(feature = "symphonia-vorbis")))]
2829
mod vorbis;
@@ -36,11 +37,15 @@ pub struct Decoder<R>(DecoderImpl<R>)
3637
where
3738
R: Read + Seek;
3839

40+
/// Source of audio samples from decoding a file that never ends. When the
41+
/// end of the file is reached the decoder starts again from the beginning.
42+
///
43+
/// Supports MP3, WAV, Vorbis and Flac.
3944
pub struct LoopedDecoder<R>(DecoderImpl<R>)
4045
where
4146
R: Read + Seek;
4247

43-
// can not really reduce the size of the VorbisDecoder. There are not any
48+
// Cannot really reduce the size of the VorbisDecoder. There are not any
4449
// arrays just a lot of struct fields.
4550
#[allow(clippy::large_enum_variant)]
4651
enum DecoderImpl<R>
@@ -239,6 +244,10 @@ where
239244
#[cfg(not(feature = "symphonia"))]
240245
Err(DecoderError::UnrecognizedFormat)
241246
}
247+
248+
/// Builds a new looped decoder.
249+
///
250+
/// Attempts to automatically detect the format of the source of data.
242251
pub fn new_looped(data: R) -> Result<LoopedDecoder<R>, DecoderError> {
243252
Self::new(data).map(LoopedDecoder::new)
244253
}
@@ -329,6 +338,7 @@ where
329338
}
330339
}
331340

341+
#[allow(missing_docs)] // Reason: will be removed, see: #612
332342
#[derive(Debug)]
333343
pub enum Mp4Type {
334344
Mp4,

src/decoder/symphonia.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,16 @@ impl Source for SymphoniaDecoder {
210210

211211
#[derive(Debug, thiserror::Error)]
212212
pub enum SeekError {
213+
/// Could not get next packet while refining seek position
213214
#[error("Could not get next packet while refining seek position: {0:?}")]
214215
Refining(symphonia::core::errors::Error),
216+
/// Format reader failed to seek
215217
#[error("Format reader failed to seek: {0:?}")]
216218
BaseSeek(symphonia::core::errors::Error),
219+
/// Decoding failed retrying on the next packet failed
217220
#[error("Decoding failed retrying on the next packet failed: {0:?}")]
218221
Retrying(symphonia::core::errors::Error),
222+
/// Decoding failed on multiple consecutive packets
219223
#[error("Decoding failed on multiple consecutive packets: {0:?}")]
220224
Decoding(symphonia::core::errors::Error),
221225
}

src/source/crossfade.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ where
2727
input_fadeout.mix(input_fadein)
2828
}
2929

30+
/// Mixes one sound fading out with another sound fading in for the given
31+
/// duration.
32+
///
33+
/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
34+
/// covered.
3035
pub type Crossfade<I1, I2> = Mix<TakeDuration<I1>, FadeIn<TakeDuration<I2>>>;
3136

3237
#[cfg(test)]

src/source/done.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{Sample, Source};
66

77
use super::SeekError;
88

9-
/// When the inner source is empty this decrements an `AtomicUsize`.
9+
/// When the inner source is empty this decrements a `AtomicUsize`.
1010
#[derive(Debug, Clone)]
1111
pub struct Done<I> {
1212
input: I,
@@ -15,6 +15,8 @@ pub struct Done<I> {
1515
}
1616

1717
impl<I> Done<I> {
18+
/// When the inner source is empty the AtomicUsize passed in is decremented.
19+
/// If it was zero it will overflow negatively.
1820
#[inline]
1921
pub fn new(input: I, signal: Arc<AtomicUsize>) -> Done<I> {
2022
Done {

src/source/empty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ impl<S> Default for Empty<S> {
1717
}
1818

1919
impl<S> Empty<S> {
20+
/// An empty source that immediately ends without ever returning a sample to
21+
/// play
2022
#[inline]
2123
pub fn new() -> Empty<S> {
2224
Empty(PhantomData)

src/source/empty_callback.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ pub struct EmptyCallback<S> {
1313

1414
impl<S> EmptyCallback<S> {
1515
#[inline]
16+
/// Create an empty source which executes a callback function.
17+
/// Example use-case:
18+
///
19+
/// Detect and do something when the source before this one has ended.
1620
pub fn new(callback: Box<dyn Send + Fn()>) -> EmptyCallback<S> {
1721
EmptyCallback {
22+
#[allow(missing_docs)] // See: https://github.com/RustAudio/rodio/issues/615
1823
phantom_data: PhantomData,
24+
#[allow(missing_docs)] // See: https://github.com/RustAudio/rodio/issues/615
1925
callback,
2026
}
2127
}

src/source/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ where
360360
stoppable::stoppable(self)
361361
}
362362

363+
/// Adds a method [`Skippable::skip`] for skipping this source. Skipping
364+
/// makes Source::next() return None. Which in turn makes the Sink skip to
365+
/// the next source.
363366
fn skippable(self) -> Skippable<Self>
364367
where
365368
Self: Sized,
@@ -374,7 +377,7 @@ where
374377
/// in the position returned by [`get_pos`](TrackPosition::get_pos).
375378
///
376379
/// This can get confusing when using [`get_pos()`](TrackPosition::get_pos)
377-
/// together with [`Source::try_seek()`] as the the latter does take all
380+
/// together with [`Source::try_seek()`] as the latter does take all
378381
/// speedup's and delay's into account. Its recommended therefore to apply
379382
/// track_position after speedup's and delay's.
380383
fn track_position(self) -> TrackPosition<Self>
@@ -455,22 +458,32 @@ where
455458

456459
// We might add decoders requiring new error types, without non_exhaustive
457460
// this would break users builds
461+
/// Occurs when try_seek fails because the underlying decoder has an error or
462+
/// does not support seeking.
458463
#[non_exhaustive]
459464
#[derive(Debug, thiserror::Error)]
460465
pub enum SeekError {
461-
#[error("Streaming is not supported by source: {underlying_source}")]
466+
/// On of the underlying sources does not support seeking
467+
#[error("Seeking is not supported by source: {underlying_source}")]
462468
NotSupported { underlying_source: &'static str },
463469
#[cfg(feature = "symphonia")]
470+
/// The symphonia decoder ran into an issue
464471
#[error("Error seeking: {0}")]
465472
SymphoniaDecoder(#[from] crate::decoder::symphonia::SeekError),
466473
#[cfg(feature = "wav")]
467474
#[error("Error seeking in wav source: {0}")]
475+
/// The hound (wav) decoder ran into an issue
468476
HoundDecoder(std::io::Error),
477+
// Prefer adding an enum variant to using this. Its meant for end users their
478+
// own try_seek implementations
479+
/// Any other error probably in a custom Source
469480
#[error("An error occurred")]
470481
Other(Box<dyn std::error::Error + Send>),
471482
}
472483

473484
impl SeekError {
485+
/// Will the source remain playing at its position before the seek or is it
486+
/// broken?
474487
pub fn source_intact(&self) -> bool {
475488
match self {
476489
SeekError::NotSupported { .. } => true,

src/source/pausable.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{Sample, Source};
44

55
use super::SeekError;
66

7-
/// Internal function that builds a `Pausable` object.
7+
/// Builds a `Pausable` object.
88
pub fn pausable<I>(source: I, paused: bool) -> Pausable<I>
99
where
1010
I: Source,
@@ -22,6 +22,12 @@ where
2222
}
2323
}
2424

25+
/// Wraps a source and makes it pausable by calling [`Pausable::set_paused`] on
26+
/// this object. When the source is paused it returns zero value samples.
27+
///
28+
/// You can usually still use this from another source wrapping this one by
29+
/// calling `inner_mut` on it. Similarly this provides [`Pausable::inner`] and
30+
/// mutable/destructing variants for accessing the underlying source.
2531
#[derive(Clone, Debug)]
2632
pub struct Pausable<I> {
2733
input: I,

src/source/position.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn track_position<I>(source: I) -> TrackPosition<I> {
1717
}
1818
}
1919

20+
/// Tracks the elapsed duration since the start of the underlying source.
2021
#[derive(Debug)]
2122
pub struct TrackPosition<I> {
2223
input: I,

src/source/samples_converter.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ use cpal::{FromSample, Sample as CpalSample};
66

77
use super::SeekError;
88

9-
/// An iterator that reads from a `Source` and converts the samples to a specific rate and
10-
/// channels count.
11-
///
12-
/// It implements `Source` as well, but all the data is guaranteed to be in a single frame whose
13-
/// channels and samples rate have been passed to `new`.
9+
/// Wrap the input and lazily converts the samples it provides to the type
10+
/// specified by the generic parameter D
1411
#[derive(Clone)]
1512
pub struct SamplesConverter<I, D> {
1613
inner: I,
1714
dest: PhantomData<D>,
1815
}
1916

2017
impl<I, D> SamplesConverter<I, D> {
18+
/// Wrap the input and lazily converts the samples it provides to the type
19+
/// specified by the generic parameter D
2120
#[inline]
2221
pub fn new(input: I) -> SamplesConverter<I, D> {
2322
SamplesConverter {

0 commit comments

Comments
 (0)