File: generator2.tcl

package info (click to toggle)
snack 2.2.10.20090623-dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,764 kB
  • sloc: ansic: 32,662; sh: 8,558; tcl: 1,086; python: 761; makefile: 582
file content (76 lines) | stat: -rwxr-xr-x 2,475 bytes parent folder | download | duplicates (12)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
# the next line restarts using wish \
exec wish8.4 "$0" "$@"

package require -exact snack 2.2

snack::sound s1 -channels 2
set leftMap [snack::filter map 1 0 0 0]
set left(generator) [snack::filter generator 440 20000 0.0 sine -1]
set leftFilter [snack::filter compose $left(generator) $leftMap]

snack::sound s2 -channels 2
set rightMap [snack::filter map 0 0 0 1]
set right(generator) [snack::filter generator 440 20000 0.0 sine -1]
set rightFilter [snack::filter compose $right(generator) $rightMap]

pack [frame .fb] -side bottom
pack [button .fb.a -bitmap snackPlay -command Play] -side left
pack [button .fb.b -bitmap snackStop -command "snack::audio stop"] -side left

set left(freq) 1000.0
set left(ampl) 20000
set right(freq) 2200.0
set right(ampl) 20000

pack [frame .left] -expand yes -fill both -side top
pack [label .left.l -text "Left channel "] -side left
pack [scale .left.s1 -label Frequency -from 4000 -to 50 -length 200\
        -variable left(freq) -command [list Config left]] -side left -expand yes -fill both
pack [scale .left.s2 -label Amplitude -from 32767 -to 0 -length 200\
        -variable left(ampl) -command [list Config left]] -side left -expand yes -fill both
tk_optionMenu .left.m1 left(type) sine rectangle triangle sawtooth noise
foreach i [list 0 1 2 3 4] {
 .left.m1.menu entryconfigure $i -command [list Config left]
}
pack .left.m1 -side left

pack [frame .right] -expand yes -fill both -side top
pack [label .right.l -text "Right channel"] -side left
pack [scale .right.s1 -label Frequency -from 4000 -to 50 -length 200\
        -variable right(freq) -command [list Config right]] -side left -expand yes -fill both
pack [scale .right.s2 -label Amplitude -from 32767 -to 0 -length 200\
        -variable right(ampl) -command [list Config right]] -side left -expand yes -fill both
tk_optionMenu .right.m2 right(type) sine rectangle triangle sawtooth noise
foreach i [list 0 1 2 3 4] {
 .right.m2.menu entryconfigure $i -command [list Config right]
}
pack .right.m2 -side left

proc Config {f args} {
  set shape 0.0
  upvar $f lf
  set type $lf(type)
  switch $type {
    sine {
      set shape 0.0
    }
    rectangle {
      set shape 0.5
    }
    triangle {
      set shape 0.5
    }
    sawtooth {
      set shape 0.0
      set type triangle
    }
  }
  $lf(generator) configure $lf(freq) $lf(ampl) $shape $type -1
}

proc Play {} {
  snack::audio stop
  s1 play -filter $::leftFilter
  s2 play -filter $::rightFilter
}