-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm_EFFECT.ino
241 lines (197 loc) · 7.01 KB
/
m_EFFECT.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// --------------------------------------------------------------------------
// 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 BITCRUSH_gain, BITCRUSH_xor;
uint32_t DISTO_gain_value, DISTO_gain_old;
int32_t old_mix_out;
uint32_t effect, waveshape, waveshape_filter, effect_filter, disto_gain_filter;
int16_t delay_line[43000];
uint32_t delay_write, delay_time, delay_time_filter, delay_feedback_filter;
int32_t delay_feedback, delay_feedback_old;
inline void init_EFFECT() {
}
inline void EFFECT_update() {
switch(EFFECT_type) {
case 0:
DISTO_update();
break;
case 1:
BITCRUSH_update();
break;
case 2:
DELAY_update();
break;
case 3:
WAVESHAPE_update();
break;
}
}
inline int32_t EFFECT(int32_t VCF_out) {
int32_t effect_out, VCA_out;
switch(EFFECT_type) {
case 0:
effect_out = DISTO(VCF_out);
VCA_out = VCA(effect_out);
break;
case 1:
effect_out = BITCRUSH(VCF_out);
VCA_out = VCA(effect_out);
break;
case 2:
VCA_out = VCA(VCF_out);
VCA_out = DELAY(VCA_out);
break;
case 3:
effect_out = WAVESHAPE(VCF_out);
VCA_out = VCA(effect_out);
break;
}
//analog_out_2(EFFECT_out ^ 0x80000000);
return(VCA_out);
}
inline void BITCRUSH_update() {
uint32_t tmp, tmp2;
tmp = clip_ana_low16(adc_value16[EFFECT1]);
tmp *= tmp;
tmp >>= 2;
tmp &= 0x3F000000;
tmp = 0xFFFFFFFF - tmp;
BITCRUSH_gain = tmp;
tmp = adc_value16[EFFECT2] * ((int32_t)modulation_data[modulation_index[index_EFFECT_MOD]] + (1<<15));
BITCRUSH_xor = tmp>>1;
}
inline int32_t BITCRUSH(int32_t VCF_out) {
int32_t EFFECT_out;
//EFFECT_out = (VCF_out & BITCRUSH_xor) & BITCRUSH_gain ; // bitcrush
EFFECT_out = (VCF_out ^ BITCRUSH_xor) ^ BITCRUSH_gain ; // Not a real bitcrush, but i like it.
return(EFFECT_out);
}
inline void DISTO_update() {
uint32_t tmp;
int32_t tmp2;
tmp = clip_ana_low16(adc_value16[EFFECT1]);
DISTO_gain_old = hysteresis16(tmp, DISTO_gain_old);
tmp = DISTO_gain_old;
tmp <<= 15; // 31 bits (will be used as signed : must be positive)
tmp2 = adc_value16[EFFECT2] * modulation_data[modulation_index[index_EFFECT_MOD]];
tmp2 >>= 1;
tmp2 += 0x3FFFFFFF;
tmp += tmp2;
tmp = tmp < 0x40000000? 0: tmp-0x40000000;
tmp = tmp > 0x7FFFFFFF? 0x7FFFFFFF: tmp;
DISTO_gain_value = tmp;
}
inline int32_t disto1 (int32_t in) {
return(gain2_cliped_S32(in-m_s32xs32_s32H(in, abs(in))));
}
inline int32_t DISTO(int32_t VCF_out) {
int32_t DISTO_in, DISTO_out;
uint32_t DISTO_gain, tmp32;
int32_t tmpS;
DISTO_in = VCF_out;
//analog_out_1(VCF_out ^ 0x80000000);
disto_gain_filter += (int32_t)(DISTO_gain_value - disto_gain_filter) >> 10;
DISTO_gain = (disto_gain_filter<<3) & 0x7FFFFFFF;
DISTO_in = (disto_gain_filter & 1<<28)? disto1(DISTO_in) : DISTO_in;
DISTO_in = (disto_gain_filter & 1<<29)? disto1(disto1(DISTO_in)) : DISTO_in;
DISTO_in = (disto_gain_filter & 1<<30)? disto1(disto1(disto1(disto1(DISTO_in)))) : DISTO_in;
//analog_out_2(DISTO_in^0x80000000);
tmpS = m_s32xs32_s32H(DISTO_in, abs(DISTO_in))<<1;
tmpS = m_s32xs32_s32H(DISTO_gain, DISTO_in-tmpS)<<1;
tmpS += DISTO_in;
DISTO_gain = (disto_gain_filter < 0x3FFFFFFF)? 0x7FFFFFFF - disto_gain_filter: 0x3FFFFFFF;
tmpS = m_s32xs32_s32H(tmpS, DISTO_gain)<<1;
DISTO_out = tmpS;
//analog_out_2(DISTO_out ^ 0x80000000);
//EFFECT_out = DISTO_out;
return(DISTO_out);
}
inline void WAVESHAPE_update() {
uint32_t tmp;
int32_t tmp2;
tmp = clip_ana_low16(adc_value16[EFFECT1]);
tmp <<= 15; // 31 bits (will be used as signed : must be positive)
tmp2 = adc_value16[EFFECT2] * modulation_data[modulation_index[index_EFFECT_MOD]];
tmp2 >>= 1;
tmp2 += 0x3FFFFFFF;
tmp += tmp2;
tmp = tmp < 0x40000000? 0: tmp-0x40000000;
tmp = tmp > 0x7FFFFFFF? 0x7FFFFFFF: tmp;
effect = tmp>0x07FFFFFF? 0x07FFFFFF: tmp; // mix amplitude
waveshape = tmp>0x10000000? tmp: 0x10000000; // forme du waveshaper
}
inline int32_t WAVESHAPE(int32_t VCF_out) {
int32_t tmp1, VCF_local;
uint32_t tmp2, tmp3;
uint32_t tmp, phaseH, phaseL, a_effect;
VCF_local = VCF_out;
// old_mix_out += (VCF_local >> 4) - (old_mix_out >> 4); // filter the audio in
old_mix_out = VCF_local;
waveshape_filter += (int32_t)(waveshape - waveshape_filter) >> 11; // filter on waveshape size fader
effect_filter += (int32_t)(effect - effect_filter) >> 11; // filter on waveshape wet
tmp1 = m_s32xs32_s32H(old_mix_out, waveshape_filter);
tmp1 <<= 4;
tmp1 += 0X10000000; // disymetrie
tmp = tmp1^0x80000000;
tmp += 1 << 30; // symetrie
phaseH = tmp>>19; // 13 bits
phaseL = tmp & 0x7FFFF; // 19 bits
tmp = table_cos[phaseH];
tmp2 = table_cos[(phaseH + 1)];
tmp3 = m_s32xs32_s32H(tmp2-tmp, phaseL<<12);
tmp3 <<= 1;
tmp3 += tmp;
tmp3 >>= 1;
tmp3 += 0x3FFFFFFF;
a_effect = effect_filter;
tmp1 = (m_s32xs32_s32H(tmp3^0x80000000,a_effect) + m_s32xs32_s32H(VCF_local,0x07FFFFFF-a_effect))<<5;
return(tmp1);
}
inline void DELAY_update() {
uint32_t tmp;
tmp = adc_value16[EFFECT2];
tmp *= tmp;
tmp = (tmp>>2) + (tmp>>3);
tmp += (1000<<14);
tmp = (tmp > (43000<<15))? (43000<<15) : tmp;
delay_time = hysteresis32(tmp, delay_time);
delay_feedback_old = hysteresis16(adc_value16[EFFECT1], delay_feedback_old);
delay_feedback = clip_anaLH16(delay_feedback_old)<<15;
}
inline int32_t DELAY(int32_t VCA_out) {
uint32_t delay_read, tmp;
int32_t delay_value, read_pos, sound, sound2;
int32_t out;
delay_time_filter += (int32_t)(delay_time - delay_time_filter) >> 12;
delay_feedback_filter += (int32_t)(delay_feedback - delay_feedback_filter) >> 12;
delay_write++;
delay_write = (delay_write >= 43000)? 0: delay_write;
tmp = (delay_time_filter>>15);
read_pos = delay_write - tmp;
delay_read = (read_pos < 0)? read_pos+43000: read_pos;
// delay line interpolation
sound = delay_line[delay_read];
sound2 = delay_line[(delay_read == 0)? 43000-1:delay_read-1]-sound;
sound <<= 16;
sound += (sound2 * (delay_time_filter & 0x00007FFF))<<1;
out = m_s32xs32_s32H(sound, delay_feedback_filter); // todo : une seule multiplication
out += m_s32xs32_s32H(VCA_out, 0x7FFFFFFF - delay_feedback_filter);
out = gain2_cliped_S32(out);
//VCA_out = out;
delay_line[delay_write] = out>>16;
return(out);
//analog_out_2((delay_line[delay_read]<<16)^0x80000000);
}