File: 06-record-table.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 (45 lines) | stat: -rw-r--r-- 1,351 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
"""
06-record-table.py - Recording live sound in RAM.

By recording a stream of sound in RAM, one can quickly re-use the
samples in the current process. A combination NewTable - TableRec
is all what one need to record any stream in a table.

The NewTable object has a `feedback` argument, allowing overdub.

The TableRec object starts a new recording (records until the table
is full) every time its method `play()` is called.

"""
from pyo import *
import os

# Audio inputs must be available.
s = Server(duplex=1).boot()

# Path of the recorded sound file.
path = os.path.join(os.path.expanduser("~"), "Desktop", "synth.wav")

# Creates a two seconds stereo empty table. The "feedback" argument
# is the amount of old data to mix with a new recording (overdub).
t = NewTable(length=2, chnls=2, feedback=0.5)

# Retrieves the stereo input
inp = Input([0, 1])

# Table recorder. Call rec.play() to start a recording, it stops
# when the table is full. Call it multiple times to overdub.
rec = TableRec(inp, table=t, fadetime=0.05).play()

# Reads the content of the table in loop.
osc = Osc(table=t, freq=t.getRate(), mul=0.5).out()


def saveToDisk():
    savefileFromTable(table=t, path=path, fileformat=0, sampletype=3)


# After two seconds, the table content is saved to a file on disk.
sv = CallAfter(saveToDisk, time=2).play()

s.gui(locals())