source: python/aubiocut @ a3e24ec

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

updated aubiocut, added zerocross

  • Property mode set to 100755
File size: 5.9 KB
Line 
1#! /usr/bin/python
2
3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
7import sys
8from aubio.aubioclass import *
9
10usage = "usage: %s [options] -i soundfile" % sys.argv[0]
11
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")
18        parser.add_option("-m","--mode", action="callback",
19                          callback=check_onset_mode, dest="mode", default='dual',
20                          help="onset detection mode [default=dual] \
21                          complexdomain|hfc|phase|specdiff|energy|kl|mkl|dual")
22        parser.add_option("-B","--bufsize",
23                          action="store", dest="bufsize", default=1024,
24                          help="buffer size [default=1024]")
25        parser.add_option("-H","--hopsize",
26                          action="store", dest="hopsize", default=256,
27                          help="overlap size [default=256]")
28        parser.add_option("-t","--threshold",
29                          action="store", dest="threshold", default=0.650,
30                          help="onset peak picking threshold [default=0.650]")
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",
38                          action="store", dest="delay", 
39                          help="number of seconds to take back [default=system]\
40                          default system delay is 2*hopsize/samplerate")
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")
48        parser.add_option("-d","--derivate",
49                          action="store_true", dest="derivate", default=False,
50                          help="derivate onset detection function")
51        parser.add_option("-S","--silencecut",
52                          action="store_true", dest="silencecut", default=False,
53                          help="outputs silence locations")
54        parser.add_option("-z","--zerocross",
55                          action="store", dest="zerothres", default=0.008,
56                          help="zero-crossing threshold for slicing [default=0.008]")
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}")
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")
70        # to be implemented
71        parser.add_option("-b","--beat",
72                          action="store_true", dest="beat", default=False,
73                          help="NOT IMPLEMENTED output beat locations")
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
83samplerate = float(sndfile(filename).samplerate())
84hopsize    = int(options.hopsize)
85bufsize    = int(options.bufsize)
86step       = float(samplerate)/float(hopsize)
87threshold  = float(options.threshold)
88silence    = float(options.silence)
89mintol     = float(options.mintol)*step
90# default take back system delay
91if options.delay: delay = float(options.delay)
92else:             delay = 2./step
93
94if options.beat:
95        #onsets = getbeats(filename,threshold,silence,mode=options.mode)
96        exit("not implemented yet")
97elif options.silencecut:
98        onsets = getsilences(filename,hopsize=hopsize,silence=silence)
99elif options.plot:
100        onsets, ofunc = getonsets(filename,threshold,silence,
101                mode=options.mode,localmin=options.localmin,
102                derivate=options.derivate,
103                bufsize=bufsize,hopsize=hopsize,storefunc=True)
104else:
105        onsets = getonsets(filename,threshold,silence,
106                mode=options.mode,localmin=options.localmin,
107                derivate=options.derivate,
108                bufsize=bufsize,hopsize=hopsize)
109
110# take back system delay
111if delay != 0:
112        for i in range(len(onsets)):
113                onsets[i] -= delay*step
114
115# prune doubled
116if mintol > 0:
117        last = -2*mintol
118        newonsets = []
119        for new in onsets:
120                if (new - last > mintol):
121                        newonsets.append(new)
122                last = new
123        onsets = newonsets
124
125# print times in second
126if options.verbose:
127        for i in onsets: print "%f" % (i/step)
128
129if options.plot:
130        from aubio.gnuplot import plot_onsets
131        plot_onsets(filename, onsets, ofunc,
132                samplerate=samplerate, hopsize=hopsize, outplot=options.outplot)
133
134if options.cut:
135        cutfile(filename,onsets,zerothres=zerothres,bufsize=bufsize,hopsize=hopsize)
Note: See TracBrowser for help on using the repository browser.