source: python/aubiopitch @ 660c1d82

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 660c1d82 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.2 KB
RevLine 
[96fb8ad]1#!/usr/bin/python
2
[d4a0cc4]3""" this file was written by Paul Brossier
4  it is released under the GNU/GPL license.
5"""
6
7import sys
[5e491b3b]8from aubio.tasks import *
[d4a0cc4]9
10usage = "usage: %s [options] -i soundfile" % sys.argv[0]
11
12
13def parse_args():
14        from optparse import OptionParser
15        parser = OptionParser(usage=usage)
16        parser.add_option("-i","--input",
17                          action="store", dest="filename", 
18                          help="input sound file")
[d9101a5]19        parser.add_option("-m","--mode", 
20                          action="store", dest="mode", default='mcomb',
[97b8c3d]21                          help="pitch detection mode [default=mcomb] \
[d4a0cc4]22                          mcomb|yin|fcomb|schmitt")
[aa17581]23        parser.add_option("-u","--units", action="callback", 
24                          callback=check_pitchm_mode, dest="omode",
25                          default=aubio_pitchm_freq,
26                          help="output pitch in units [default=Hz] \
27                          freq|midi|cent|bin")
[d4a0cc4]28        parser.add_option("-B","--bufsize",
[aa17581]29                          action="store", dest="bufsize", default=None, 
[d4a0cc4]30                          help="buffer size [default=1024]")
31        parser.add_option("-H","--hopsize",
[aa17581]32                          action="store", dest="hopsize", default=None, 
[d4a0cc4]33                          help="overlap size [default=512]")
34        parser.add_option("-t","--threshold",
35                          action="store", dest="threshold", default=0.1, 
36                          help="pitch threshold (for yin) [default=0.1]")
37        parser.add_option("-s","--silence",
38                          action="store", dest="silence", default=-70, 
39                          help="silence threshold [default=-70]")
40        parser.add_option("-D","--delay",
41                          action="store", dest="delay", 
42                          help="number of seconds to take back [default=system]\
43                          default system delay is 2*hopsize/samplerate")
44        parser.add_option("-L","--localmin",
45                          action="store_true", dest="localmin", default=False, 
46                          help="use local minima after peak detection")
47        parser.add_option("-c","--cut",
48                          action="store_true", dest="cut", default=False,
49                          help="cut input sound file at detected labels \
50                          best used with option -L")
51        # to be implemented
52        parser.add_option("-n","--note",
53                          action="store_true", dest="note", default=False,
54                          help="NOT IMPLEMENTED output notes")
55        # plotting functions
56        parser.add_option("-p","--plot",
57                          action="store_true", dest="plot", default=False, 
58                          help="NOT IMPLEMENTED draw plot")
59        parser.add_option("-O","--outplot",
60                          action="store", dest="outplot", default=None, 
61                          help="NOT IMPLEMENTED save plot to output.{ps,png}")
62        parser.add_option("-v","--verbose",
63                          action="store_true", dest="verbose", default=False,
64                          help="make lots of noise [default]")
65        parser.add_option("-q","--quiet",
66                          action="store_false", dest="verbose", default=False, 
67                          help="be quiet")
68        (options, args) = parser.parse_args()
[aa17581]69        if not options.bufsize:
70                if options.mode == aubio_pitch_yin:     options.bufsize = 1024
71                if options.mode == aubio_pitch_schmitt: options.bufsize = 2048
72                if options.mode == aubio_pitch_mcomb:   options.bufsize = 4096
73                if options.mode == aubio_pitch_fcomb:   options.bufsize = 4096 
[5e491b3b]74                else: options.bufsize = 2048
[aa17581]75        if not options.hopsize:
76                options.hopsize = float(options.bufsize) / 2
[d4a0cc4]77        if not options.filename: 
[aa17581]78                print "no file name given\n", usage
79                sys.exit(1)
[d4a0cc4]80        return options, args
81
82options, args = parse_args()
83
[aa17581]84#print options.bufsize, options.hopsize
85
[d4a0cc4]86filename   = options.filename
[d9101a5]87params = taskparams()
88#params.samplerate = float(sndfile(filename).samplerate())
89params.hopsize    = int(options.hopsize)
90params.bufsize    = int(options.bufsize)
91#params.step       = float(samplerate)/float(hopsize)
92params.threshold  = float(options.threshold)
93params.silence    = float(options.silence)
[d4a0cc4]94#mintol     = float(options.mintol)*step
95# default take back system delay
96if options.delay: delay = float(options.delay)
[d9101a5]97else:             delay = 2./params.step
[d4a0cc4]98
99if options.note:
100        exit("not implemented yet")
101
102
[d9101a5]103pitch = []
104modes = options.mode.split(',')
105for i in range(len(modes)):
106        params.pitchmode  = modes[i]
107        dotask = taskpitch
108        #pitch.append(getpitch(filename, #threshold,
109        #       mode=mode[i],
110        #       omode=options.omode,
111        #       bufsize=bufsize,hopsize=hopsize,
112        #       silence=silence))
113        filetask = dotask(filename,params=params)
114        pitch.append(filetask.compute_all())
115        for j in range(len(pitch[i])):
116                if pitch[i][j] > 10000 or pitch[i][j] < 40:
117                        pitch[i][j] = 0.;
[d4a0cc4]118
[d9101a5]119        if options.verbose:
120                for j in range(len(pitch[i])): 
121                        print "%f\t" % (j/params.step),
122                        print "%f\t" % pitch[i][j],
123                        print
124
125        if options.plot:
126                filetask.plot(pitch,outplot=options.outplot)
Note: See TracBrowser for help on using the repository browser.