1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
use crate::{Buffer, Input, Node};
use dasp_frame::Frame;
use dasp_signal::Signal;

impl<F> Node for dyn Signal<Frame = F>
where
    F: Frame<Sample = f32>,
{
    fn process(&mut self, _inputs: &[Input], output: &mut [Buffer]) {
        let channels = std::cmp::min(F::CHANNELS, output.len());
        for ix in 0..Buffer::LEN {
            let frame = self.next();
            for ch in 0..channels {
                // Safe, as we verify the number of channels at the beginning of the function.
                output[ch][ix] = unsafe { *frame.channel_unchecked(ch) };
            }
        }
    }
}