Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import numpy
- import wave
- import sys
- w = wave.open(sys.argv[1])
- buf = w.readframes(65536)
- res = [0, 0, 0, 0, 0, 0, 0, 0]
- i = 0
- x = []
- blackman = numpy.blackman(65536)
- while 65536*i < w.getnframes():
- w.setpos(65536*i)
- x = []
- for j in range(0, len(buf)/2):
- tmp = buf[2*j]+buf[2*j+1]
- x.append((int(tmp.encode('hex'), 16)-32768)*blackman[j])
- i += 1
- t = numpy.fft.fft(x)
- k = -1
- for j in range (0, 22001):
- if j <= 20:
- k = 0
- elif j <= 40:
- k = 1
- elif j <= 160:
- k = 2
- elif j <= 315:
- k = 3
- elif j <= 2500:
- k = 4
- elif j <= 5000:
- k = 5
- elif j <= 10000:
- k = 6
- elif j <= 20000:
- k = 7
- if k <> -1:
- res[k] += abs(t[j])
- res[0] /= 20
- res[1] /= 20
- res[2] /= 120
- res[3] /= 315-160
- res[4] /= 2500-315
- res[5] /= 2500
- res[6] /= 5000
- res[7] /= 10000
- for n in range(0, 8):
- res[n] /= i
- print res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement