Mercurial > code > home > repos > light9
changeset 221:4a51d4eefa95
add wavecurve from semprini with new cmdline ui
author | drewp@bigasterisk.com |
---|---|
date | Sun, 17 Apr 2005 08:41:28 +0000 |
parents | 13c089886f61 |
children | bb4d1e9b30c1 |
files | bin/wavecurve light9/wavepoints.py |
diffstat | 2 files changed, 57 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/wavecurve Sun Apr 17 08:41:28 2005 +0000 @@ -0,0 +1,17 @@ +#!/usr/bin/env python +import os, sys, optparse +import run_local +from light9.wavepoints import simp + +parser = optparse.OptionParser() +parser.add_option("-t",type="float",default=.01, + help="seconds per sample (default .01, .07 is smooth)") +options,args = parser.parse_args() + +inpath,outpath = args + +points = simp(inpath, seconds_per_average=options.t) + +f = file(outpath, 'w') +for time_val in points: + print >>f, "%s %s" % time_val
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light9/wavepoints.py Sun Apr 17 08:41:28 2005 +0000 @@ -0,0 +1,40 @@ +from __future__ import division +import wave, audioop + +def simp(filename, seconds_per_average=0.001): + """smaller seconds_per_average means fewer data points""" + wavefile = wave.open(filename, 'rb') + print "# gnuplot data for %s, seconds_per_average=%s" % \ + (filename, seconds_per_average) + print "# %d channels, samplewidth: %d, framerate: %s, frames: %d\n# Compression type: %s (%s)" % wavefile.getparams() + + framerate = wavefile.getframerate() # frames / second + frames_to_read = int(framerate * seconds_per_average) + print "# frames_to_read=%s" % frames_to_read + + time_and_max = [] + values = [] + count = 0 + while 1: + fragment = wavefile.readframes(frames_to_read) + if not fragment: + break + + # other possibilities: + # m = audioop.avg(fragment, 2) + # print count, "%s %s" % audioop.minmax(fragment, 2) + + m = audioop.rms(fragment, wavefile._framesize) + time_and_max.append((count, m)) + values.append(m) + count += frames_to_read + # if count>1000000: + # break + + # find the min and max + min_value, max_value = min(values), max(values) + points = [] # (secs,height) + for count, value in time_and_max: + points.append((count/framerate, + (value - min_value) / (max_value - min_value))) + return points