shithub: aubio

ref: 1b6a62deb6137e96437f0eb9924aac93006719b3
dir: /python.old/aubioplot-spec/

View raw version
#! /usr/bin/python

""" this file was written by Paul Brossier 
  it is released under the GNU/GPL license.
"""

import sys
from aubio.gnuplot import gnuplot_create,gnuplot_addargs,plot_spec 

usage = "usage: %s [options] -i soundfile" % sys.argv[0]

def parse_args():
        from optparse import OptionParser
        parser = OptionParser(usage=usage)
        parser.add_option("-i","--input",
                          action="store", dest="filename", 
                          help="input sound file")
        parser.add_option("-M","--maxf",
                          action="store", dest="maxf", default=10000., 
                          type='float',help="higher frequency limit")
        parser.add_option("-L","--minf",
                          action="store", dest="minf", default=0., 
                          type='float',help="lower frequency limit")
        parser.add_option("-l","--log",
                          action="store_true", dest="log", default=False, 
                          help="plot on a logarithmic scale")
        parser.add_option("-B","--bufsize", type='int',
                          action="store", dest="bufsize", default=8192, 
                          help="buffer size [default=8192]")
        parser.add_option("-H","--hopsize", type='int',
                          action="store", dest="hopsize", default=1024, 
                          help="overlap size [default=1024]")
        gnuplot_addargs(parser)
        (options, args) = parser.parse_args()
        if not options.filename: 
                 print "no file name given\n", usage
                 sys.exit(1)
        return options, args

options, args = parse_args()
filename = options.filename

if options.outplot: 
  extension = options.outplot.split('.')[-1] 
  outplot = '.'.join(options.outplot.split('.')[:-1])
else: 
  extension = ''
  outplot = None

g = gnuplot_create(outplot,extension,options)
plot_spec(filename, g, options)