Advertisement
wandrake

Untitled

May 12th, 2012
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import numpy
  4. import wave
  5. import sys
  6.  
  7. w = wave.open(sys.argv[1])
  8.  
  9. buf = w.readframes(65536)
  10. res = [0, 0, 0, 0, 0, 0, 0, 0]
  11. i = 0
  12. x = []
  13. blackman = numpy.blackman(65536)
  14. while 65536*i < w.getnframes():
  15.     w.setpos(65536*i)
  16.     x = []
  17.     for j in range(0, len(buf)/2):
  18.         tmp = buf[2*j]+buf[2*j+1]
  19.         x.append((int(tmp.encode('hex'), 16)-32768)*blackman[j])
  20.     i += 1
  21.     t = numpy.fft.fft(x)
  22.  
  23.     k = -1
  24.     for j in range (0, 22001):
  25.         if j <= 20:
  26.             k = 0
  27.         elif j <= 40:
  28.             k = 1
  29.         elif j <= 160:
  30.             k = 2
  31.         elif j <= 315:
  32.             k = 3
  33.         elif j <= 2500:
  34.             k = 4
  35.         elif j <= 5000:
  36.             k = 5
  37.         elif j <= 10000:
  38.             k = 6
  39.         elif j <= 20000:
  40.             k = 7
  41.  
  42.         if k <> -1:
  43.             res[k] += abs(t[j])
  44.  
  45. res[0] /= 20
  46. res[1] /= 20
  47. res[2] /= 120
  48. res[3] /= 315-160
  49. res[4] /= 2500-315
  50. res[5] /= 2500
  51. res[6] /= 5000
  52. res[7] /= 10000
  53.  
  54. for n in range(0, 8):
  55.     res[n] /= i
  56.  
  57. print res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement