blob: 1aadbead3d4eccd95a1a609ad7f02daf0fde867d (
plain)
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
|
/*
* Sample based oscillator
* NOTE: may not be frequency-synced!
*/
public class SampOsc extends SndBuf {
1 => float __freq; /* pseudo-private */
fun float freq(float f)
{
return f => __freq;
}
fun float freq()
{
return __freq;
}
/*
* Wait till next loop point but no longer than 100::ms,
* so frequency changes get applied with a maximum of 100::ms latency.
* NOTE: Due to a ChucK bug, simply killing and restarting the shred
* does not work very well.
*/
fun void
__loop() /* pseudo-private */
{
now => time last_trigger;
while (second/__freq => dur interval) {
if (last_trigger+interval - now > 100::ms) {
100::ms => now;
} else {
interval +=> last_trigger;
if (last_trigger >= now)
last_trigger => now;
0 => pos;
}
}
}
spork ~ __loop();
/* FIXME: not independant from cwd when instantiated */
"lib/pulse.wav" => read;
1 => rate;
}
|