Skip to main content

Normalizer

Struct Normalizer 

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

入力デバイスフレームを内部正規形(48k/stereo/960frame)へ正規化し、さらに 出力フォーマット(output.sample_rate / output.channels / 時間ベース 20ms) へ再変換するステートフルな 2 段変換器。

push で interleaved サンプルを蓄積し、pop_chunk で完成済みの出力チャンクを 1 つずつ取り出す。

Implementations§

Source§

impl Normalizer

Source

pub fn new( in_sample_rate: u32, in_channels: u16, output: OutputFormat, ) -> Result<Self>

入力 SR / 入力チャンネル数 / 出力フォーマットを指定して正規化器を作る。

第 1 段は入力を 48k/stereo へ正規化する(in_sample_rate == 48000 なら SR パススルー、in_channels が 1 なら mono→stereo 複製、2 はそのまま、3 以上は フロント 2ch を採る)。第 2 段は内部正規形を output へ再変換する (output == {48000, 2} ならパススルー)。

output は呼び出し側で OutputFormat::validate 済みであることを期待する (ここでは妥当域へ丸めない)。

rubato リサンプラの構築は極端なレート比などで失敗し得る。panic させると非 RT の取り込みスレッドが無言で止まるため、失敗時は Error::Backend を返して 呼び出し側に伝播させる。

Source

pub fn in_sample_rate(&self) -> u32

入力サンプルレート(Hz)。

Source

pub fn output(&self) -> OutputFormat

出力フォーマット。

Source

pub fn is_passthrough(&self) -> bool

第 1 段 SR 変換がパススルー(in == 48000)か。

Source

pub fn is_output_passthrough(&self) -> bool

第 2 段(出口)が完全パススルー(output == {48000, 2})か。

Source

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

interleaved 入力サンプルを蓄積する。

interleaved の長さは in_channels の倍数であること。device_pts_ns は この push の先頭フレームに対応するデバイス由来 PTS。

rubato の process が失敗したら Error::Backend を返す(panic させて取り込み スレッドを無言で止めない。呼び出し側がストリームを明示停止できる)。

Source

pub fn pop_chunk(&mut self) -> Option<(Vec<f32>, i64)>

完成済みの出力チャンクを 1 つ取り出す。

返り値は (output.channels interleaved の out_chunk_frames frame, 先頭サンプル の device_pts(ns))。1 チャンク分溜まっていなければ None

Source

pub fn buffered_out_frames(&self) -> usize

現在 out_buf に溜まっている未取り出し出力フレーム数。

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, 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.