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

pub struct AudioBuffer { /* fields omitted */ }

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]

Create a silent audiobuffer with given channel and samples count.

This function does not allocate.

pub fn from_channels(data: 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 channel_data(&self, channel: usize) -> Option<&ChannelData>[src]

Get the samples from this specific channel.

Returns None if this channel is silent or not present

pub fn make_mono(&mut self)[src]

Convert this buffer to a mono sound, maintaining the channel and sample counts.

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 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).unwrap(),
    &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]

impl Debug for AudioBuffer[src]

impl FromIterator<AudioBuffer> for AudioBuffer[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.