Debian Codegraph @

pyo/examples/x10-tables/02-scrubbing.py

raw symbols SCIP
1 """
2 02-scrubbing.py - Navigate through a sound table.
3
4 The SndTable object allows to transfer the data from a soundfile
5 into a function table for a fast access to every sample.
6
7 This example illustrates how to do scrubbing with the mouse in
8 a sound window. The mouse position is then used to control the
9 position and the balance of a simple stereo granulator.
10
11 Give the focus to the Scrubbing window then click and move the mouse...
12
13 """
14
15 from pyo import *
16
17 s = Server().boot()
18
19 # The callback given to the SndTable.view() method.
20 def mouse(mpos):
21 print("X = %.2f, Y = %.2f" % tuple(mpos))
22 # X value controls the granulator pointer position.
23 position.value = mpos[0]
24 # Y value controls the balance between left and right channels.
25 l, r = 1.0 - mpos[1], mpos[1]
26 leftRightAmp.value = [l, r]
27
28
29 # Load and normalize the sound in the table.
30 snd = SndTable("../snds/ounkmaster.aif").normalize()
31 # Open the waveform view with a mouse position callback.
32 snd.view(title="Scrubbing window", mouse_callback=mouse)
33
34 # Left and right channel gain values.
35 leftRightAmp = SigTo([1, 1], time=0.1, init=[1, 1], mul=0.1)
36 # Position, in samples, in the SndTable.
37 position = SigTo(0.5, time=0.1, init=0.5, mul=snd.getSize(), add=Noise(5))
38
39 # Simple sound granulator.
40 gran = Granulator(
41 table=snd, # the sound table.
42 env=HannTable(), # the grain envelope.
43 pitch=[0.999, 1.0011], # global pitch (change every grain).
44 pos=position, # position in the table where to start a new grain.
45 dur=Noise(0.002, 0.1), # duration of the grain (can be used to transpose per grain).
46 grains=64, # the number of grains.
47 basedur=0.1, # duration for which the grain is not transposed.
48 mul=leftRightAmp, # stereo gain.
49 ).out()
50
51 s.gui(locals())