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: u32Implementations§
Source§impl Pcm
impl Pcm
pub fn new(samples: Vec<i16>, channels: u16, frame_rate: u32) -> Pcm
Sourcepub fn from_s16le(bytes: &[u8], channels: u16, frame_rate: u32) -> Pcm
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.
Sourcepub fn frame_count(&self) -> usize
pub fn frame_count(&self) -> usize
Frames, i.e. samples divided by channels (len(_data) // frame_width).
Sourcepub fn rms(&self) -> i64
pub fn rms(&self) -> i64
audioop.rms — int(sqrt(sum(v²)/n)), accumulated in f64 and
truncated toward zero.
Sourcepub fn max_abs(&self) -> i64
pub fn max_abs(&self) -> i64
audioop.max — the largest absolute sample. -32768 yields 32768,
which is why this is not an i16.
Sourcepub fn slice_ms(&self, start_ms: i64, end_ms: i64) -> Pcm
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.
Sourcefn frame_for_ms(&self, ms: i64) -> usize
fn frame_for_ms(&self, ms: i64) -> usize
_parse_position — int(ms * frame_rate / 1000.0).