Skip to main content

rill_core_dsp/lang/
noise.rs

1use rill_core::builtin::BlockBuiltin;
2use rill_core::math::Transcendental;
3use rill_core::traits::algorithm::Algorithm;
4use rill_core::traits::ProcessResult;
5
6use crate::generators::{Generator, NoiseGenerator};
7use crate::lang::pv_f32;
8
9pub struct NoiseGenBuiltin<T: Transcendental> {
10    pub gen: NoiseGenerator<T>,
11}
12
13impl<T: Transcendental> Algorithm<T> for NoiseGenBuiltin<T> {
14    fn process(&mut self, input: Option<&[T]>, output: &mut [T]) -> ProcessResult<()> {
15        self.gen.process(input, output)
16    }
17    fn init(&mut self, sr: f32) {
18        Algorithm::init(&mut self.gen, sr);
19    }
20    fn reset(&mut self) {
21        Algorithm::reset(&mut self.gen);
22    }
23}
24
25impl<T: Transcendental> BlockBuiltin<T> for NoiseGenBuiltin<T> {
26    fn set_param(&mut self, index: usize, value: &rill_core::traits::ParamValue) {
27        if index == 1 {
28            self.gen.set_amplitude(T::from_f32(pv_f32(value)));
29        }
30    }
31}