-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgls_mouse.ck
264 lines (220 loc) · 7.45 KB
/
gls_mouse.ck
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
260
261
262
263
264
/*
Lobanov Glottal Source Model
as described in:
Lobanov, B. M. PHD Thesis. Minsk, 1983.
Implemented in Chuck by Danila Gomulkin, 2017
Mouse controls:
<<< (left) - pitch down
>>> (right) - pitch up
^^^ (up) - relative pulse duration up ("skvazhnost")
VVV (down) - relative pulse duration down
left button - sound ON/OFF
right button - quit the program
*/
// headline
<<<"******************************">>>;
<<<" NEW SHRED ">>>;
<<<"******************************">>>;
//sound chain
Impulse pop => Gain out => Gain out1 => dac;
// variables for OSC/Hid/Serial control:
// Pitch (Hz)
100.0 => float pitch => float pitchNew;
0.95 => float pitchSmooth; // smoothening ratio
// T3 (duration of Force b) ratio to T0:
0.7 => float bForce => float bForceNew;
0.95 => float bForceSmooth; // smoothening ratio
// T1 (duration of Force b) ratio to T3:
0.3 => float aForce => float aForceNew;
0.95 => float aForceSmooth; // smoothening ratio
// smoothening function
fun void smoothStuff(){
while (true){
pitch*pitchSmooth + pitchNew*(1-pitchSmooth) => pitch;
bForce*bForceSmooth + bForceNew*(1-bForceSmooth) => bForce;
aForce*aForceSmooth + aForceNew*(1-aForceSmooth) => aForce;
//out2.gain()*volumeSmooth + volume*(1-volumeSmooth) => out2.gain;
20::ms => now;
}
}
// declare arrays
float popGain0[10000];
float popGain1[10000];
float popGain2[10000];
//variables
int T0, T3, T1;
float Pitch;
function void glottal(){
// SET PITCH (HZ)
if (pitch!= Pitch){
pitch => Pitch;
Std.ftoi(44100/Pitch) => T0; // duration of the cycle (samples, Fs=44100 Hz)
Std.ftoi(T0*bForce) => T3; // duration for Force B (samples) relative to T0
1.0/(T0*2) => out.gain; // scaling OUT gain DOWN (to be improved)
Std.ftoi(T3*aForce) => T1; // duration for Force A (samples) relative to T0
// no clipping down to 38 Hz (T0 under 1160 samples)
0.04 => float Force_A; // starting point fot further automatical adjusted
-0.04 => float Force_B; // fixed value
// fill them arrays
for (0 => int i; i < T1+1; i++){
Force_A => popGain0[i];
//<<<"gain0(", i, ")", popGain0[i]>>>;
}
for (T1 => int i; i < T3+1; i++){
Force_B => popGain0[i];
//<<<"gain0(", i, ")", popGain0[i]>>>;
}
//integrate x2
for (1=>int i; i < T3+1; i++){
popGain1[i-1] + popGain0[i] => popGain1[i]; // force => velocity (1)
//<<<"gain1(", i, ")", popGain1[i]>>>;
}
for (1 => int i; i < T3+1; i++){
popGain2[i-1] + popGain1[i] => popGain2[i]; // velocity => movement (2)
// <<<"gain2(", i, ")", popGain2[i]>>>;
}
// <<<"popGain2[T3]=",popGain2[T3]>>>;
if (popGain2[T3] < 0){
// <<<"popGain2[T3] < 0">>>;
while (popGain2[T3] < 0){
Force_A + 0.0001 => Force_A;
// <<<"Force_A =", Force_A>>>;
// fill them arrays again
for (0 => int i; i < T1+1; i++){
Force_A => popGain0[i];
// <<<"gain0(", i, ")", popGain0[i]>>>;
}
for (T1 => int i; i < T3+1; i++){
Force_B => popGain0[i];
// <<<"gain0(", i, ")", popGain0[i]>>>;
}
//integrate two times again
for (1=>int i; i < T3+1; i++){
popGain1[i-1] + popGain0[i] => popGain1[i]; // force => velocity
// <<<"gain1(", i, ")", popGain1[i]>>>;
}
for (1=>int i; i < T3+1; i++){
popGain2[i-1] + popGain1[i] => popGain2[i]; // velocity => displacement
// <<<"gain2(", i, ")", popGain2[i]>>>;
}
<<<"popGain2[T3]=",popGain2[T3]>>>;
}
}
if (popGain2[T3] > 1){
// <<< "popGain2[T3] > 1" >>>;
while (popGain2[T3] > 1 ){
Force_A - 0.0001 => Force_A;
// <<<"Force_A =", Force_A>>>;
// fill them arrays again
for (0 => int i; i < T1+1; i++){
Force_A => popGain0[i];
// <<<"gain0(", i, ")", popGain0[i]>>>;
}
for (T1 => int i; i < T3+1; i++){
Force_B => popGain0[i];
// <<<"gain0(", i, ")", popGain0[i]>>>;
}
//integrate two times again
for (1=>int i; i < T3+1; i++){
popGain1[i-1] + popGain0[i] => popGain1[i]; // force => velocity
// <<<"gain1(", i, ")", popGain1[i]>>>;
}
for (1=>int i; i < T3+1; i++){
popGain2[i-1] + popGain1[i] => popGain2[i]; // velocity => displacement
// <<<"gain2(", i, ")", popGain2[i]>>>;
}
<<<"popGain2[T3]=",popGain2[T3]>>>;
}
}
else{
}
// print final gain values:
/*
for (1 => int i; i < T3+1; i++){
<<<"gain2(", i, ")", popGain2[i]>>>;
}
*/
<<<"******************************">>>;
//<<<"T0 =", T0, "(cycle) / T3 =", T3, "(open) / T1 =", T1, "(up)">>>;
<<<"Pitch =", Pitch, "Hz, Fs = 44100 Hz">>>;
<<<"T0 =", T0, "sm / T3 =", T3, "sm / T1 =", T1, "sm">>>;
<<<"Force_A = ", Force_A, "(calculated)">>>;
<<<"Force_B =", Force_B, "(set)">>>;
<<<"popGain2[T3]=", popGain2[T3]>>>;
<<<"******************************">>>;
}
}
//play
function void play(){
while(true){
glottal();
for(0 => int i; i < T0+1; i++){
popGain2[i] => pop.gain;
1 => pop.next;
1::samp => now;
if (pop.last() > 20000){ // just in case
<<<"Too loud!">>>;
break;
}
}
}
}
// MOUSE CONTROL*************************************************
// from mouse-fm.ck by Spencer Salazar
// which mouse
0 => int device;
// get from command line
if( me.args() ) me.arg(0) => Std.atoi => device;
// variables
100.0 => float a0;
0.7 => float a1;
0.3 => float a2;
1 => int count;
// start things
//set( base, a0, a1, a2 );
// hid objects
Hid hi;
HidMsg msg;
// try
if( !hi.openMouse( device ) ) me.exit();
<<< "mouse '" + hi.name() + "' ready...", "" >>>;
// END OF MOUSE CONTROL*****************************************
function void mouseControl(){
// infinite time loop
while( true )
{
// wait on event
hi => now;
// loop over messages
while( hi.recv(msg) ){
if( msg.isMouseMotion() ){
msg.deltaX*.2 + a0 => a0;
-msg.deltaY*.001 + a1 => a1;
a0 => pitchNew;
a1 => bForceNew;
//<<<"pitchNew =", pitchNew>>>;
}
else if( msg.isButtonDown() & msg.which==0){
//msg.which => base;
count++;
if( count%2 == 1 ){
1 => out1.gain;
<<<"sound ON">>>;
}
else {
0 => out1.gain;
<<<"sound OFF">>>;
}
}
else if( msg.isButtonDown() & msg.which==1){
Machine.remove(1);
<<<"right buttom down!!">>>;
}
}
0.2::second=>now;
}
}
spork ~ mouseControl();
spork ~ smoothStuff();
play();
// CONTROLS