source: python/aubiocut @ 8d29cfe

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 8d29cfe was d9101a5, checked in by Paul Brossier <piem@altern.org>, 19 years ago

move aubiopitch to new tasks, comment out old task versions
move aubiopitch to new tasks, comment out old task versions

  • Property mode set to 100755
File size: 5.9 KB
RevLine 
[98df9f4]1#! /usr/bin/python
[96fb8ad]2
3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
[98df9f4]7import sys
[5e491b3b]8from aubio.tasks import *
[96fb8ad]9
[98df9f4]10usage = "usage: %s [options] -i soundfile" % sys.argv[0]
[96fb8ad]11
[98df9f4]12def parse_args():
13        from optparse import OptionParser
14        parser = OptionParser(usage=usage)
15        parser.add_option("-i","--input",
16                          action="store", dest="filename",
17                          help="input sound file")
[4f4a8a4]18        parser.add_option("-m","--mode",
[ada5baf]19                          action="store", dest="mode", default='dual',
[80c0417]20                          help="onset detection mode [default=dual] \
[2d04b86]21                          complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual")
[98df9f4]22        parser.add_option("-B","--bufsize",
[855ed0a]23                          action="store", dest="bufsize", default=512,
[61680aa]24                          help="buffer size [default=512]")
[98df9f4]25        parser.add_option("-H","--hopsize",
[2d04b86]26                          action="store", dest="hopsize", default=256,
27                          help="overlap size [default=256]")
[98df9f4]28        parser.add_option("-t","--threshold",
[2d04b86]29                          action="store", dest="threshold", default=0.650,
30                          help="onset peak picking threshold [default=0.650]")
[98df9f4]31        parser.add_option("-s","--silence",
32                          action="store", dest="silence", default=-70,
33                          help="silence threshold [default=-70]")
34        parser.add_option("-M","--mintol",
35                          action="store", dest="mintol", default=0.048,
36                          help="minimum inter onset interval [default=0.048]")
37        parser.add_option("-D","--delay",
[80c0417]38                          action="store", dest="delay", 
39                          help="number of seconds to take back [default=system]\
[855ed0a]40                          default system delay is 3*hopsize/samplerate")
[98df9f4]41        parser.add_option("-L","--localmin",
42                          action="store_true", dest="localmin", default=False,
43                          help="use local minima after peak detection")
44        parser.add_option("-c","--cut",
45                          action="store_true", dest="cut", default=False,
46                          help="cut input sound file at detected labels \
47                          best used with option -L")
[80c0417]48        parser.add_option("-d","--derivate",
49                          action="store_true", dest="derivate", default=False,
50                          help="derivate onset detection function")
[13340a68]51        parser.add_option("-S","--silencecut",
52                          action="store_true", dest="silencecut", default=False,
53                          help="outputs silence locations")
[98df9f4]54        parser.add_option("-z","--zerocross",
[427be71]55                          action="store", dest="zerothres", default=0.008,
[855ed0a]56                          help="zero-crossing threshold for slicing [default=0.00008]")
[80c0417]57        # plotting functions
58        parser.add_option("-p","--plot",
59                          action="store_true", dest="plot", default=False,
60                          help="draw plot")
61        parser.add_option("-O","--outplot",
62                          action="store", dest="outplot", default=None,
63                          help="save plot to output.{ps,png}")
[98df9f4]64        parser.add_option("-v","--verbose",
65                          action="store_true", dest="verbose", default=False,
66                          help="make lots of noise [default]")
67        parser.add_option("-q","--quiet",
68                          action="store_false", dest="verbose", default=False,
69                          help="be quiet")
[427be71]70        # to be implemented
71        parser.add_option("-b","--beat",
72                          action="store_true", dest="beat", default=False,
[d9101a5]73                          help="output beat locations")
[98df9f4]74        (options, args) = parser.parse_args()
75        if not options.filename:
76                 print "no file name given\n", usage
77                 sys.exit(1)
78        return options, args
79
80options, args = parse_args()
81
82filename   = options.filename
[4f4a8a4]83params = taskparams()
84params.hopsize    = int(options.hopsize)
85params.bufsize    = int(options.bufsize)
86params.threshold  = float(options.threshold)
87params.zerothres  = float(options.zerothres)
88params.silence    = float(options.silence)
89params.mintol     = float(options.mintol)
[80c0417]90# default take back system delay
91if options.delay: delay = float(options.delay)
[4f4a8a4]92else:             delay = 3./params.step
[98df9f4]93
[5e491b3b]94
95lonsets, lofunc = [], []
[4f4a8a4]96modes = options.mode.split(',')
97for i in range(len(modes)):
98
99        params.onsetmode = modes[i]
[ada5baf]100        dotask = taskonset
101        if options.beat:
102                dotask = taskbeat
103        elif options.silencecut:
104                dotask = tasksilence
105        elif options.plot:
106                params.storefunc=True
107        else:             
108                params.storefunc=False
109        filetask = dotask(filename,params=params)
[4f4a8a4]110        onsets = filetask.compute_all()
111        ofunc = filetask.ofunc
112        #onsets, ofunc = getonsets(filename,threshold,silence,
113        #        mode=mode[i],localmin=options.localmin,
114        #        derivate=options.derivate,
115        #        bufsize=bufsize,hopsize=hopsize,storefunc=True)
[98df9f4]116
[5e491b3b]117        # take back system delay
118        if delay != 0:
[4f4a8a4]119                for each in range(len(onsets)):
120                        onsets[each] = onsets[each][0] - delay*params.step
[5e491b3b]121
122        # prune doubled
[4f4a8a4]123        params.mintol *= params.step
124        if params.mintol > 0:
125                last = -2*params.mintol
[5e491b3b]126                newonsets = []
127                for new in onsets:
[4f4a8a4]128                        if (new - last > params.mintol):
[5e491b3b]129                                newonsets.append(new)
130                        last = new
131                onsets = newonsets
[98df9f4]132
[5e491b3b]133        lonsets.append(onsets)
134        lofunc.append(ofunc)
[98df9f4]135
[4f4a8a4]136        # print times in second
137        if options.verbose:
[ada5baf]138                #print modes[i]
[4f4a8a4]139                for i in range(len(onsets)):
140                                print onsets[i]*params.step
[98df9f4]141
[4f4a8a4]142        if options.plot:
143                filetask.plot(onsets, ofunc)
144                filetask.plotplot(outplot=options.outplot)
[80c0417]145
[98df9f4]146if options.cut:
[4f4a8a4]147        a = taskcut(filename,onsets,params=params)
148        a.compute_all()
Note: See TracBrowser for help on using the repository browser.