10 inertia
<linear_ramp
> ramp
;
11 float first_value
, next_value
;
14 bypass(int _ramp_len
= 1024)
15 : ramp(linear_ramp(_ramp_len
))
19 /// Pass the new state of the bypass button, and return the ramp-aware
21 bool update(bool new_state
, uint32_t nsamples
)
23 ramp
.set_inertia(new_state
? 1.f
: 0.f
);
24 first_value
= ramp
.get_last();
25 ramp
.step_many(nsamples
);
26 next_value
= ramp
.get_last();
27 return first_value
>= 1 && next_value
>= 1;
30 /// Apply ramp to prevent clicking
31 void crossfade(float *inputs
[], float *outputs
[], uint32_t nbuffers
, uint32_t offset
, uint32_t nsamples
)
33 if (!nsamples
|| (first_value
+ next_value
) == 0)
35 float step
= (next_value
- first_value
) / nsamples
;
36 for (uint32_t b
= 0; b
< nbuffers
; ++b
)
38 float *out
= outputs
[b
] + offset
, *in
= inputs
[b
] + offset
;
39 if (first_value
>= 1 && next_value
>= 1)
40 memcpy(out
, in
, nsamples
* sizeof(float));
43 for (uint32_t i
= 0; i
< nsamples
; ++i
)
45 float bypass_amt
= first_value
+ i
* step
;
46 out
[i
] += (in
[i
] - out
[i
]) * bypass_amt
;