Debian Codegraph @

docs/_sources/examples/21-utilities/06-batch-synthesis.rst.txt

raw
1 Offline batch generation of synthesis sounds
2 ============================================================================================================================================
3
4
5 **06-batch-synthesis.py**
6
7 This program demonstrates how to use pyo to do offline synthesis batch
8 generation.
9
10 .. code-block:: python
11
12 import os
13 from pyo import *
14
15 # Initialize the Server in offline mode.
16 s = Server(duplex=0, audio="offline")
17
18 # Path to the output sound folder (user's home directory/pyo_batch_synth/).
19 output_folder = os.path.join(os.path.expanduser("~"), "pyo_batch_synth")
20
21 # Create the folder if it does not exist.
22 if not os.path.isdir(output_folder):
23 os.mkdir(output_folder)
24
25 # Output file duration.
26 dur = 2
27
28 # How many file to generate.
29 NUM = 12
30
31 # Enter the batch synthesis loop.
32 for i in range(NUM):
33 # Boot the Server.
34 s.boot()
35
36 # Define the pitch of the note.
37 note = 60 + i
38 noteFreq = midiToHz(note)
39
40 # Set recording parameters.
41 s.recordOptions(
42 dur=dur + 0.1, filename=os.path.join(output_folder, "file_%02d.wav" % note), fileformat=0, sampletype=0,
43 )
44
45 # Synthesis, an exponential envelope modulating a slightly out-of-tune stereo oscillator.
46 env = Adsr(attack=0.005, decay=0.15, sustain=0.7, release=1.7, dur=dur).play()
47 qenv = Pow(env, 4, mul=0.8)
48 osc1 = SineLoop(freq=noteFreq, feedback=0.075, mul=qenv).out()
49 osc2 = SineLoop(freq=noteFreq * 1.01, feedback=0.075, mul=qenv).out(1)
50
51 # Start thw rendering.
52 s.start()
53
54 # Cleanup for the next pass.
55 s.shutdown()
56
57 print("Batch processing done!")
58