Trait audio_core::BufMut

source ·
pub trait BufMut: Buf {
    type ChannelMut<'this>: ChannelMut<Sample = Self::Sample>
       where Self: 'this;
    type IterChannelsMut<'this>: Iterator<Item = Self::ChannelMut<'this>>
       where Self: 'this;

    // Required methods
    fn iter_channels_mut(&mut self) -> Self::IterChannelsMut<'_>;
    fn get_channel_mut(
        &mut self,
        channel: usize
    ) -> Option<Self::ChannelMut<'_>>;
    fn copy_channel(&mut self, from: usize, to: usize)
       where Self::Sample: Copy;

    // Provided method
    fn fill(&mut self, value: Self::Sample)
       where Self::Sample: Copy { ... }
}
Expand description

A trait describing a mutable audio buffer.

Required Associated Types§

source

type ChannelMut<'this>: ChannelMut<Sample = Self::Sample> where Self: 'this

The type of the mutable channel container.

source

type IterChannelsMut<'this>: Iterator<Item = Self::ChannelMut<'this>> where Self: 'this

A mutable iterator over available channels.

Required Methods§

source

fn iter_channels_mut(&mut self) -> Self::IterChannelsMut<'_>

Construct a mutable iterator over available channels.

Examples
use audio::{BufMut, ChannelMut};

fn test(mut buf: impl BufMut<Sample = i32>) {
    for (n, mut chan) in buf.iter_channels_mut().enumerate() {
        for f in chan.iter_mut() {
            *f += n as i32 + 1;
        }
    }
}

let mut buf = audio::dynamic![[0; 4]; 2];
test(&mut buf);
assert_eq!(
    buf.iter_channels().collect::<Vec<_>>(),
    vec![[1, 1, 1, 1], [2, 2, 2, 2]],
);

let mut buf = audio::interleaved![[0; 4]; 2];
test(&mut buf);
assert_eq!(
    buf.iter_channels().collect::<Vec<_>>(),
    vec![[1, 1, 1, 1], [2, 2, 2, 2]],
);
source

fn get_channel_mut(&mut self, channel: usize) -> Option<Self::ChannelMut<'_>>

Return a mutable handler to the buffer associated with the channel.

Examples
use audio::{BufMut, ChannelMut};

fn test(mut buf: impl BufMut<Sample = i32>) {
    if let Some(mut chan) = buf.get_channel_mut(1) {
        for f in chan.iter_mut() {
            *f += 1;
        }
    }
}

let mut buf = audio::dynamic![[0; 4]; 2];
test(&mut buf);
assert_eq!(
    buf.iter_channels().collect::<Vec<_>>(),
    vec![[0, 0, 0, 0], [1, 1, 1, 1]],
);
source

fn copy_channel(&mut self, from: usize, to: usize)
where Self::Sample: Copy,

Copy one channel into another.

If the channels have different sizes, the minimul difference between them will be copied.

Panics

Panics if one of the channels being tried to copy from or to is out of bounds as reported by Buf::channels.

Examples
use audio::{Buf, BufMut};

let mut buf = audio::dynamic![[1, 2, 3, 4], [0, 0, 0, 0]];
buf.copy_channel(0, 1);
assert_eq!(buf.get_channel(1), buf.get_channel(0));

Provided Methods§

source

fn fill(&mut self, value: Self::Sample)
where Self::Sample: Copy,

Fill the entire buffer with the specified value

Example
use audio::BufMut;

let mut buf = audio::sequential![[0; 2]; 2];
buf.fill(1);
assert_eq!(buf.as_slice(), &[1, 1, 1, 1]);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<B> BufMut for &mut B
where B: ?Sized + BufMut,

§

type ChannelMut<'this> = <B as BufMut>::ChannelMut<'this> where Self: 'this

§

type IterChannelsMut<'this> = <B as BufMut>::IterChannelsMut<'this> where Self: 'this

source§

fn get_channel_mut(&mut self, channel: usize) -> Option<Self::ChannelMut<'_>>

source§

fn copy_channel(&mut self, from: usize, to: usize)
where Self::Sample: Copy,

source§

fn iter_channels_mut(&mut self) -> Self::IterChannelsMut<'_>

Implementors§

source§

impl<B> BufMut for Limit<B>
where B: BufMut,

§

type ChannelMut<'this> = <B as BufMut>::ChannelMut<'this> where Self: 'this

§

type IterChannelsMut<'this> = IterChannelsMut<<B as BufMut>::IterChannelsMut<'this>> where Self: 'this

source§

impl<B> BufMut for Skip<B>
where B: BufMut,

§

type ChannelMut<'a> = <B as BufMut>::ChannelMut<'a> where Self: 'a

§

type IterChannelsMut<'a> = IterChannelsMut<<B as BufMut>::IterChannelsMut<'a>> where Self: 'a

source§

impl<B> BufMut for Tail<B>
where B: BufMut,

§

type ChannelMut<'a> = <B as BufMut>::ChannelMut<'a> where Self: 'a

§

type IterChannelsMut<'a> = IterChannelsMut<<B as BufMut>::IterChannelsMut<'a>> where Self: 'a