Skip to main content

FlacWriter

Struct FlacWriter 

Source
pub struct FlacWriter { /* private fields */ }
Expand description

録音チャンクを逐次 FLAC ファイルへ書き出すライター。

interleaved f32(flexaudio の AudioChunk.data と同じ形)を write_chunk に流し、終わったら finalize でヘッダを確定する。エンコードは呼び出し スレッド上で同期的に行う。

finalize を呼ばずに drop した場合もベストエフォートで閉じる(端数の書き出しと ヘッダ確定を試み、エラーは握りつぶす)。確実に完結させたいときは finalize を 呼ぶこと。

Implementations§

Source§

impl FlacWriter

Source

pub fn create<P: AsRef<Path>>( path: P, sample_rate: u32, channels: u16, ) -> Result<FlacWriter>

path に 16bit FLAC ファイルを新規作成する(既存ファイルは上書き)。

対応範囲は channels 1..=2、sample_rate 1..=96,000 Hz。範囲外は EncodeError::Unsupported(ファイルは作られない)。

Source

pub fn write_chunk(&mut self, interleaved: &[f32]) -> Result<()>

interleaved f32 サンプルを追記する。

長さは channels の倍数であること(flexaudio の AudioChunk.data は そのまま渡せる)。倍数でなければ EncodeError::Unsupported を返し、 何も書かない。ブロックに満たない端数は内部に持ち越し、次の呼び出しか finalize で書かれる。

Source

pub fn finalize(self) -> Result<()>

端数フレームの書き出しとヘッダ確定を行い、ファイルを閉じる。

self を消費するので、以後の write_chunk は型で 不可能。Drop でも同じ処理をベストエフォートで行うが、書き込みエラーを 検知できるのはこちらだけなので finalize 推奨。

Trait Implementations§

Source§

impl Debug for FlacWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for FlacWriter

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.