-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm_VCA.ino
95 lines (79 loc) · 3.51 KB
/
m_VCA.ino
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
// --------------------------------------------------------------------------
// This file is part of the OCS-2 firmware.
//
// OCS-2 firmware is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OCS-2 firmware is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with OCS-2 firmware. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------------
uint32_t VCO_FILTER_data[4];
uint32_t MIX_fader1, MIX_fader2;
uint32_t filter1, filter2, filter3, filter4, filter5;
uint32_t VCA_MIX_value, VCA_MIX_value_old;
uint32_t VCA_GAIN_value, VCA_GAIN_value_old, gain_filter;
uint32_t MIX_fader1_filter, MIX_fader2_filter;
inline void init_VCA() {
VCO_FILTER_data[0] = 0x80000000;
VCO_FILTER_data[1] = 0x80000000;
VCO_FILTER_data[2] = 0x80000000;
VCO_FILTER_data[3] = 0x80000000;
MIX_fader1 = 0;
MIX_fader2 = 0;
}
inline void VCA_update(){
uint32_t VCA_modulation, VCA_MIX_value_local, VCA_GAIN_value_local;
uint32_t tmp = clip_ana_low16(adc_value16[VCA_MOD]);
VCA_MIX_value_old = hysteresis16(clip_anaLH16(adc_value16[VCA_MIX]), VCA_MIX_value_old);
VCA_MIX_value_local = VCA_MIX_value_old;
if(MIX_type == 0) {
VCA_modulation = ((modulation_data[modulation_index[index_VCA_MOD]])+(1<<15)) * tmp;
VCA_modulation >>= 16;
VCA_modulation += VCA_MIX_value_local;
tmp >>= 1;
VCA_MIX_value_local = (VCA_modulation > tmp)? VCA_modulation - tmp : 0;
VCA_MIX_value_local = (VCA_MIX_value_local > 0xFFF0)? 0xFFF0 : VCA_MIX_value_local;
//analog_out_1(VCA_MIX_value<<16);
}
VCA_MIX_value = VCA_MIX_value_local;
MIX_fader2 = VCA_MIX_value << 8; // 24 bit max
VCA_GAIN_value_old = hysteresis16(clip_ana_low16(adc_value16[VCA_GAIN]), VCA_GAIN_value_old);
VCA_GAIN_value_local = VCA_GAIN_value_old;
if(MIX_type != 0) {
VCA_modulation = (0xFFFF - (1<<15) - (modulation_data[modulation_index[index_VCA_MOD]])) * tmp;
VCA_modulation >>= 16;
VCA_GAIN_value_local = VCA_GAIN_value_local * (0xFFFF - VCA_modulation);
VCA_GAIN_value_local >>= 16;
}
VCA_GAIN_value_local *= VCA_GAIN_value_local; // pow 2 for a nice amplitude curve
VCA_GAIN_value_local >>= 16;
VCA_GAIN_value = VCA_GAIN_value_local;
}
inline int32_t MIX(uint32_t VCO1_out, uint32_t VCO2_out) {
uint32_t tmp1, tmp2, tmp3;
uint32_t VCO2;
int32_t VCO_out;
MIX_fader2_filter += (MIX_fader2 >> 10) - (MIX_fader2_filter >> 10);
MIX_fader1_filter = 0x00FFF000-MIX_fader2_filter;
VCO2 = (RINGMOD)? (m_s32xs32_s32H(VCO1_out^0x80000000, VCO2_out^0x80000000)<<1)^0x80000000: VCO2_out;
VCO_out = m_u32xu32_u32H(VCO1_out, MIX_fader1_filter) + m_u32xu32_u32H(VCO2, MIX_fader2_filter);
//analog_out_1(VCO_out<<8);
//MIX_out = VCO_out;
return(VCO_out);
}
inline int32_t VCA(int32_t EFFECT_out) {
uint32_t gain;
int32_t tmp32, env;
gain_filter += (int32_t)(VCA_GAIN_value - gain_filter) >> 10;
gain = gain_filter << 15;
tmp32 = m_s32xs32_s32H(EFFECT_out, gain);
env = (GATE_mode != 3)? ADSR_out<<1 : 0X7FFFFFFF; // on est en signed, le MSB est le signe
return(m_s32xs32_s32H(tmp32, env)<<2);
}