File: polarspec.py

package info (click to toggle)
snack 2.2.10.20090624%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,868 kB
  • sloc: ansic: 32,602; sh: 8,558; tcl: 1,086; python: 761; makefile: 578
file content (64 lines) | stat: -rwxr-xr-x 1,501 bytes parent folder | download | duplicates (5)
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
#! /usr/bin/env python

import sys
if sys.version_info[0] == 2:
    from Tkinter import *
else:
    from tkinter import *

from tkSnack import *
from math import *

root = Tkinter.Tk()

initializeSnack(root)
snd = Sound()

w = 300
h = 300
s = 100
n = 1024
type = StringVar()
type.set("FFT") 

def stop():
    snd.stop()
    root.after_cancel(id)

def draw():
    if (snd.length() > n) :
        pos = snd.length() - n
        spec = snd.dBPowerSpectrum(start=pos,fftlen=n,winlen=n,analysistype=type.get())
        coords=[]
        f=0.0001
        for val in spec :
            v = 6.282985 * log(f)/log(2.0)
            a = 1.4*(val+s)
            x = w/2+a*cos(v)
            y = h/2+a*sin(v)
            coords.append(x)
            coords.append(y)
            f = f + 16000.0 / n
        c.delete('polar')
        c.create_polygon(coords, tags='polar', fill='green')
    if (snd.length(unit='sec') > 20) :
        stop()
    id = root.after(100,draw)
        
def start():
    pos = 0
    snd.record()
    c.update_idletasks()
    id = root.after(100,draw)

c = SnackCanvas(height=h, width=w, bg='black')
c.pack()
f = Frame()
f.pack()
Button(f, bitmap='snackRecord', fg='red', command=start).pack(side='left')
Button(f, bitmap='snackStop', command=stop).pack(side='left')
Radiobutton(f, text='FFT', variable=type, value='FFT').pack(side='left')
Radiobutton(f, text='LPC', variable=type, value='LPC').pack(side='left')
Button(f, text='Exit', command=root.quit).pack(side='left')

root.mainloop()