| 1 |
""" |
| 2 |
01-processes-spawning.py - Simple processes spawning, no synchronization. |
| 3 |
|
| 4 |
Need at least 4 cores to be really effective. |
| 5 |
|
| 6 |
Usage: |
| 7 |
python3 -i 01-processes-spawning.py |
| 8 |
|
| 9 |
""" |
| 10 |
import sys, time, random, multiprocessing |
| 11 |
from pyo import * |
| 12 |
|
| 13 |
if sys.platform.startswith("linux"): |
| 14 |
audio = "jack" |
| 15 |
elif sys.platform.startswith("darwin"): |
| 16 |
audio = "portaudio" |
| 17 |
else: |
| 18 |
print("Multicore examples don't run under Windows... Sorry!") |
| 19 |
exit() |
| 20 |
|
| 21 |
|
| 22 |
class Proc(multiprocessing.Process): |
| 23 |
def __init__(self, pitch): |
| 24 |
super(Proc, self).__init__() |
| 25 |
self.daemon = True |
| 26 |
self.pitch = pitch |
| 27 |
|
| 28 |
def run(self): |
| 29 |
self.server = Server(audio=audio) |
| 30 |
self.server.deactivateMidi() |
| 31 |
self.server.boot().start() |
| 32 |
|
| 33 |
|
| 34 |
self.amp = Fader(fadein=5, mul=0.01).play() |
| 35 |
lo, hi = midiToHz((self.pitch - 0.1, self.pitch + 0.1)) |
| 36 |
self.fr = Randi(lo, hi, [random.uniform(0.2, 0.4) for i in range(50)]) |
| 37 |
self.sh = Randi(0.1, 0.9, [random.uniform(0.2, 0.4) for i in range(50)]) |
| 38 |
self.osc = LFO(self.fr, sharp=self.sh, type=2, mul=self.amp).out() |
| 39 |
|
| 40 |
time.sleep(30) |
| 41 |
self.server.stop() |
| 42 |
|
| 43 |
|
| 44 |
if __name__ == "__main__": |
| 45 |
|
| 46 |
p1, p2, p3, p4 = Proc(48), Proc(52), Proc(55), Proc(60) |
| 47 |
p1.start() |
| 48 |
p2.start() |
| 49 |
p3.start() |
| 50 |
p4.start() |
| 51 |
time.sleep(35) |