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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
ix!();

use crate::{
    SampleAndHoldOscillator,
    SampleAndHoldOscillatorParam,
};

impl SetPitch for SampleAndHoldOscillator {

    fn set_pitch(&mut self, pitch: f32, is_display: bool) {

        if is_display {
            self.blitter.n_unison = 1;
            //srand(2);
        }

        self.blitter.prepare_unison(self.blitter.n_unison as usize);

        self.pitch = pitch;

        self.update_lagvals::<true>();

        for i in (0_usize..(self.blitter.n_unison as usize)).step_by(1) {

            if pvalb![self.osc_params[OscillatorParam::Retrigger]] || is_display {
                self.blitter.oscstate[i] = 0.0;
                self.blitter.syncstate[i] = 0.0;

            } else {

                let drand: f64 = rand01() as f64;

                let detune: f64 = 
                    (self.pvalf_extended(
                            SampleAndHoldOscillatorParam::UniSpread) as f64) *
                    (self.blitter.detune_bias * (i as f32) + 
                     self.blitter.detune_offset) as f64;

                let st: f64 = drand * 
                    self.tuner.n2p_tuningctr(detune) *
                    0.5;

                //value assigned is never read
                /*
                drand = rand01() as f64;

                let ot: f64 = drand * 
                    self.tuner.n2p_tuningctr(detune);
                */

                self.blitter.oscstate[i]  = st as f32;
                self.blitter.syncstate[i] = st as f32;
            }

            self.blitter.state[i]     = 0;
            self.last_level[i]        = 0.0;

            self.pwidth[i] = limit_range(
                self.l_pw.v as f32, 
                0.001, 
                0.999
            );

            self.blitter.driftlfo2[i] = 0.0;
            self.blitter.driftlfo[i]  = 0.0;
        }
    }
}