pub struct FlacStreamWriter<W> { /* private fields */ }Expand description
A FLAC writer which operates on streamed output
Because this encodes FLAC frames without any metadata blocks or finalizing, it does not need to be seekable.
§Example
use flac_codec::{
decode::{FlacStreamReader, FrameBuf},
encode::{FlacStreamWriter, Options},
};
use std::io::{Cursor, Seek};
use bitstream_io::SignedBitCount;
let mut flac = Cursor::new(vec![]);
let samples = (0..100).collect::<Vec<i32>>();
let mut w = FlacStreamWriter::new(&mut flac, Options::default());
// write a single FLAC frame with some samples
w.write(
44100, // sample rate
1, // channels
16, // bits-per-sample
&samples,
).unwrap();
flac.rewind().unwrap();
let mut r = FlacStreamReader::new(&mut flac);
// read a single FLAC frame with some samples
assert_eq!(
r.read().unwrap(),
FrameBuf {
samples: &samples,
sample_rate: 44100,
channels: 1,
bits_per_sample: 16,
},
);Implementations§
Source§impl<W: Write> FlacStreamWriter<W>
impl<W: Write> FlacStreamWriter<W>
Sourcepub fn write(
&mut self,
sample_rate: u32,
channels: u8,
bits_per_sample: u32,
samples: &[i32],
) -> Result<(), Error>
pub fn write( &mut self, sample_rate: u32, channels: u8, bits_per_sample: u32, samples: &[i32], ) -> Result<(), Error>
Writes a whole FLAC frame to our output stream
Samples are interleaved by channel, like: [left₀ , right₀ , left₁ , right₁ , left₂ , right₂ , …]
This writes a whole FLAC frame to the output stream on each call.
§Errors
Returns an error of any of the parameters are invalid or if an I/O error occurs when writing to the stream.
Sourcepub fn write_cdda(&mut self, samples: &[i32]) -> Result<(), Error>
pub fn write_cdda(&mut self, samples: &[i32]) -> Result<(), Error>
Writes a whole FLAC frame to our output stream with CDDA parameters
Samples are interleaved by channel, like: [left₀ , right₀ , left₁ , right₁ , left₂ , right₂ , …]
This writes a whole FLAC frame to the output stream on each call.
§Errors
Returns an error of any of the parameters are invalid or if an I/O error occurs when writing to the stream.