Skip to main content

PcmFormat

Struct PcmFormat 

Source
pub struct PcmFormat {
    pub sample_rate: u32,
    pub channels: u16,
    pub sample: SampleFormat,
}
Expand description

A PCM stream: its frame rate, channel count and sample layout.

Fields§

§sample_rate: u32§channels: u16§sample: SampleFormat

Implementations§

Source§

impl PcmFormat

Source

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

Examples found in repository?
examples/convert_bench.rs (line 49)
48fn main() {
49    let stereo = |rate, sample| PcmFormat::new(rate, 2, sample);
50    println!("{}", plan_line());
51    run(
52        "copy 44.1k 16-bit",
53        stereo(44_100, SampleFormat::I16),
54        stereo(44_100, SampleFormat::I16),
55        Quality::High,
56    );
57    run(
58        "widen 16 -> 24 bit (integer engine)",
59        stereo(44_100, SampleFormat::I16),
60        stereo(44_100, SampleFormat::I24),
61        Quality::High,
62    );
63    run(
64        "narrow 32 -> 16 bit, TPDF dither",
65        stereo(96_000, SampleFormat::I32),
66        stereo(96_000, SampleFormat::I16),
67        Quality::High,
68    );
69    for (label, from, to) in [
70        ("44.1k -> 48k", 44_100, 48_000),
71        ("48k -> 44.1k", 48_000, 44_100),
72        ("96k -> 44.1k", 96_000, 44_100),
73        ("44.1k -> 96k", 44_100, 96_000),
74        ("44.1k -> 192k", 44_100, 192_000),
75        ("192k -> 48k", 192_000, 48_000),
76        ("44.1k -> 768k (most phases)", 44_100, 768_000),
77        ("768k -> 44.1k (longest filter)", 768_000, 44_100),
78    ] {
79        for quality in [Quality::High, Quality::Fast] {
80            run(
81                &format!("resample {label}, 24-bit, {quality:?}"),
82                stereo(from, SampleFormat::I24),
83                stereo(to, SampleFormat::I24),
84                quality,
85            );
86        }
87    }
88}
Source

pub fn bytes_per_frame(&self) -> usize

Bytes of one frame (one sample for every channel).

Trait Implementations§

Source§

impl Clone for PcmFormat

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PcmFormat

Source§

impl Debug for PcmFormat

Source§

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

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

impl Eq for PcmFormat

Source§

impl Hash for PcmFormat

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PcmFormat

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PcmFormat

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.