Struct FlacStreamWriter

Source
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>

Source

pub fn new(writer: W, options: Options) -> Self

Creates new stream writer

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<W> Freeze for FlacStreamWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for FlacStreamWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for FlacStreamWriter<W>
where W: Send,

§

impl<W> Sync for FlacStreamWriter<W>
where W: Sync,

§

impl<W> Unpin for FlacStreamWriter<W>
where W: Unpin,

§

impl<W> UnwindSafe for FlacStreamWriter<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.