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

Allocate a silent audiobuffer with given channel and samples count.

Create a multi-channel audiobuffer.

Number of channels in this AudioBuffer

Number of samples per channel in this AudioBuffer

Sample rate of this AudioBuffer in Hertz

Duration in seconds of the AudioBuffer

Channel data as slice

Channel data as slice (mutable)

Get the samples from this specific channel.

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

Get the samples (mutable) from this specific channel.

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

Modify every channel in the same way

Extends an AudioBuffer with the contents of another.

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

Extends an AudioBuffer with an FixedAudioBuffer

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

Split an AudioBuffer in chunks with length sample_len.

The last chunk may be shorter than sample_len

Split an AudioBuffer in two at the given index.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.