Skip to content

Commit

Permalink
Merge pull request #4 from mitchmindtree/description_format
Browse files Browse the repository at this point in the history
Move method for returning Format from Reader to Description
  • Loading branch information
mitchmindtree authored Jan 11, 2017
2 parents 17f8a78 + 56d9b15 commit 2530621
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub type BufFileReader = Reader<std::io::BufReader<std::fs::File>>;
/// A description of the audio format that was read from file.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Description {
format: Format,
channel_count: u32,
sample_rate: u32,
}
Expand Down Expand Up @@ -140,6 +141,11 @@ pub fn open<P>(file_path: P) -> Result<BufFileReader, OpenError>

impl Description {

/// The format from which the audio will be read.
pub fn format(&self) -> Format {
self.format
}

/// The number of channels of audio.
///
/// E.g. For audio stored in stereo this should return `2`. Mono audio will return `1`.
Expand Down Expand Up @@ -205,18 +211,6 @@ impl<R> Reader<R>
where R: std::io::Read + std::io::Seek,
{

/// The format from which the audio will be read.
pub fn format(&self) -> Format {
match *self {
#[cfg(feature="flac")]
Reader::Flac(_) => Format::Flac,
#[cfg(feature="ogg_vorbis")]
Reader::OggVorbis(_) => Format::OggVorbis,
#[cfg(feature="wav")]
Reader::Wav(_) => Format::Wav,
}
}

/// A basic description of the audio being read.
pub fn description(&self) -> Description {
match *self {
Expand All @@ -225,6 +219,7 @@ impl<R> Reader<R>
Reader::Flac(ref reader) => {
let info = reader.streaminfo();
Description {
format: Format::Flac,
channel_count: info.channels as u32,
sample_rate: info.sample_rate,
}
Expand All @@ -233,6 +228,7 @@ impl<R> Reader<R>
#[cfg(feature="ogg_vorbis")]
Reader::OggVorbis(ref reader) => {
Description {
format: Format::OggVorbis,
channel_count: reader.ident_hdr.audio_channels as u32,
sample_rate: reader.ident_hdr.audio_sample_rate as u32,
}
Expand All @@ -242,6 +238,7 @@ impl<R> Reader<R>
Reader::Wav(ref reader) => {
let spec = reader.spec();
Description {
format: Format::Wav,
channel_count: spec.channels as u32,
sample_rate: spec.sample_rate,
}
Expand Down

0 comments on commit 2530621

Please sign in to comment.