pub struct AudioClip {
sample_rate: u32,
channels: u16,
pcm: Arc<[f32]>,
}Expand description
Decoded audio: interleaved f32 PCM samples.
Clips are immutable and cheap to clone (sample data is shared). Decoding a
file normalizes to MASTER_SAMPLE_RATE and MASTER_CHANNELS; clips
built with AudioClip::from_pcm may carry any rate/channels and the
mixer adapts them on the fly.
Fields§
§sample_rate: u32§channels: u16§pcm: Arc<[f32]>Implementations§
Source§impl AudioClip
impl AudioClip
Sourcepub fn from_pcm(
pcm: impl Into<Arc<[f32]>>,
sample_rate: u32,
channels: u16,
) -> Self
pub fn from_pcm( pcm: impl Into<Arc<[f32]>>, sample_rate: u32, channels: u16, ) -> Self
Build a clip from interleaved PCM samples.
Sourcepub fn sine(freq: f64, secs: f64, amplitude: f64) -> Self
pub fn sine(freq: f64, secs: f64, amplitude: f64) -> Self
A mono sine tone, mainly for tests and self-contained examples.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, AudioError>
Available on crate feature audio-decode only.
pub fn from_bytes(bytes: &[u8]) -> Result<Self, AudioError>
audio-decode only.Decode audio bytes in memory (requires the audio-decode feature).
Any format symphonia supports decodes: WAV, MP3, FLAC, AAC/M4A, Ogg
Vorbis. Output is normalized to MASTER_SAMPLE_RATE and
MASTER_CHANNELS — other sample rates are resampled with rubato’s
FFT resampler, mono is duplicated to stereo, and beyond-stereo channel
layouts keep their front left/right pair.
This is the whole-file entry point that works everywhere std::io
does, including wasm; AudioClip::from_file is a thin wrapper.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, AudioError>
Available on crate feature audio-decode only.
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, AudioError>
audio-decode only.Decode an audio file (requires the audio-decode feature).
Pure-Rust decoding via symphonia — no ffmpeg binary on PATH. See
AudioClip::from_bytes for the supported formats and the
normalization applied to the output.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Sample rate of the PCM data.
Sourcepub fn duration_secs(&self) -> f64
pub fn duration_secs(&self) -> f64
Duration in seconds.
fn frames(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AudioClip
impl RefUnwindSafe for AudioClip
impl Send for AudioClip
impl Sync for AudioClip
impl Unpin for AudioClip
impl UnsafeUnpin for AudioClip
impl UnwindSafe for AudioClip
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> TransformedExt for T
impl<T> TransformedExt for T
Source§fn transformed<G>(self, transform: G) -> Transformed<Self, G>
fn transformed<G>(self, transform: G) -> Transformed<Self, G>
self wrapped with transform stored exactly as G.