History

src/pitch: use a string to set pitch method, add a new function to set pitch unit, keep pitch enums private, update pitch methods where they are used

Paul Brossier committed 17 years ago

Commit fe163ad1 parent cd77c1514 files · +129 −196Browse files

Showing the changes to python (5 of 14 files). Show all

Unified · Split

5 files
  1. python/aubio/aubioclass.py +5 −4
  2. python/aubio/task/params.py +1 −2
  3. python/aubio/task/pitch.py +1 −1
  4. python/aubio/task/utils.py +0 −35
  5. python/aubiopitch +7 −9
python/aubio/aubioclass.py+5−4
@@ -124,11 +124,12 @@ class onsetpick: · 123 unmodified lines
124 return isonset, dval124 return isonset, dval
125 125
126class pitchdetection:126class pitchdetection:
127 def __init__(self,mode=aubio_pitch_mcomb,bufsize=2048,hopsize=1024,127 def __init__(self,mode="mcomb",bufsize=2048,hopsize=1024,
128 channels=1,samplerate=44100.,omode=aubio_pitchm_freq,tolerance=0.1):128 channels=1,samplerate=44100.,omode="freq",tolerance=0.1):
129 self.pitchp = new_aubio_pitchdetection(bufsize,hopsize,channels,129 self.pitchp = new_aubio_pitchdetection(mode,bufsize,hopsize,channels,
130 samplerate,mode,omode)130 samplerate)
131 self.mypitch = fvec(1, channels)131 self.mypitch = fvec(1, channels)
132 aubio_pitchdetection_set_unit(self.pitchp,omode)
132 aubio_pitchdetection_set_tolerance(self.pitchp,tolerance)133 aubio_pitchdetection_set_tolerance(self.pitchp,tolerance)
133 #self.filt = filter(srate,"adsgn")134 #self.filt = filter(srate,"adsgn")
134 def __del__(self):135 def __del__(self):
python/aubio/task/params.py+1−2
@@ -1,4 +1,3 @@
1from aubio.aubioclass import aubio_pitchm_freq
2 1
3class taskparams(object):2class taskparams(object):
4 """ default parameters for task classes """3 """ default parameters for task classes """
@@ -29,6 +28,6 @@ class taskparams(object): · 24 unmodified lines
29 self.pitchmax=20000.28 self.pitchmax=20000.
30 self.pitchdelay = -0.529 self.pitchdelay = -0.5
31 self.dcthreshold = -1.30 self.dcthreshold = -1.
32 self.omode = aubio_pitchm_freq31 self.omode = "freq"
33 self.verbose = False32 self.verbose = False
34 33
python/aubio/task/pitch.py+1−1
@@ -13,7 +13,7 @@ class taskpitch(task): · 12 unmodified lines
13 tolerance = self.params.yinfftthresh13 tolerance = self.params.yinfftthresh
14 else:14 else:
15 tolerance = 0.15 tolerance = 0.
16 self.pitchdet = pitchdetection(mode=get_pitch_mode(self.params.pitchmode),16 self.pitchdet = pitchdetection(mode=self.params.pitchmode,
17 bufsize=self.params.bufsize,17 bufsize=self.params.bufsize,
18 hopsize=self.params.hopsize,18 hopsize=self.params.hopsize,
19 channels=self.channels,19 channels=self.channels,
python/aubio/task/utils.py+0−35
@@ -25,23 +25,6 @@ def get_onset_mode(nvalue): · 24 unmodified lines
25 print "unknown onset detection function selected: %s" % nvalue25 print "unknown onset detection function selected: %s" % nvalue
26 sys.exit(1)26 sys.exit(1)
27 27
28def get_pitch_mode(nvalue):
29 """ utility function to convert a string to aubio_pitchdetection_type """
30 if nvalue == 'mcomb' :
31 return aubio_pitch_mcomb
32 elif nvalue == 'yin' :
33 return aubio_pitch_yin
34 elif nvalue == 'fcomb' :
35 return aubio_pitch_fcomb
36 elif nvalue == 'schmitt':
37 return aubio_pitch_schmitt
38 elif nvalue == 'yinfft':
39 return aubio_pitch_yinfft
40 else:
41 import sys
42 print "error: unknown pitch detection function selected"
43 sys.exit(1)
44
45def check_onset_mode(option, opt, value, parser):28def check_onset_mode(option, opt, value, parser):
46 """ wrapper function to convert a list of modes to 29 """ wrapper function to convert a list of modes to
47 aubio_onsetdetection_type """30 aubio_onsetdetection_type """
@@ -58,21 +41,3 @@ def check_pitch_mode(option, opt, value, parser): · 10 unmodified lines
58 for nvalue in nvalues:41 for nvalue in nvalues:
59 val.append(get_pitch_mode(nvalue))42 val.append(get_pitch_mode(nvalue))
60 setattr(parser.values, option.dest, val)43 setattr(parser.values, option.dest, val)
61
62def check_pitchm_mode(option, opt, value, parser):
63 """ utility function to convert a string to aubio_pitchdetection_mode """
64 nvalue = parser.rargs[0]
65 if nvalue == 'freq' :
66 setattr(parser.values, option.dest, aubio_pitchm_freq)
67 elif nvalue == 'midi' :
68 setattr(parser.values, option.dest, aubio_pitchm_midi)
69 elif nvalue == 'cent' :
70 setattr(parser.values, option.dest, aubio_pitchm_cent)
71 elif nvalue == 'bin' :
72 setattr(parser.values, option.dest, aubio_pitchm_bin)
73 else:
74 import sys
75 print "error: unknown pitch detection output selected"
76 sys.exit(1)
77
78
python/aubiopitch+7−9
@@ -17,12 +17,11 @@ def parse_args(): · 16 unmodified lines
17 action="store", dest="filename", 17 action="store", dest="filename",
18 help="input sound file")18 help="input sound file")
19 parser.add_option("-m","--mode", 19 parser.add_option("-m","--mode",
20 action="store", dest="mode", default='mcomb',20 action="store", dest="mode", default='yinfft',
21 help="pitch detection mode [default=mcomb] \21 help="pitch detection mode [default=mcomb] \
22 mcomb|yin|fcomb|schmitt")22 mcomb|yin|fcomb|schmitt")
23 parser.add_option("-u","--units", action="callback", 23 parser.add_option("-u","--units",
24 callback=check_pitchm_mode, dest="omode",24 action="store", dest="omode", default="freq",
25 default=aubio_pitchm_freq,
26 help="output pitch in units [default=Hz] \25 help="output pitch in units [default=Hz] \
27 freq|midi|cent|bin")26 freq|midi|cent|bin")
28 parser.add_option("-B","--bufsize",27 parser.add_option("-B","--bufsize",
@@ -77,10 +76,10 @@ def parse_args(): · 48 unmodified lines
77 help="be quiet")76 help="be quiet")
78 (options, args) = parser.parse_args()77 (options, args) = parser.parse_args()
79 if not options.bufsize:78 if not options.bufsize:
80 if options.mode == aubio_pitch_yin: options.bufsize = 102479 if options.mode == "yin": options.bufsize = 1024
81 if options.mode == aubio_pitch_schmitt: options.bufsize = 204880 if options.mode == "schmitt": options.bufsize = 2048
82 if options.mode == aubio_pitch_mcomb: options.bufsize = 409681 if options.mode == "mcomb": options.bufsize = 4096
83 if options.mode == aubio_pitch_fcomb: options.bufsize = 4096 82 if options.mode == "fcomb": options.bufsize = 4096
84 else: options.bufsize = 204883 else: options.bufsize = 2048
85 if not options.hopsize:84 if not options.hopsize:
86 options.hopsize = float(options.bufsize) / 285 options.hopsize = float(options.bufsize) / 2
@@ -105,7 +104,6 @@ params.verbose = options.verbose · 18 unmodified lines
105if options.smoothing: params.pitchsmooth = int(options.smoothing)104if options.smoothing: params.pitchsmooth = int(options.smoothing)
106if options.pitchmax: params.pitchmax = int(options.pitchmax)105if options.pitchmax: params.pitchmax = int(options.pitchmax)
107if options.pitchmin: params.pitchmin = int(options.pitchmin)106if options.pitchmin: params.pitchmin = int(options.pitchmin)
108if options.omode: params.omode = int(options.omode)
109#mintol = float(options.mintol)*step107#mintol = float(options.mintol)*step
110# default take back system delay108# default take back system delay
111if options.delay: params.pitchdelay = float(options.delay)109if options.delay: params.pitchdelay = float(options.delay)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t