/usr/share/doc/tcl-snack-doc/examples/tcl/polarspec.tcl is in tcl-snack-doc 2.2.10.20090623-dfsg-6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #!/bin/sh
# the next line restarts using wish \
exec wish8.5 "$0" "$@"
package require -exact snack 2.2
set rate 16000
snack::sound s -rate $rate
# Length of FFT
set n 1024
set type FFT
# Start recording, create polygon, and schedule a draw in 100 ms
proc Start {} {
Stop
set ::pos 0
.c delete all
.c create polygon -1 -1 -1 -1 -tags polar -fill green
s record
after 100 Draw
}
# Stop recording and updating the plot
proc Stop {} {
s stop
after cancel Draw
}
# Calculate spectrum and plot it
proc Draw {} {
if {[s length] > $::n} {
set ::pos [expr [s length] - $::n]
set spec [s dBPowerSpectrum -start $::pos -fftlen $::n -winlen $::n \
-analysistype $::type]
set coords {}
set f 0.0001
foreach val $spec {
set v [expr {6.282985 * log($f)/log(2.0)}]
set a [expr {[winfo height .c]/214.0*($val+100)}]
set x [expr {[winfo width .c]/2+$a*cos($v)}]
set y [expr {[winfo height .c]/2+$a*sin($v)}]
lappend coords $x $y
set f [expr {$f + 16000.0 / $::n}]
}
eval .c coords polar $coords
}
after 10 Draw
if {[s length -unit sec] > 20} Stop
}
# Create simple GUI
pack [ frame .f] -side bottom
pack [ button .f.b1 -bitmap snackRecord -command Start -fg red -width 40] \
-side left
pack [ button .f.b2 -bitmap snackStop -command Stop -width 40] -side left
pack [ radiobutton .f.b3 -text FFT -variable type -value FFT] -side left
pack [ radiobutton .f.b4 -text LPC -variable type -value LPC] -side left
pack [ canvas .c -width 300 -height 300 -bg black] -side top -expand true \
-fill both
.c create text 150 150 -text "Polar spectrum plot of microphone signal" \
-fill red
|