-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathKick.cpp
118 lines (85 loc) · 2.69 KB
/
Kick.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*****************************************************************************
Kick.cpp
Copyright (c) 2020 Raphael DINGE
*Tab=3***********************************************************************/
/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
#include "Kick.h"
#include <cmath>
/*
==============================================================================
Name : init
==============================================================================
*/
void Kick::init ()
{
filter.set_sample_freq (48000.f);
filter.set_type_high_pass ();
filter.set_resonance (0.7071f);
filter.reset ();
active_ramp.reset (1.f);
}
/*
==============================================================================
Name : process
==============================================================================
*/
void Kick::process ()
{
if (ui.clock_gate.triggered ())
{
const float space_norm
= ui.space_pot
+ ui.space_cv * ui.space_trim * ui.space_trim * ui.space_trim;
space.tick (ui.board.clock (), std::clamp (space_norm, 0.f, 1.f));
}
if (
ui.trigger_button.pressed ()
|| ui.trigger_gate.triggered ()
)
{
ui.trigger_led.pulse ();
body.trigger ();
transient.trigger ();
space.trigger ();
bool cur_active = active_ramp.target () != 0.f;
if (cur_active != active)
{
active_ramp = active ? 1.f : 0.f;
}
}
if (ui.mute_button.pressed ())
{
active = !active;
ui.mute_led = !active;
}
{
const float pitch_norm = std::clamp (
ui.body_pitch_pot + ui.body_pitch_cv, 0.f, 1.f
);
const float speed = 0.5f * std::pow (4.f, pitch_norm);
body.set_speed (speed);
}
{
const float pitch_norm = std::clamp (
ui.transient_pitch_pot + ui.transient_pitch_cv, 0.f, 1.f
);
const float speed = 0.5f * std::pow (4.f, pitch_norm);
transient.set_speed (speed);
}
const float freq_norm
= ui.transient_freq_pot
+ ui.transient_freq_cv * ui.transient_freq_trim * ui.transient_freq_trim * ui.transient_freq_trim;
const float freq_hz = 20.f * std::pow (1000.f, std::clamp (freq_norm, 0.f, 1.f));
filter.set_freq (freq_hz);
filter.update ();
presence.set (ui.presence_pot + ui.presence_cv);
transient.set_transient_morph (ui.transient_morph_pot + ui.transient_morph_cv);
for (size_t i = 0 ; i < erb_BUFFER_SIZE ; ++i)
{
float val = body.process (data.body) * active_ramp.process ();
val += filter.process (transient.process ());
val = space.process (val);
val = presence.process (val);
ui.audio_out [i] = val;
}
}