Skip to main content

Pcm

Struct Pcm 

Source
pub struct Pcm {
    pub samples: Vec<i16>,
    pub channels: u16,
    pub frame_rate: u32,
}
Expand description

Interleaved i16 samples plus the format they were decoded at.

Fields§

§samples: Vec<i16>§channels: u16§frame_rate: u32

Implementations§

Source§

impl Pcm

Source

pub fn new(samples: Vec<i16>, channels: u16, frame_rate: u32) -> Pcm

Source

pub fn from_s16le(bytes: &[u8], channels: u16, frame_rate: u32) -> Pcm

Decode raw little-endian s16le bytes. A trailing odd byte is dropped, as reading 16-bit frames necessarily does.

Source

pub fn frame_count(&self) -> usize

Frames, i.e. samples divided by channels (len(_data) // frame_width).

Source

pub fn len_ms(&self) -> i64

len(segment) — duration in whole milliseconds, rounded.

Source

pub fn rms(&self) -> i64

audioop.rms — int(sqrt(sum(v²)/n)), accumulated in f64 and truncated toward zero.

Source

pub fn max_abs(&self) -> i64

audioop.max — the largest absolute sample. -32768 yields 32768, which is why this is not an i16.

Source

pub fn dbfs(&self) -> f64

segment.dBFS — RMS relative to full scale. -inf for silence.

Source

pub fn max_dbfs(&self) -> f64

segment.max_dBFS — peak sample relative to full scale.

Source

pub fn slice_ms(&self, start_ms: i64, end_ms: i64) -> Pcm

segment[start_ms:end_ms]. Both ends clamp to the segment length, and the frame index is int(ms * rate / 1000).

pydub pads a short tail with silence so the slice is the length the caller asked for; that only happens mid-buffer, never at the end, so slicing the final partial chunk returns what is actually there.

Source

fn frame_for_ms(&self, ms: i64) -> usize

_parse_position — int(ms * frame_rate / 1000.0).

Trait Implementations§

Source§

impl Clone for Pcm

Source§

fn clone(&self) -> Pcm

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 Debug for Pcm

Source§

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

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

impl PartialEq for Pcm

Source§

fn eq(&self, other: &Pcm) -> 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 Pcm

Auto Trait Implementations§

§

impl Freeze for Pcm

§

impl RefUnwindSafe for Pcm

§

impl Send for Pcm

§

impl Sync for Pcm

§

impl Unpin for Pcm

§

impl UnsafeUnpin for Pcm

§

impl UnwindSafe for Pcm

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

Source§

type Output = T

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