1#!/bin/sh
2# the next line restarts using wish \
3exec wish8.4 "$0" "$@"
4
5package require -exact snack 2.2
6
7set f [snack::filter generator 440.0]
8snack::sound s
9#snack::audio playLatency 200
10
11tk_optionMenu .m v(type) sine rectangle triangle sawtooth noise
12foreach i [list 0 1 2 3 4] {
13  .m.menu entryconfigure $i -command Config
14}
15pack .m -side bottom
16
17pack [frame .fb] -side bottom
18pack [button .fb.a -bitmap snackPlay -command Play] -side left
19pack [button .fb.b -bitmap snackStop -command "s stop"] -side left
20
21set v(freq) 440.0
22set v(ampl) 20000
23
24pack [frame .f] -expand yes -fill both -side top
25pack [scale .f.s1 -label Frequency -from 4000 -to 50 -length 200\
26        -variable v(freq) -command Config] -side left -expand yes -fill both
27pack [scale .f.s2 -label Amplitude -from 32767 -to 0 -length 200\
28        -variable v(ampl) -command Config] -side left -expand yes -fill both
29
30proc Config {args} {
31  global f v
32  set shape 0.0
33  set type $v(type)
34  switch $type {
35    sine {
36      set shape 0.0
37    }
38    rectangle {
39      set shape 0.5
40    }
41    triangle {
42      set shape 0.5
43    }
44    sawtooth {
45      set shape 0.0
46      set type triangle
47    }
48  }
49  $f configure $v(freq) $v(ampl) $shape $type -1
50}
51
52proc Play {} {
53  global f
54  s stop
55  s play -filter $f
56}
57