Skip to main content

PcmQueue

Struct PcmQueue 

Source
pub struct PcmQueue {
    samples: PcmSegQueue,
    pub channels: u32,
    pub sample_rate: u32,
    usb_rate_rem: u32,
    volume: u32,
    muted: bool,
    peak_level: i16,
    pub underrun_frames: u64,
    pub underrun_events: u64,
    pub max_frames: usize,
    pub dropped_frames: u64,
    pub alloc_dropped_frames: u64,
}
Expand description

復号済み PCM の待ち行列(ステレオ交互、i16)。

Fields§

§samples: PcmSegQueue§channels: u32

入力のチャンネル数(1 ならモノラル。出力時に左右へ複製する)。

§sample_rate: u32

標本化周波数 [Hz]。

§usb_rate_rem: u32

USB Audio 1ms パケット切り出し時の端数アキュムレータ(0..999)。

§volume: u32

音量スケール: 0 (無音/0%) 〜 256 (通常/100%)。初期値は 256。

§muted: bool

ミュート状態

§peak_level: i16

ピーク振幅(絶対値最大: 0..=32767)

§underrun_frames: u64

アンダーラン累積フレーム数

§underrun_events: u64

アンダーラン発生回数(不足により無音補完されたイベント数)

§max_frames: usize

最大許容フレーム数(0 なら無制限)。超過時は古い標本をドロップ。

§dropped_frames: u64

オーバーランによりドロップされた累積フレーム数

§alloc_dropped_frames: u64

ヒープ不足で足せずに捨てた累積フレーム数

Implementations§

Source§

impl PcmQueue

Source

pub fn new(sample_rate: u32, channels: u32) -> Self

Source

pub fn set_volume(&mut self, vol: u32)

音量を設定する(0..=256。256 が 100%、128 が 50%、0 が無音)。256 を超える場合は 256 にクランプ。

Source

pub fn volume(&self) -> u32

現在の音量を取得する。

Source

pub fn set_muted(&mut self, muted: bool)

ミュート状態を設定する。

Source

pub fn is_muted(&self) -> bool

ミュート状態かを取得する。

Source

pub fn peak_level(&self) -> i16

ピーク振幅レベル(0..=32767)を取得する。

Source

pub fn reset_peak(&mut self)

ピーク振幅レベルをリセットする。

Source

pub fn set_max_frames(&mut self, max: usize)

最大許容フレーム数を設定する(0 なら無制限)。

Source

fn enforce_capacity(&mut self)

Source

pub fn push(&mut self, pcm: &[i16])

交互配置の PCM(channels 本)を末尾へ足す。

Source

fn scale_sample(&mut self, s: i16) -> i16

標本に音量とミュートを適用し、ピークを更新して返す。

Source

pub fn buffered_ms(&self) -> u64

溜まっている時間 [ms]。

Source

pub fn clear(&mut self)

Source

pub fn frames(&self) -> usize

溜まっているフレーム数。

Source

pub fn fill_words(&mut self, out: &mut [u32], range: u32) -> usize

out(左右交互の PWM 語。長さは偶数)を待ち行列から埋める。足りない分は無音。 埋めた(実データの)フレーム数を返す。

Source

pub fn drain_frames(&mut self, frames: usize) -> usize

frames フレーム分を捨てる(実機の DMA が無い環境で、実時間の消費を真似る)。 実際に捨てたフレーム数を返す。

Source

pub fn fill_usb_iso_packet( &mut self, dst_rate: u32, dst_channels: u8, max_packet_size: u16, out_bytes: &mut [u8], ) -> (usize, usize)

USB Audio Class 1.0 の 1ms 等時性 OUT パケット(out_bytes)へ待ち行列の PCM を リサンプルして書き込む。戻り値は (書き込んだバイト数, 消費した入力フレーム数)。

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.