-
Notifications
You must be signed in to change notification settings - Fork 2
/
m84_SEQ4.ino
136 lines (122 loc) · 4.25 KB
/
m84_SEQ4.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
// --------------------------------------------------------------------------
// 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/>.
// --------------------------------------------------------------------------
//Seq 4
// Pot 1 : Value 1
// Pot 2 : Time 1
// Pot 3 : Value 2
// Pot 4 : Time 2
// Pot 5 : Value 3
// Pot 6 : Time 3
// Pot 7 : Value 4
// Pot 8 : Time 4
// IN 1 : clock
// IN 2 : Effect
// Selecteur3 : effect type (skip / long gate / glide)
// OUT 1 : Gate
// OUT 2 : Value
uint32_t time_value[4], out_value[4];
uint32_t clock_div, current_pos;
bool last_gate, new_clock;
uint32_t value_out, gate_out;
uint32_t interpol_increment, interpol_A, interpol_B;
bool do_interpol;
inline void SEQ4_init_() {
last_gate = false;
clock_div = 1;
}
inline void SEQ4_loop_() {
uint32_t toggle;
filter16_nozori_84
test_connect_loop_84();
toggle = get_toggle();
toggle_global = toggle;
//time_value[0] = CV_filter16_out[index_filter_pot2] / 7282; // from 0 to 8
//time_value[1] = CV_filter16_out[index_filter_pot4] / 7282;
//time_value[2] = CV_filter16_out[index_filter_pot6] / 7282;
//time_value[3] = CV_filter16_out[index_filter_pot8] / 7282;
time_value[0] = (CV_filter16_out[index_filter_pot2] + 4095) / 8192;
time_value[1] = (CV_filter16_out[index_filter_pot4] + 4095) / 8192;
time_value[2] = (CV_filter16_out[index_filter_pot6] + 4095) / 8192;
time_value[3] = (CV_filter16_out[index_filter_pot8] + 4095) / 8192;
out_value[0] = CV_filter16_out[index_filter_pot1];
out_value[1] = CV_filter16_out[index_filter_pot3];
out_value[2] = CV_filter16_out[index_filter_pot5];
out_value[3] = CV_filter16_out[index_filter_pot7];
}
inline void SEQ4_audio_() {
uint32_t time_all, toggle, tmp;
int32_t tmpS;
nb_tick++;
toggle = toggle_global;
if ( (IN1_connect < 60) && (audio_inL > 0xB0000000) && (last_gate== false) ) {
last_gate = true;
new_clock = true;
last_clock_ = nb_tick;
nb_tick = 0;
if ( (toggle==1) && (IN2_connect < 60) && (audio_inR > 0xB0000000) ) {
gate_out = 0xE0000000;
}
}
else if ((IN1_connect < 60) && (audio_inL < 0xA0000000)) {
last_gate = false;
gate_out = OUT1_0V;
//if (!( (toggle==1) && (IN2_connect < 60) && (audio_inR > 0xB0000000) && (clock_div != 0) )) { // !long gate
// gate_out = OUT1_0V;
//}
}
if ( (new_clock) && (clock_div > 0) ) {
clock_div--;
new_clock = false;
}
if ( (new_clock) && (clock_div == 0) ) {
current_pos = (current_pos+1) & 0b11;
clock_div = time_value[current_pos];
if ((clock_div > 0)) {
clock_div--;
new_clock = false;
if (!((toggle==0) && (IN2_connect < 60) && (audio_inR > 0xB0000000))) { // if we are not in skip mode
gate_out = 0xE0000000;
if ((toggle==2) && (IN2_connect < 60) && (audio_inR > 0xB0000000)) { // glide mode
do_interpol = true;
interpol_B = out_value[current_pos];
interpol_A = audio_outR>>16;
interpol_increment = 0xFFFFFFFF / last_clock_;
interpol_increment /= clock_div+1;
interpol_pos = 0;
} else {
do_interpol = false;
value_out = out_value[current_pos];
}
}
}
}
if(do_interpol) {
interpol_pos += interpol_increment;
if (interpol_pos < interpol_increment) { // overflow
interpol_pos = 0xFFFFFFFF;
}
value_out = MIX16U(interpol_A>>1, interpol_B>>1, interpol_pos>>16)<<1;
}
audio_outL = gate_out;
tmp = value_out<<16;
tmpS = tmp^0x80000000;
tmpS -= tmpS >> 2;
tmp = tmpS^0x80000000;
audio_outR = tmp;
led2(min(gate_out-OUT1_0V,0x1FF));
led4(value_out>>7);
}