Struct web_audio_api::buffer::AudioBuffer[][src]

pub struct AudioBuffer { /* fields omitted */ }
Expand description

Memory-resident audio asset, basically a matrix of channels * samples

An AudioBuffer has copy-on-write semantics, so it is cheap to clone.

Implementations

impl AudioBuffer[src]

pub fn new(channels: usize, len: usize, sample_rate: SampleRate) -> Self[src]

Allocate a silent audiobuffer with given channel and samples count.

pub fn from_channels(
    channels: Vec<ChannelData>,
    sample_rate: SampleRate
) -> Self
[src]

Create a multi-channel audiobuffer.

pub fn number_of_channels(&self) -> usize[src]

Number of channels in this AudioBuffer

pub fn sample_len(&self) -> usize[src]

Number of samples per channel in this AudioBuffer

pub fn sample_rate(&self) -> SampleRate[src]

Sample rate of this AudioBuffer in Hertz

pub fn duration(&self) -> f64[src]

Duration in seconds of the AudioBuffer

pub fn channels(&self) -> &[ChannelData][src]

Channel data as slice

pub fn channels_mut(&mut self) -> &mut [ChannelData][src]

Channel data as slice (mutable)

pub fn channel_data(&self, index: usize) -> &ChannelData[src]

Get the samples from this specific channel.

Panics if the index is greater than the available number of channels

pub fn channel_data_mut(&mut self, index: usize) -> &mut ChannelData[src]

Get the samples (mutable) from this specific channel.

Panics if the index is greater than the available number of channels

pub fn modify_channels<F: Fn(&mut ChannelData)>(&mut self, fun: F)[src]

Modify every channel in the same way

pub fn extend(&mut self, other: &Self)[src]

Extends an AudioBuffer with the contents of another.

This function will panic if the sample_rate and channel_count are not equal

pub fn extend_alloc(&mut self, other: &FixedAudioBuffer)[src]

Extends an AudioBuffer with an FixedAudioBuffer

This assumes the sample_rate matches. No up/down-mixing is performed

pub fn split(self, sample_len: u32) -> Vec<AudioBuffer>[src]

Split an AudioBuffer in chunks with length sample_len.

The last chunk may be shorter than sample_len

pub fn split_off(&mut self, index: u32) -> AudioBuffer[src]

Split an AudioBuffer in two at the given index.

pub fn resample(&mut self, sample_rate: SampleRate)[src]

Resample to the desired sample rate.

This changes the sample_length of the buffer.

use web_audio_api::SampleRate;
use web_audio_api::buffer::{ChannelData, AudioBuffer};

let channel = ChannelData::from(vec![1., 2., 3., 4., 5.]);
let mut buffer = AudioBuffer::from_channels(vec![channel], SampleRate(48_000));

// upmix from 48k to 96k Hertz sample rate
buffer.resample(SampleRate(96_000));

assert_eq!(
    buffer.channel_data(0),
    &ChannelData::from(vec![1., 1., 2., 2., 3., 3., 4., 4., 5., 5.,])
);

assert_eq!(buffer.sample_rate().0, 96_000);

Trait Implementations

impl Clone for AudioBuffer[src]

fn clone(&self) -> AudioBuffer[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for AudioBuffer[src]

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

Formats the value using the given formatter. Read more

impl FromIterator<AudioBuffer> for AudioBuffer[src]

fn from_iter<I: IntoIterator<Item = AudioBuffer>>(iter: I) -> Self[src]

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.