Changeset c95062b for python/lib/aubio
- Timestamp:
- Sep 16, 2017, 3:45:18 PM (7 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
- Children:
- eb8f7d5
- Parents:
- b02d52f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cmd.py
rb02d52f rc95062b 21 21 22 22 subparsers = parser.add_subparsers(title='commands', dest='command', 23 parser_class= AubioArgumentParser, 23 24 metavar="") 24 25 … … 47 48 help='estimate time of onsets (beginning of sound event)', 48 49 formatter_class = argparse.ArgumentDefaultsHelpFormatter) 49 parser_add_input(subparser)50 parser_add_buf_hop_size(subparser)50 subparser.add_input() 51 subparser.add_buf_hop_size() 51 52 helpstr = "onset novelty function" 52 53 helpstr += " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>" 53 parser_add_method(subparser,helpstr=helpstr)54 parser_add_threshold(subparser)55 parser_add_silence(subparser)56 parser_add_minioi(subparser)57 parser_add_time_format(subparser)58 parser_add_verbose_help(subparser)54 subparser.add_method(helpstr=helpstr) 55 subparser.add_threshold() 56 subparser.add_silence() 57 subparser.add_minioi() 58 subparser.add_time_format() 59 subparser.add_verbose_help() 59 60 subparser.set_defaults(process=process_onset) 60 61 … … 63 64 subparser = subparsers.add_parser('pitch', 64 65 help='estimate fundamental frequency (monophonic)') 65 parser_add_input(subparser)66 parser_add_buf_hop_size(subparser,buf_size=2048)66 subparser.add_input() 67 subparser.add_buf_hop_size(buf_size=2048) 67 68 helpstr = "pitch detection method <default|yinfft|yin|mcomb|fcomb|schmitt>" 68 parser_add_method(subparser,helpstr=helpstr)69 parser_add_threshold(subparser)70 parser_add_pitch_unit(subparser)71 parser_add_silence(subparser)72 parser_add_time_format(subparser)73 parser_add_verbose_help(subparser)69 subparser.add_method(helpstr=helpstr) 70 subparser.add_threshold() 71 subparser.add_pitch_unit() 72 subparser.add_silence() 73 subparser.add_time_format() 74 subparser.add_verbose_help() 74 75 subparser.set_defaults(process=process_pitch) 75 76 … … 78 79 subparser = subparsers.add_parser('beat', 79 80 help='estimate location of beats') 80 parser_add_input(subparser)81 parser_add_buf_hop_size(subparser,buf_size=1024, hop_size=512)82 parser_add_time_format(subparser)83 parser_add_verbose_help(subparser)81 subparser.add_input() 82 subparser.add_buf_hop_size(buf_size=1024, hop_size=512) 83 subparser.add_time_format() 84 subparser.add_verbose_help() 84 85 subparser.set_defaults(process=process_beat) 85 86 … … 88 89 subparser = subparsers.add_parser('tempo', 89 90 help='estimate overall tempo in bpm') 90 parser_add_input(subparser)91 parser_add_buf_hop_size(subparser,buf_size=1024, hop_size=512)92 parser_add_time_format(subparser)93 parser_add_verbose_help(subparser)91 subparser.add_input() 92 subparser.add_buf_hop_size(buf_size=1024, hop_size=512) 93 subparser.add_time_format() 94 subparser.add_verbose_help() 94 95 subparser.set_defaults(process=process_tempo) 95 96 … … 98 99 subparser = subparsers.add_parser('notes', 99 100 help='estimate midi-like notes (monophonic)') 100 parser_add_input(subparser)101 parser_add_buf_hop_size(subparser)102 parser_add_time_format(subparser)103 parser_add_verbose_help(subparser)101 subparser.add_input() 102 subparser.add_buf_hop_size() 103 subparser.add_time_format() 104 subparser.add_verbose_help() 104 105 subparser.set_defaults(process=process_notes) 105 106 … … 108 109 subparser = subparsers.add_parser('mfcc', 109 110 help='extract Mel-Frequency Cepstrum Coefficients') 110 parser_add_input(subparser)111 parser_add_buf_hop_size(subparser)112 parser_add_time_format(subparser)113 parser_add_verbose_help(subparser)111 subparser.add_input() 112 subparser.add_buf_hop_size() 113 subparser.add_time_format() 114 subparser.add_verbose_help() 114 115 subparser.set_defaults(process=process_mfcc) 115 116 … … 118 119 subparser = subparsers.add_parser('melbands', 119 120 help='extract energies in Mel-frequency bands') 120 parser_add_input(subparser)121 parser_add_buf_hop_size(subparser)122 parser_add_time_format(subparser)123 parser_add_verbose_help(subparser)121 subparser.add_input() 122 subparser.add_buf_hop_size() 123 subparser.add_time_format() 124 subparser.add_verbose_help() 124 125 subparser.set_defaults(process=process_melbands) 125 126 … … 128 129 subparser = subparsers.add_parser('quiet', 129 130 help='extract timestamps of quiet and loud regions') 130 parser_add_input(subparser)131 parser_add_hop_size(subparser)132 parser_add_silence(subparser)133 parser_add_time_format(subparser)134 parser_add_verbose_help(subparser)131 subparser.add_input() 132 subparser.add_hop_size() 133 subparser.add_silence() 134 subparser.add_time_format() 135 subparser.add_verbose_help() 135 136 subparser.set_defaults(process=process_quiet) 136 137 137 def parser_add_input(parser): 138 parser.add_argument("source_uri", default=None, nargs='?', 139 help="input sound file to analyse", metavar = "<source_uri>") 140 parser.add_argument("-i", "--input", dest = "source_uri2", 141 help="input sound file to analyse", metavar = "<source_uri>") 142 parser.add_argument("-r", "--samplerate", 143 metavar = "<freq>", type=int, 144 action="store", dest="samplerate", default=0, 145 help="samplerate at which the file should be represented") 146 147 def parser_add_verbose_help(parser): 148 parser.add_argument("-v","--verbose", 149 action="count", dest="verbose", default=1, 150 help="make lots of noise [default]") 151 parser.add_argument("-q","--quiet", 152 action="store_const", dest="verbose", const=0, 153 help="be quiet") 154 155 def parser_add_buf_hop_size(parser, buf_size=512, hop_size=256): 156 parser_add_buf_size(parser, buf_size=buf_size) 157 parser_add_hop_size(parser, hop_size=hop_size) 158 159 def parser_add_buf_size(parser, buf_size=512): 160 parser.add_argument("-B","--bufsize", 161 action="store", dest="buf_size", default=buf_size, 162 metavar = "<size>", type=int, 163 help="buffer size [default=%d]" % buf_size) 164 165 def parser_add_hop_size(parser, hop_size=256): 166 parser.add_argument("-H","--hopsize", 167 metavar = "<size>", type=int, 168 action="store", dest="hop_size", default=hop_size, 169 help="overlap size [default=%d]" % hop_size) 170 171 def parser_add_method(parser, method='default', helpstr='method'): 172 parser.add_argument("-m","--method", 173 metavar = "<method>", type=str, 174 action="store", dest="method", default=method, 175 help="%s [default=%s]" % (helpstr, method)) 176 177 def parser_add_threshold(parser, default=None): 178 parser.add_argument("-t","--threshold", 179 metavar = "<threshold>", type=float, 180 action="store", dest="threshold", default=default, 181 help="threshold [default=%s]" % default) 182 183 def parser_add_silence(parser): 184 parser.add_argument("-s", "--silence", 185 metavar = "<value>", type=float, 186 action="store", dest="silence", default=-70, 187 help="silence threshold") 188 189 def parser_add_minioi(parser): 190 parser.add_argument("-M", "--minioi", 191 metavar = "<value>", type=str, 192 action="store", dest="minioi", default="12ms", 193 help="minimum Inter-Onset Interval") 194 195 def parser_add_pitch_unit(parser, default="Hz"): 196 help_str = "frequency unit, should be one of Hz, midi, bin, cent" 197 help_str += " [default=%s]" % default 198 parser.add_argument("-u", "--pitch-unit", 199 metavar = "<value>", type=str, 200 action="store", dest="pitch_unit", default=default, 201 help=help_str) 202 203 def parser_add_time_format(parser): 204 helpstr = "select time values output format (samples, ms, seconds)" 205 helpstr += " [default=seconds]" 206 parser.add_argument("-T", "--time-format", 207 metavar='format', 208 dest="time_format", 209 default=None, 210 help=helpstr) 138 class AubioArgumentParser(argparse.ArgumentParser): 139 140 def add_input(self): 141 self.add_argument("source_uri", default=None, nargs='?', 142 help="input sound file to analyse", metavar = "<source_uri>") 143 self.add_argument("-i", "--input", dest = "source_uri2", 144 help="input sound file to analyse", metavar = "<source_uri>") 145 self.add_argument("-r", "--samplerate", 146 metavar = "<freq>", type=int, 147 action="store", dest="samplerate", default=0, 148 help="samplerate at which the file should be represented") 149 150 def add_verbose_help(self): 151 self.add_argument("-v","--verbose", 152 action="count", dest="verbose", default=1, 153 help="make lots of noise [default]") 154 self.add_argument("-q","--quiet", 155 action="store_const", dest="verbose", const=0, 156 help="be quiet") 157 158 def add_buf_hop_size(self, buf_size=512, hop_size=256): 159 self.add_buf_size(buf_size=buf_size) 160 self.add_hop_size(hop_size=hop_size) 161 162 def add_buf_size(self, buf_size=512): 163 self.add_argument("-B","--bufsize", 164 action="store", dest="buf_size", default=buf_size, 165 metavar = "<size>", type=int, 166 help="buffer size [default=%d]" % buf_size) 167 168 def add_hop_size(self, hop_size=256): 169 self.add_argument("-H","--hopsize", 170 metavar = "<size>", type=int, 171 action="store", dest="hop_size", default=hop_size, 172 help="overlap size [default=%d]" % hop_size) 173 174 def add_method(self, method='default', helpstr='method'): 175 self.add_argument("-m","--method", 176 metavar = "<method>", type=str, 177 action="store", dest="method", default=method, 178 help="%s [default=%s]" % (helpstr, method)) 179 180 def add_threshold(self, default=None): 181 self.add_argument("-t","--threshold", 182 metavar = "<threshold>", type=float, 183 action="store", dest="threshold", default=default, 184 help="threshold [default=%s]" % default) 185 186 def add_silence(self): 187 self.add_argument("-s", "--silence", 188 metavar = "<value>", type=float, 189 action="store", dest="silence", default=-70, 190 help="silence threshold") 191 192 def add_minioi(self, default="12ms"): 193 self.add_argument("-M", "--minioi", 194 metavar = "<value>", type=str, 195 action="store", dest="minioi", default=default, 196 help="minimum Inter-Onset Interval [default=%s]" % default) 197 198 def add_pitch_unit(self, default="Hz"): 199 help_str = "frequency unit, should be one of Hz, midi, bin, cent" 200 help_str += " [default=%s]" % default 201 self.add_argument("-u", "--pitch-unit", 202 metavar = "<value>", type=str, 203 action="store", dest="pitch_unit", default=default, 204 help=help_str) 205 206 def add_time_format(self): 207 helpstr = "select time values output format (samples, ms, seconds)" 208 helpstr += " [default=seconds]" 209 self.add_argument("-T", "--time-format", 210 metavar='format', 211 dest="time_format", 212 default=None, 213 help=helpstr) 211 214 212 215 # some utilities
Note: See TracChangeset
for help on using the changeset viewer.