pub struct FlacChannelReader<R> { /* private fields */ }Expand description
A FLAC reader which outputs non-interleaved channels
§Example
use flac_codec::{
encode::{FlacChannelWriter, Options},
decode::FlacChannelReader,
};
use std::io::{Cursor, Seek};
let mut flac = Cursor::new(vec![]); // a FLAC file in memory
let mut writer = FlacChannelWriter::new(
&mut flac, // our wrapped writer
Options::default(), // default encoding options
44100, // sample rate
16, // bits-per-sample
2, // channel count
Some(5), // total channel-independent samples
).unwrap();
// write our samples, divided by channel
let written_samples = vec![
vec![1, 2, 3, 4, 5],
vec![-1, -2, -3, -4, -5],
];
assert!(writer.write(&written_samples).is_ok());
// finalize writing file
assert!(writer.finalize().is_ok());
flac.rewind().unwrap();
// open reader around written FLAC file
let mut reader = FlacChannelReader::new(flac).unwrap();
// read a buffer's worth of samples
let read_samples = reader.fill_buf().unwrap();
// ensure the channels match
assert_eq!(read_samples.len(), written_samples.len());
assert_eq!(read_samples[0], written_samples[0]);
assert_eq!(read_samples[1], written_samples[1]);Implementations§
Source§impl<R: Read> FlacChannelReader<R>
impl<R: Read> FlacChannelReader<R>
Sourcepub fn new(reader: R) -> Result<Self, Error>
pub fn new(reader: R) -> Result<Self, Error>
Opens new FLAC reader which wraps the given reader
The reader must be positioned at the start of the
FLAC stream. If the file has non-FLAC data
at the beginning (such as ID3v2 tags), one
should skip such data before initializing a FlacByteReader.
Sourcepub fn fill_buf(&mut self) -> Result<Vec<&[i32]>, Error>
pub fn fill_buf(&mut self) -> Result<Vec<&[i32]>, Error>
Returns complete buffer of all read samples
Analogous to std::io::BufRead::fill_buf, this should
be paired with FlacSampleReader::consume to
consume samples in the filled buffer once used.
Returned samples are returned as a Vec of channel slices,
like: [[left₀ , left₁ , left₂ , …], [right₀ , right₁ , right₂ , …]]
The returned buffer will always contain at least one channel. All channel slices will always be the same length.
§Errors
Returns error if some error occurs reading FLAC file to fill buffer.
Sourcepub fn consume(&mut self, amt: usize)
pub fn consume(&mut self, amt: usize)
Informs the reader that amt channel-indepedent samples
have been consumed.
Analagous to std::io::BufRead::consume, which marks
samples as having been read.
May panic if attempting to consume more bytes than are available in the buffer.
Source§impl<R: Read + Seek> FlacChannelReader<R>
impl<R: Read + Seek> FlacChannelReader<R>
Sourcepub fn new_seekable(reader: R) -> Result<Self, Error>
pub fn new_seekable(reader: R) -> Result<Self, Error>
Opens a new seekable FLAC reader which wraps the given reader
If a stream is both readable and seekable, it’s vital to use this method to open it if one also wishes to seek within the FLAC stream. Otherwise, an I/O error will result when attempting to seek.
FlacChannelReader::open calls this method to ensure
all File-based streams are also seekable.
The reader must be positioned at the start of the
FLAC stream. If the file has non-FLAC data
at the beginning (such as ID3v2 tags), one
should skip such data before initializing a FlacChannelReader.
Trait Implementations§
Source§impl<R: Clone> Clone for FlacChannelReader<R>
impl<R: Clone> Clone for FlacChannelReader<R>
Source§fn clone(&self) -> FlacChannelReader<R>
fn clone(&self) -> FlacChannelReader<R>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read more