Changeset - 4a51d4eefa95
[Not reviewed]
default
0 0 2
drewp@bigasterisk.com - 20 years ago 2005-04-17 08:41:28
drewp@bigasterisk.com
add wavecurve from semprini with new cmdline ui
2 files changed with 57 insertions and 0 deletions:
0 comments (0 inline, 0 general)
bin/wavecurve
Show inline comments
 
new file 100644
 
#!/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
light9/wavepoints.py
Show inline comments
 
new file 100644
 
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
0 comments (0 inline, 0 general)