-
Notifications
You must be signed in to change notification settings - Fork 22
/
VoicesTransient.cpp
136 lines (102 loc) · 3.21 KB
/
VoicesTransient.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*****************************************************************************
VoicesTransient.cpp
Copyright (c) 2020 Raphael DINGE
*Tab=3***********************************************************************/
/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
#include "VoicesTransient.h"
#include <cmath>
/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*
==============================================================================
Name : trigger
==============================================================================
*/
void VoicesTransient::trigger ()
{
_cur_voice = (_cur_voice + 1) % _voices.size ();
for (size_t i = 0 ; i < _voices.size () ; ++i)
{
auto & voice = _voices [i];
if (i == _cur_voice)
{
voice.trigger ();
}
else
{
voice.stop ();
}
}
}
/*
==============================================================================
Name : set_transient_morph
==============================================================================
*/
void VoicesTransient::set_transient_morph (float transient_morph)
{
_transient_morph_ramp = transient_morph;
}
/*
==============================================================================
Name : set_speed
==============================================================================
*/
void VoicesTransient::set_speed (float step_spl)
{
for (auto && voice : _voices)
{
voice.set_speed (step_spl);
}
}
/*
==============================================================================
Name : process
==============================================================================
*/
float VoicesTransient::process ()
{
float transient_morph = _transient_morph_ramp.process ();
float integral;
float mix = std::modf (transient_morph * 18.f, &integral);
size_t index = size_t (integral + 18.f);
const auto & sample_1 = get_sample (index);
const auto & sample_2 = get_sample (index + 1);
float val = 0.f;
for (auto && voice : _voices)
{
val += voice.process (sample_1, sample_2, mix);
}
return val;
}
/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*
==============================================================================
Name : get_sample
==============================================================================
*/
const erb::AudioSampleMono <float, 38400> & VoicesTransient::get_sample (size_t index)
{
index = index % 18;
switch (index)
{
default:
case 0: return _data.transient01;
case 1: return _data.transient02;
case 2: return _data.transient03;
case 3: return _data.transient04;
case 4: return _data.transient05;
case 5: return _data.transient06;
case 6: return _data.transient07;
case 7: return _data.transient08;
case 8: return _data.transient09;
case 9: return _data.transient10;
case 10: return _data.transient11;
case 11: return _data.transient12;
case 12: return _data.transient13;
case 13: return _data.transient14;
case 14: return _data.transient15;
case 15: return _data.transient16;
case 16: return _data.transient17;
case 17: return _data.transient18;
}
}