File: callback_example.py

package info (click to toggle)
sndobj 2.6.7%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,952 kB
  • sloc: ansic: 55,663; cpp: 21,625; python: 391; makefile: 130; java: 22; sh: 21
file content (62 lines) | stat: -rw-r--r-- 1,127 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
56
57
58
59
60
61
62
#!/usr/bin/python
##########################################
#
#  Example using python callbacks
#
#  VL, 01/07

from sndobj import *
import time
import sys

class test:
    def get(self):
       return self.i
    def set(self,val):
        self.i = val
    def __init__(self,val):
       self.i = val

def callb(data):
    data[0].SetFreq(data[1].get(),data[2])
    data[1].set(data[1].get()+1)

def callc(data):
    data[0].SetFreq(data[1].get(),data[2])
    data[1].set(data[1].get()-1)

t = SndThread()
harm = HarmTable(10000,1,1)
osc = Oscili(harm, 440, 10000)
mod = Oscili(harm, 2, 5)
osc.SetFreq(440, mod)
tes = test(100)
dat = (osc, tes, mod)
if sys.platform[:6] == "darwin":
  outp = SndCoreAudio(2, 2048)
  outp.SetOutput(1, osc)
  outp.SetOutput(2, osc)
else:
  outp = SndRTIO(osc)

inp = SndRTIO(1, SND_INPUT, 2048,4)
t.SetProcessCallback(callb, dat)
t.AddObj(osc)
t.AddObj(mod)
t.AddObj(outp, SNDIO_OUT)
t.AddObj(inp, SNDIO_IN)
t.ProcOn()
time.sleep(2)
t.LimitVectorSize(64)

tes.set(100)
time.sleep(2)

t.SetProcessCallback(callc,dat)
tes.set(1000)
t.RestoreVectorSize()
time.sleep(2)
t.ProcOff()
time.sleep(2)