| 1 |
06-record-table.py - Recording live sound in RAM. |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
By recording a stream of sound in RAM, one can quickly re-use the |
| 6 |
samples in the current process. A combination NewTable - TableRec |
| 7 |
is all what one need to record any stream in a table. |
| 8 |
|
| 9 |
The NewTable object has a `feedback` argument, allowing overdub. |
| 10 |
|
| 11 |
The TableRec object starts a new recording (records until the table |
| 12 |
is full) every time its method `play()` is called. |
| 13 |
|
| 14 |
.. code-block:: python |
| 15 |
|
| 16 |
from pyo import * |
| 17 |
import os |
| 18 |
|
| 19 |
# Audio inputs must be available. |
| 20 |
s = Server(duplex=1).boot() |
| 21 |
|
| 22 |
# Path of the recorded sound file. |
| 23 |
path = os.path.join(os.path.expanduser("~"), "Desktop", "synth.wav") |
| 24 |
|
| 25 |
# Creates a two seconds stereo empty table. The "feedback" argument |
| 26 |
# is the amount of old data to mix with a new recording (overdub). |
| 27 |
t = NewTable(length=2, chnls=2, feedback=0.5) |
| 28 |
|
| 29 |
# Retrieves the stereo input |
| 30 |
inp = Input([0, 1]) |
| 31 |
|
| 32 |
# Table recorder. Call rec.play() to start a recording, it stops |
| 33 |
# when the table is full. Call it multiple times to overdub. |
| 34 |
rec = TableRec(inp, table=t, fadetime=0.05).play() |
| 35 |
|
| 36 |
# Reads the content of the table in loop. |
| 37 |
osc = Osc(table=t, freq=t.getRate(), mul=0.5).out() |
| 38 |
|
| 39 |
|
| 40 |
def saveToDisk(): |
| 41 |
savefileFromTable(table=t, path=path, fileformat=0, sampletype=3) |
| 42 |
|
| 43 |
|
| 44 |
# After two seconds, the table content is saved to a file on disk. |
| 45 |
sv = CallAfter(saveToDisk, time=2).play() |
| 46 |
|
| 47 |
s.gui(locals()) |
| 48 |
|