File: generator.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 (56 lines) | stat: -rwxr-xr-x 1,270 bytes parent folder | download | duplicates (7)
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
#!/bin/sh
# the next line restarts using wish \
exec wish8.5 "$0" "$@"

package require -exact snack 2.2

set f [snack::filter generator 440.0]
snack::sound s
#snack::audio playLatency 200

tk_optionMenu .m v(type) sine rectangle triangle sawtooth noise
foreach i [list 0 1 2 3 4] {
  .m.menu entryconfigure $i -command Config
}
pack .m -side bottom

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

set v(freq) 440.0
set v(ampl) 20000

pack [frame .f] -expand yes -fill both -side top
pack [scale .f.s1 -label Frequency -from 4000 -to 50 -length 200\
        -variable v(freq) -command Config] -side left -expand yes -fill both
pack [scale .f.s2 -label Amplitude -from 32767 -to 0 -length 200\
        -variable v(ampl) -command Config] -side left -expand yes -fill both

proc Config {args} {
  global f v
  set shape 0.0
  set type $v(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
    }
  }
  $f configure $v(freq) $v(ampl) $shape $type -1
}

proc Play {} {
  global f
  s stop
  s play -filter $f
}