1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Utilities for manipulating audio buffers.

use audio_core::Translate;
use audio_core::{Channels, ChannelsMut};

/// Copy from the buffer specified by `from` into the buffer specified by `to`.
///
/// Only the common count of channels will be copied.
pub fn copy<I, O, T>(from: I, mut to: O)
where
    I: Channels<T>,
    O: ChannelsMut<T>,
    T: Copy,
{
    let end = usize::min(from.channels(), to.channels());

    for chan in 0..end {
        to.channel_mut(chan).copy_from(from.channel(chan));
    }
}

/// Translate the content of one buffer `from` into the buffer specified by `to`.
///
/// Only the common count of channels will be copied.
pub fn translate<I, O, U, T>(from: I, mut to: O)
where
    I: Channels<U>,
    O: ChannelsMut<T>,
    T: Translate<U>,
    U: Copy,
{
    let end = usize::min(from.channels(), to.channels());

    for chan in 0..end {
        to.channel_mut(chan).translate_from(from.channel(chan));
    }
}