forked from ch-nry/nozoid_nozori
-
Notifications
You must be signed in to change notification settings - Fork 0
/
m68_Noise.ino
260 lines (229 loc) · 8.44 KB
/
m68_Noise.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// --------------------------------------------------------------------------
// This file is part of the NOZORI firmware.
//
// NOZORI 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.
//
// NOZORI 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 NOZORI firmware. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------------
// noise generator
// Pot 1 : digital noise frequeny
// Pot 2 : noise frequency modulation
// Pot 3 : high pass filter cutoff
// Pot 4 : high pass filter cutoff modulation
// Pot 5 : Low pass filter cutoff
// Pot 6 : Low pass filter cutoff modulation
// CV 1 : Trig
// CV 2 : Noise frequency modulation CV
// CV 3 : high pass frequency modulation
// CV 4 : low pass frequency modulation
// IN 1 : gain
// IN 2 : pan
// Selecteur3 : noise color (white, pink, red)
// OUT 1 : noise Left
// OUT 2 : Noise Right
int32_t noiseL, noiseR, noiseL_filter_low, noiseR_filter_low, noiseL_filter_high, noiseR_filter_high;
int32_t filterL1, filterL2, filterL3, filterL4;
int32_t filterR1, filterR2, filterR3, filterR4;
inline void noise_init_() {
VCO1_phase = 0;
init_chaos();
last_CV1 = 0;
}
inline void noise_loop_() {
int32_t CV1_value, CV2_value, CV3_value, CV4_value;
int32_t tmpS, pot3_tmp, pot5_tmp;
uint32_t tmp;
int32_t freq;
filter16_nozori_68
test_connect_loop_68();
chaos(16); // for default mod values
if (CV3_connect < 60) CV3_value = CV_filter16_out[index_filter_cv3] - CV3_0V; else CV3_value = (chaos_dx>>16);
if (CV4_connect < 60) CV4_value = CV_filter16_out[index_filter_cv4] - CV4_0V; else CV4_value = (chaos_dy>>16);
CV3_value = min(0x7FFF,max(-0x7FFF,CV3_value));
CV4_value = min(0x7FFF,max(-0x7FFF,CV4_value));
led2((CV3_value+0x7FFF)>>7);
led4((CV4_value+0x7FFF)>>7);
// fq
//macro_fq_in
//freq = (CV_filter16_out[index_filter_pot1])<<11;
//freq += 0x06000000;
freq = (CV_filter16_out[index_filter_pot1])<<12;
macro_FqMod_fine(pot2,CV2)
macro_fq2increment
increment_1 = increment1;
//filter
pot3_tmp = CV_filter16_out[index_filter_pot3];
tmpS = CV3_value;
tmpS *= CV_filter16_out[index_filter_pot4];
tmpS >>= 16;
pot3_tmp += tmpS;
pot3_tmp = min(0xFFFF, max(0,pot3_tmp));
//high_gain = pot3_tmp;
pot5_tmp = CV_filter16_out[index_filter_pot5];
tmpS = CV4_value;
tmpS *= CV_filter16_out[index_filter_pot6];
tmpS >>= 16;
pot5_tmp += tmpS;
pot5_tmp = min(0xFFFF, max(0,pot5_tmp));
//low_gain = pot5_tmp;
//tmp = pot3_tmp; // passage en unsigned
//tmp *= tmp; // TODO : better curve???
//tmp >>= 17;
//high_gain = max(10,tmp)-10;
//freq = _min(0xFA00000, freq); /*20KHz max*/
freq = pot3_tmp << 12;
freq_MSB = freq >> 18; /* keep the 1st 10 bits */
freq_LSB = freq & 0x3FFFF; /* other 18 bits */
increment1 = table_CV2increment[freq_MSB];
increment2 = table_CV2increment[freq_MSB+1];
increment2 -= increment1;
increment1 += ((increment2>>8)*(freq_LSB>>2))>>8;
increment1 -= 60;
high_gain = increment1 * 5; // 31 bit max
//tmp= pot5_tmp; // passage en unsigned
//tmp *= tmp;
//tmp >>= 17;
//low_gain = max(10,tmp)-10;
freq = pot5_tmp << 12;
freq_MSB = freq >> 18; /* keep the 1st 10 bits */
freq_LSB = freq & 0x3FFFF; /* other 18 bits */
increment1 = table_CV2increment[freq_MSB];
increment2 = table_CV2increment[freq_MSB+1];
increment2 -= increment1;
increment1 += ((increment2>>8)*(freq_LSB>>2))>>8;
increment1 -= 60;
low_gain = increment1 * 12; // 31 bit max
}
inline void noise_audio_() {
int32_t tmpS, tmpS2;
int32_t out, out2;
if (CV1_connect < 60) {
if ( (last_CV1 == 0) && (CV_filter16_out[index_filter_CV1] > 0xB000) )
{
last_CV1 = 1;
switch(get_toggle()) { // noise type
case 0: // white
tmpS = random32();
noiseL = tmpS/3;// 30 bits + sign
tmpS = random32();
noiseR = tmpS/3;// 30 bits + sign
break;
case 1: // pink
tmpS = random32();
tmpS >>= 1; // limation de l'amplitude pour etre sur de ne pas saturer
filterL1 += (tmpS/128) - (filterL1>>9);
filterL2 += (tmpS/40) - (filterL2>>6);
filterL3 += (tmpS/12) - (filterL3>>3);
filterL4 = (tmpS/10);
tmpS = filterL1 + filterL2 + filterL3 + filterL4;
saturate_S31(tmpS, tmpS);
noiseL = tmpS;
tmpS = random32();
tmpS >>= 1; // limation de l'amplitude pour etre sur de ne pas saturer
filterR1 += (tmpS/128) - (filterR1>>9);
filterR2 += (tmpS/40) - (filterR2>>6);
filterR3 += (tmpS/12) - (filterR3>>3);
filterR4 = (tmpS/10);
tmpS = filterR1 + filterR2 + filterR3 + filterR4;
saturate_S31(tmpS, tmpS);
noiseR = tmpS;
break;
case 2: // red
tmpS = random32();
filterL1 += (tmpS>>5) - (filterL1>>9);
saturate_S31(filterL1, filterL1);
noiseL = filterL1;
tmpS = random32();
//tmpS >>= 1; // limation de l'amplitude pour etre sur de ne pas saturer
filterR1 += (tmpS>>5) - (filterR1>>9);
saturate_S31(filterR1, filterR1);
noiseR = filterR1;
break;
}
}
else if ( (last_CV1 == 1) && (CV_filter16_out[index_filter_CV1] < 0xA000)) {
last_CV1 = 0;
}
}
else {
VCO1_phase += increment_1<<4;
if (VCO1_phase & 0xC0000000) {
VCO1_phase &= 0x3FFFFFFF;
switch(get_toggle()) { // noise type
case 0: // white
tmpS = random32();
noiseL = tmpS/3;// 30bits + sign
tmpS = random32();
noiseR = tmpS/3;// 30bits + sign
break;
case 1: // pink
tmpS = random32();
tmpS >>= 1; // limation de l'amplitude pour etre sur de ne pas saturer
filterL1 += (tmpS/128) - (filterL1>>9);
filterL2 += (tmpS/40) - (filterL2>>6);
filterL3 += (tmpS/12) - (filterL3>>3);
filterL4 = (tmpS/10);
tmpS = filterL1 + filterL2 + filterL3 + filterL4;
saturate_S31(tmpS, tmpS);
noiseL = tmpS;
tmpS = random32();
tmpS >>= 1; // limation de l'amplitude pour etre sur de ne pas saturer
filterR1 += (tmpS/128) - (filterR1>>9);
filterR2 += (tmpS/40) - (filterR2>>6);
filterR3 += (tmpS/12) - (filterR3>>3);
filterR4 = (tmpS/10);
tmpS = filterR1 + filterR2 + filterR3 + filterR4;
saturate_S31(tmpS, tmpS);
noiseR = tmpS;
break;
case 2: // red
tmpS = random32();
filterL1 += (tmpS>>5) - (filterL1>>9);
saturate_S31(filterL1, filterL1);
noiseL = filterL1;
tmpS = random32();
//tmpS >>= 1; // limation de l'amplitude pour etre sur de ne pas saturer
filterR1 += (tmpS>>5) - (filterR1>>9);
saturate_S31(filterR1, filterR1);
noiseR = filterR1;
break;
}
}
}
//left
tmpS = noiseL - noiseL_filter_high; // 31 bits + sign
_m_s32xs32_s32(tmpS, high_gain, tmpS, tmpS2);
noiseL_filter_high += tmpS;
tmpS = noiseL - noiseL_filter_high; // hip
tmpS -= noiseL_filter_low; //31 bit + sign
_m_s32xs32_s32(tmpS, low_gain, tmpS, tmpS2);
noiseL_filter_low += tmpS<<1;
tmpS = noiseL_filter_low>>2;
tmpS *= 3;
saturate_S31(tmpS, tmpS);
tmpS <<= 1;
out = tmpS ^0x80000000;
//right
tmpS = noiseR - noiseR_filter_high; // 31 bits + sign
_m_s32xs32_s32(tmpS, high_gain, tmpS, tmpS2);
noiseR_filter_high += tmpS;
tmpS = noiseR - noiseR_filter_high; // hip
tmpS -= noiseR_filter_low; //31 bit + sign
_m_s32xs32_s32(tmpS, low_gain, tmpS, tmpS2);
noiseR_filter_low += tmpS<<1;
tmpS = noiseR_filter_low>>2;
tmpS *= 3;
saturate_S31(tmpS, tmpS);
tmpS <<= 1;
out2 = tmpS ^0x80000000;
macro_out_gain_pan_stereo
}