1#!/bin/sh
2# the next line restarts using wish \
3exec wish8.4 "$0" "$@"
4
5package require -exact snack 2.2
6
7snack::sound s1 -channels 2
8set leftMap [snack::filter map 1 0 0 0]
9set left(generator) [snack::filter generator 440 20000 0.0 sine -1]
10set leftFilter [snack::filter compose $left(generator) $leftMap]
11
12snack::sound s2 -channels 2
13set rightMap [snack::filter map 0 0 0 1]
14set right(generator) [snack::filter generator 440 20000 0.0 sine -1]
15set rightFilter [snack::filter compose $right(generator) $rightMap]
16
17pack [frame .fb] -side bottom
18pack [button .fb.a -bitmap snackPlay -command Play] -side left
19pack [button .fb.b -bitmap snackStop -command "snack::audio stop"] -side left
20
21set left(freq) 1000.0
22set left(ampl) 20000
23set right(freq) 2200.0
24set right(ampl) 20000
25
26pack [frame .left] -expand yes -fill both -side top
27pack [label .left.l -text "Left channel "] -side left
28pack [scale .left.s1 -label Frequency -from 4000 -to 50 -length 200\
29        -variable left(freq) -command [list Config left]] -side left -expand yes -fill both
30pack [scale .left.s2 -label Amplitude -from 32767 -to 0 -length 200\
31        -variable left(ampl) -command [list Config left]] -side left -expand yes -fill both
32tk_optionMenu .left.m1 left(type) sine rectangle triangle sawtooth noise
33foreach i [list 0 1 2 3 4] {
34 .left.m1.menu entryconfigure $i -command [list Config left]
35}
36pack .left.m1 -side left
37
38pack [frame .right] -expand yes -fill both -side top
39pack [label .right.l -text "Right channel"] -side left
40pack [scale .right.s1 -label Frequency -from 4000 -to 50 -length 200\
41        -variable right(freq) -command [list Config right]] -side left -expand yes -fill both
42pack [scale .right.s2 -label Amplitude -from 32767 -to 0 -length 200\
43        -variable right(ampl) -command [list Config right]] -side left -expand yes -fill both
44tk_optionMenu .right.m2 right(type) sine rectangle triangle sawtooth noise
45foreach i [list 0 1 2 3 4] {
46 .right.m2.menu entryconfigure $i -command [list Config right]
47}
48pack .right.m2 -side left
49
50proc Config {f args} {
51  set shape 0.0
52  upvar $f lf
53  set type $lf(type)
54  switch $type {
55    sine {
56      set shape 0.0
57    }
58    rectangle {
59      set shape 0.5
60    }
61    triangle {
62      set shape 0.5
63    }
64    sawtooth {
65      set shape 0.0
66      set type triangle
67    }
68  }
69  $lf(generator) configure $lf(freq) $lf(ampl) $shape $type -1
70}
71
72proc Play {} {
73  snack::audio stop
74  s1 play -filter $::leftFilter
75  s2 play -filter $::rightFilter
76}
77