forked from CPJKU/madmom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpectralOnsetDetection
executable file
·120 lines (97 loc) · 4.64 KB
/
SpectralOnsetDetection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python
# encoding: utf-8
"""
Spectral onset detection script.
"""
from __future__ import absolute_import, division, print_function
import argparse
from madmom.processors import IOProcessor, io_arguments
from madmom.audio.signal import SignalProcessor, FramedSignalProcessor
from madmom.audio.filters import FilterbankProcessor, LogarithmicFilterbank
from madmom.audio.spectrogram import (LogarithmicSpectrogramProcessor,
SpectrogramDifferenceProcessor)
from madmom.features import ActivationsProcessor
from madmom.features.onsets import (SpectralOnsetProcessor,
OnsetPeakPickingProcessor)
def main():
"""SpectralOnsetDetection"""
# define parser
p = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter, description='''
The SpectralOnsetDetection program detects all onsets in an audio file
with selectable algorithms. The parameters have to be set accordingly.
The different algorithms are described in:
"Evaluating the Online Capabilities of Onset Detection Methods"
Sebastian Böck, Florian Krebs and Markus Schedl.
Proceedings of the 13th International Society for Music Information
Retrieval Conference (ISMIR), 2012.
This program can be run in 'single' file mode to process a single audio
file and write the detected onsets to STDOUT or the given output file.
$ SpectralOnsetDetection single INFILE [-o OUTFILE]
If multiple audio files should be processed, the program can also be run
in 'batch' mode to save the detected onsets to files with the given suffix.
$ SpectralOnsetDetection batch [-o OUTPUT_DIR] [-s OUTPUT_SUFFIX] FILES
If no output directory is given, the program writes the files with the
detected onsets to the same location as the audio files.
The 'pickle' mode can be used to store the used parameters to be able to
exactly reproduce experiments.
''')
# version
p.add_argument('--version', action='version',
version='SpectralOnsetDetection')
# add arguments
io_arguments(p, output_suffix='.onsets.txt')
ActivationsProcessor.add_arguments(p)
SignalProcessor.add_arguments(p, norm=False, gain=0)
FramedSignalProcessor.add_arguments(p, fps=100, online=False)
FilterbankProcessor.add_arguments(p, filterbank=LogarithmicFilterbank,
num_bands=12, fmin=30, fmax=17000,
norm_filters=False)
LogarithmicSpectrogramProcessor.add_arguments(p, log=True, mul=1, add=1)
SpectrogramDifferenceProcessor.add_arguments(p, diff_ratio=0.5,
positive_diffs=True)
SpectralOnsetProcessor.add_arguments(p, onset_method='spectral_flux')
OnsetPeakPickingProcessor.add_arguments(p, threshold=1.6, pre_max=0.01,
post_max=0.05, pre_avg=0.15,
post_avg=0, combine=0.03, delay=0)
# parse arguments
args = p.parse_args()
# set online mode parameters
if args.origin == 'online':
args.post_avg = 0
args.post_max = 0
# add circular shift for correct phase and remove filterbank if needed
if args.onset_method in ('phase_deviation', 'weighted_phase_deviation',
'normalized_weighted_phase_deviation',
'complex_domain', 'rectified_complex_domain'):
args.circular_shift = True
args.filterbank = None
if args.onset_method in ('superflux', 'complex_flux'):
raise SystemExit('Please use the dedicated onset detection script for '
'%s.' % args.onset_method)
# print arguments
if args.verbose:
print(args)
# input processor
if args.load:
# load the activations from file
in_processor = ActivationsProcessor(mode='r', **vars(args))
else:
# define a spectral onset processor
in_processor = SpectralOnsetProcessor(**vars(args))
# output processor
if args.save:
# save the onset activations to file
out_processor = ActivationsProcessor(mode='w', **vars(args))
else:
# perform peak picking of the onset function
peak_picking = OnsetPeakPickingProcessor(**vars(args))
from madmom.utils import write_events as writer
# sequentially process them
out_processor = [peak_picking, writer]
# create an IOProcessor
processor = IOProcessor(in_processor, out_processor)
# and call the processing function
args.func(processor, **vars(args))
if __name__ == '__main__':
main()