File: 06-batch-synthesis.py

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (55 lines) | stat: -rw-r--r-- 1,433 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
"""
Offline batch generation of synthesis sounds  

**06-batch-synthesis.py**

This program demonstrates how to use pyo to do offline synthesis batch
generation.

"""
import os
from pyo import *

# Initialize the Server in offline mode.
s = Server(duplex=0, audio="offline")

# Path to the output sound folder (user's home directory/pyo_batch_synth/).
output_folder = os.path.join(os.path.expanduser("~"), "pyo_batch_synth")

# Create the folder if it does not exist.
if not os.path.isdir(output_folder):
    os.mkdir(output_folder)

# Output file duration.
dur = 2

# How many file to generate.
NUM = 12

# Enter the batch synthesis loop.
for i in range(NUM):
    # Boot the Server.
    s.boot()

    # Define the pitch of the note.
    note = 60 + i
    noteFreq = midiToHz(note)

    # Set recording parameters.
    s.recordOptions(
        dur=dur + 0.1, filename=os.path.join(output_folder, "file_%02d.wav" % note), fileformat=0, sampletype=0,
    )

    # Synthesis, an exponential envelope modulating a slightly out-of-tune stereo oscillator.
    env = Adsr(attack=0.005, decay=0.15, sustain=0.7, release=1.7, dur=dur).play()
    qenv = Pow(env, 4, mul=0.8)
    osc1 = SineLoop(freq=noteFreq, feedback=0.075, mul=qenv).out()
    osc2 = SineLoop(freq=noteFreq * 1.01, feedback=0.075, mul=qenv).out(1)

    # Start thw rendering.
    s.start()

    # Cleanup for the next pass.
    s.shutdown()

print("Batch processing done!")