Debian Codegraph @

docs/_sources/examples/04-soundfiles/05-record-streams.rst.txt

raw
1 05-record-streams.py - Recording individual audio streams on disk.
2 ============================================================================================================================================
3
4
5 The Record object can be used to record specific audio streams
6 from a performance. It can be useful to record a sound in mutiple
7 tracks to make post-processing on individual part easier. This
8 example record the bass, the mid and the higher part in three
9 separated files on the user's desktop.
10
11 The `fileformat` and `sampletype` arguments are the same as in
12 the Server's `recordOptions` method.
13
14 .. code-block:: python
15
16 from pyo import *
17 import os
18
19 s = Server().boot()
20
21 # Defines sound file paths.
22 path = os.path.join(os.path.expanduser("~"), "Desktop")
23 bname = os.path.join(path, "bass.wav")
24 mname = os.path.join(path, "mid.wav")
25 hname = os.path.join(path, "high.wav")
26
27 # Creates an amplitude envelope
28 amp = Fader(fadein=1, fadeout=1, dur=10, mul=0.3).play()
29
30 # Bass voice
31 blfo = Sine(freq=[0.15, 0.16]).range(78, 82)
32 bass = RCOsc(freq=blfo, mul=amp).out()
33
34 # Mid voice
35 mlfo = Sine(freq=[0.18, 0.19]).range(0.24, 0.26)
36 mid = FM(carrier=1600, ratio=mlfo, index=5, mul=amp * 0.3).out()
37
38 # High voice
39 hlfo = Sine(freq=[0.1, 0.11, 0.12, 0.13]).range(7000, 8000)
40 high = Sine(freq=hlfo, mul=amp * 0.1).out()
41
42 # Creates the recorders
43 brec = Record(bass, filename=bname, chnls=2, fileformat=0, sampletype=1)
44 mrec = Record(mid, filename=mname, chnls=2, fileformat=0, sampletype=1)
45 hrec = Record(high, filename=hname, chnls=2, fileformat=0, sampletype=1)
46
47 # After 10.1 seconds, recorder objects will be automatically deleted.
48 # This will trigger their stop method and properly close the sound files.
49 clean = Clean_objects(10.1, brec, mrec, hrec)
50
51 # Starts the internal timer of Clean_objects. Use its own thread.
52 clean.start()
53
54 # Starts the Server, in order to be sync with the cleanup process.
55 s.start()
56
57 s.gui(locals())
58