source: python/aubio/task/utils.py @ 862d78f

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

utils.c, utils.py: add specflux onset function

  • Property mode set to 100644
File size: 2.4 KB
Line 
1from aubio.aubioclass import *
2
3def get_onset_mode(nvalue):
4        """ utility function to convert a string to aubio_onsetdetection_type """
5        if   nvalue == 'complexdomain' or nvalue == 'complex' :
6                 return aubio_onset_complex
7        elif nvalue == 'hfc'           :
8                 return aubio_onset_hfc
9        elif nvalue == 'phase'         :
10                 return aubio_onset_phase
11        elif nvalue == 'specdiff'      :
12                 return aubio_onset_specdiff
13        elif nvalue == 'energy'        :
14                 return aubio_onset_energy
15        elif nvalue == 'kl'            :
16                 return aubio_onset_kl
17        elif nvalue == 'mkl'           :
18                 return aubio_onset_mkl
19        elif nvalue == 'specflux'      :
20                 return aubio_onset_specflux
21        elif nvalue == 'dual'          :
22                 return 'dual'
23        else:
24                 import sys
25                 print "unknown onset detection function selected: %s" % nvalue
26                 sys.exit(1)
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):
46        """ wrapper function to convert a list of modes to
47                aubio_onsetdetection_type """
48        nvalues = parser.rargs[0].split(',')
49        val =  []
50        for nvalue in nvalues:
51                val.append(get_onset_mode(nvalue))
52                setattr(parser.values, option.dest, val)
53
54def check_pitch_mode(option, opt, value, parser):
55        """ utility function to convert a string to aubio_pitchdetection_type"""
56        nvalues = parser.rargs[0].split(',')
57        val = []
58        for nvalue in nvalues:
59                val.append(get_pitch_mode(nvalue))
60                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
Note: See TracBrowser for help on using the repository browser.