-
Notifications
You must be signed in to change notification settings - Fork 16
/
chaotic-feedback-example.py
executable file
·49 lines (40 loc) · 2.1 KB
/
chaotic-feedback-example.py
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
#!/usr/bin/env python3
#------------------------------------------------------------------------
# SignalFlow: Chaotic feedback from FM self-modulation.
#------------------------------------------------------------------------
from signalflow import *
def main():
graph = AudioGraph()
graph.poll(1)
#------------------------------------------------------------------------
# Once per second, select a new random frequency (40-20000Hz)
#------------------------------------------------------------------------
f0 = RandomExponential(40, 2000, clock=RandomImpulse(1))
#------------------------------------------------------------------------
# Allocate a one-second buffer for use in the feedback line.
#------------------------------------------------------------------------
buf = Buffer(1, graph.sample_rate)
#------------------------------------------------------------------------
# op1 self-modulates by sending its output value to a
# FeedbackBufferWriter, and reading its previous outputs from a
# FeedbackBufferReader.
#------------------------------------------------------------------------
feedback = FeedbackBufferReader(buf)
op0 = SineOscillator(f0 + f0 * feedback * 14)
#------------------------------------------------------------------------
# Alter the level of self-oscillation once per second.
# Pass an array to RandomImpulse to generate different randomised
# sequences in the L/R channels, for stereo output.
#------------------------------------------------------------------------
level = Smooth(RandomUniform(0, 1, clock=RandomImpulse([0.5, 0.5])))
level = ScaleLinExp(level, 0, 1, 0.0001, 1.0)
op0 = op0 * level
graph.add_node(FeedbackBufferWriter(buf, op0, 0.5))
#------------------------------------------------------------------------
# Use the chaotic output of op0 to modulate a second sine oscillator.
#------------------------------------------------------------------------
op1 = SineOscillator(f0 + f0 * op0 * 14)
graph.play(op1)
graph.wait()
if __name__ == "__main__":
main()