Skip to main content

rill_core_dsp/lang/
osc.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::{BasicOscillator, Generator};
7use crate::lang::pv_f32;
8
9pub struct OscBuiltin<T: Transcendental> {
10    pub osc: BasicOscillator<T>,
11}
12
13impl<T: Transcendental> Algorithm<T> for OscBuiltin<T> {
14    fn process(&mut self, input: Option<&[T]>, output: &mut [T]) -> ProcessResult<()> {
15        self.osc.process(input, output)
16    }
17    fn init(&mut self, sr: f32) {
18        Algorithm::init(&mut self.osc, sr);
19    }
20    fn reset(&mut self) {
21        Algorithm::reset(&mut self.osc);
22    }
23}
24
25impl<T: Transcendental> BlockBuiltin<T> for OscBuiltin<T> {
26    fn set_param(&mut self, index: usize, value: &rill_core::traits::ParamValue) {
27        match index {
28            0 => self.osc.set_frequency(pv_f32(value)),
29            1 => self.osc.set_amplitude(T::from_f32(pv_f32(value))),
30            2 => self.osc.set_phase(T::from_f32(pv_f32(value))),
31            _ => {}
32        }
33    }
34}