forked from ch-nry/nozoid_nozori
-
Notifications
You must be signed in to change notification settings - Fork 0
/
m68_VCO_MORPH.ino
178 lines (146 loc) · 5.1 KB
/
m68_VCO_MORPH.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
// --------------------------------------------------------------------------
// 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/>.
// --------------------------------------------------------------------------
// VCO with control of the WF : square to saw to double saw and PWM control
// Pot 1 : FQ
// Pot 2 : Mod Fq (or fine if nothing is connected on the modulation)
// Pot 3 : WF
// Pot 4 : MOD WF (chaos if nothing is connected)
// Pot 5 : PWM
// Pot 6 : Mod PWM (chaos if nothing is connected)
// CV 1 : Pitch (1V/Oct)
// CV 2 : Mod Fq (1V/Oct a full)
// CV 3 : Mod WF
// CV 4 : Mod PWM
// IN 1 : GAIN (Exp)
// IN 2 : Pan
// Selecteur3 : Wave Form : Square / Double Saw / sin
// OUT 1 : OUT L
// OUT 2 : OUT R
// LED 1 : CV2
// LED 2 : CV3
uint32_t pot3_save, pot5_save, pot3_data, pot5_data;
inline uint32_t sawBL(uint32_t phase, uint32_t BLsize) {
uint32_t sinc, table_index;
table_index = phase;
table_index = (table_index & 0x80000000)? -table_index: table_index;
sinc = m_u32xu32_u32H(table_index, BLsize);
sinc = (sinc & 0xFFFFF000)? 0xFFF : sinc;
sinc = table_Isinc[sinc];
sinc = m_s32xs32_s32H(phase^0x80000000, (sinc << 16)^0x80000000);
sinc -= phase >> 1;
sinc -= 0x40000000;
sinc += sinc >>1;
sinc -= 0x40000000;
return(sinc);
}
inline void VCO_Param_init_() {
VCO1_phase = 0;
init_chaos();
}
inline void VCO_Param_loop_() {
int32_t pot5_tmp, pot3_tmp;
int32_t tmpS;
int32_t CV3_value, CV4_value;
filter16_nozori_68
test_connect_loop_68();
chaos(15); // 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));
// frequency control
macro_fq_in_tlg
macro_1VOct_CV1
macro_FqMod_fine(pot2,CV2)
macro_fq2increment
increment_0 = increment1;
// Wave Form control
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));
pot3_data = pot3_tmp;
// PWM
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));
pot5_data = pot5_tmp;
led2((CV3_value+0x7FFF)>>7);
//led3((chaos_dz^0x80000000)>>23);
led4((CV4_value+0x7FFF)>>7);
}
inline void VCO_Param_audio_() {
int32_t tmp, tmp1, tmp2, tmp4;
int32_t tmpS;
uint32_t VCO1_increment, VCO1_WS, VCO1_PWM, VCO1_offset, VCO1_gain, VCO1_BLsize;
uint32_t VCO2_BLsize;
uint32_t increment1;
uint32_t pot5_tmp, pot3_tmp;
uint32_t out, out2;
increment1 = increment_0;
//Waveform control
pot3_tmp = filter(pot3_data, pot3_save, 6);
pot3_save = pot3_tmp;
pot5_tmp = filter(pot5_data, pot5_save, 6);
pot5_save = pot5_tmp;
pot5_tmp = min(pot5_tmp, 0xFFFF-(min(0xFFFF,increment1>>10))); // limit du PWM en fct de la frequence pour ne pas avoir d'impulsion trop petite
VCO1_PWM = (0xFFFF-(pot5_tmp))<<15;
//VCO1_PWM = max(VCO1_PWM, increment1<<6);
VCO1_WS = (pot3_tmp)<<16;
tmp = pot3_tmp;
tmp = (tmp > (1<<15))? 0:(1<<15)-tmp; // 12 bits
tmp >>= 3; // 12 bits
VCO1_offset = (pot5_tmp) * 3 * tmp;
tmp = (pot3_tmp < (1<<15))? 0 : pot3_tmp - (1<<15);
tmp *= pot5_tmp;
VCO1_gain = 0x7FFFFFFF - (tmp>>1);
// compute output
VCO1_BLsize = (0xFFFFFFFF / increment1)<<4;
VCO1_phase += increment1<<3;
tmp1 = sawBL(VCO1_phase, VCO1_BLsize)>>1;
tmp1 -= 0x40000000;
tmp2 = sawBL(VCO1_phase + VCO1_PWM, VCO1_BLsize)>>1;
tmp2 -= 0x40000000;
_m_s32xs32_s32(tmp2, VCO1_WS>>1, tmp4, tmp);
tmp1 += tmp4<<2;
tmp1 -= tmp2;
tmp1 += VCO1_offset;
_m_s32xs32_s32(tmp1, VCO1_gain, tmp1, tmp2);
tmp1 <<= 2;
out2 = tmp1^0x80000000;
/////////////////////////////////////////////////////////////////////
// 2eme oscillateur
VCO2_BLsize = (0xFFFFFFFF / increment1)<<5;
VCO2_phase += increment1<<2;
tmp1 = sawBL(VCO2_phase, VCO2_BLsize)>>1;
tmp1 -= 0x40000000;
tmp2 = sawBL(VCO2_phase + VCO1_PWM, VCO2_BLsize)>>1;
tmp2 -= 0x40000000;
_m_s32xs32_s32(tmp2, VCO1_WS>>1, tmp4, tmp);
tmp1 += tmp4<<2;
tmp1 -= tmp2;
tmp1 += VCO1_offset;
_m_s32xs32_s32(tmp1, VCO1_gain, tmp1, tmp2);
tmp1 <<= 2;
out = tmp1^0x80000000;
macro_out_gain_pan_stereo
}