LMMS
Loading...
Searching...
No Matches
bypass.h
Go to the documentation of this file.
1#ifndef CALF_BYPASS_H
2#define CALF_BYPASS_H
3
4#include "inertia.h"
5
6namespace dsp {
7
8class bypass
9{
12
13public:
14 bypass(int _ramp_len = 1024)
15 : ramp(linear_ramp(_ramp_len))
16 {
17 }
18
21 bool update(bool new_state, uint32_t nsamples)
22 {
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;
28 }
29
31 void crossfade(float *inputs[], float *outputs[], uint32_t nbuffers, uint32_t offset, uint32_t nsamples)
32 {
33 if (!nsamples || (first_value + next_value) == 0)
34 return;
35 float step = (next_value - first_value) / nsamples;
36 for (uint32_t b = 0; b < nbuffers; ++b)
37 {
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));
41 else
42 {
43 for (uint32_t i = 0; i < nsamples; ++i)
44 {
45 float bypass_amt = first_value + i * step;
46 out[i] += (in[i] - out[i]) * bypass_amt;
47 }
48 }
49 }
50 }
51};
52
53}
54
55#endif
inertia< linear_ramp > ramp
Definition bypass.h:10
float first_value
Definition bypass.h:11
float next_value
Definition bypass.h:11
bypass(int _ramp_len=1024)
Definition bypass.h:14
void crossfade(float *inputs[], float *outputs[], uint32_t nbuffers, uint32_t offset, uint32_t nsamples)
Apply ramp to prevent clicking.
Definition bypass.h:31
bool update(bool new_state, uint32_t nsamples)
Definition bypass.h:21
Definition inertia.h:108
Algorithm for a constant time linear ramp.
Definition inertia.h:29
register unsigned i
Definition inflate.c:1575
float in
Definition lilv_test.c:1460
float out
Definition lilv_test.c:1461
unsigned int uint32_t
Definition mid.cpp:100
Definition audio_fx.h:36
memcpy(hh, h, RAND_HEAD_LEN)
b
Definition crypt.c:628