forked from CPJKU/madmom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeatDetector
executable file
·108 lines (82 loc) · 3.59 KB
/
BeatDetector
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
#!/usr/bin/env python
# encoding: utf-8
"""
BeatDetector beat tracking algorithm.
"""
from __future__ import absolute_import, division, print_function
import argparse
from madmom.audio import SignalProcessor
from madmom.features import (ActivationsProcessor, BeatDetectionProcessor,
RNNBeatProcessor, TempoEstimationProcessor)
from madmom.io import write_beats
from madmom.processors import IOProcessor, io_arguments
def main():
"""BeatDetector"""
# define parser
p = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter, description='''
The BeatDetector program detects all beats in an audio file according to
the method described in (assuming a constant tempo throughout the whole
piece):
"Enhanced Beat Tracking with Context-Aware Neural Networks"
Sebastian Böck and Markus Schedl.
Proceedings of the 14th International Conference on Digital Audio Effects
(DAFx), 2011.
Instead of using the originally proposed auto-correlation method to build
a tempo histogram, comb filters are used to estimate the tempo:
"Accurate Tempo Estimation based on Recurrent Neural Networks and
Resonating Comb Filters"
Sebastian Böck, Florian Krebs and Gerhard Widmer.
Proceedings of the 16th International Society for Music Information
Retrieval Conference (ISMIR), 2015.
This program can be run in 'single' file mode to process a single audio
file and write the detected beats to STDOUT or the given output file.
$ BeatDetector single INFILE [-o OUTFILE]
If multiple audio files should be processed, the program can also be run
in 'batch' mode to save the detected beats to files with the given suffix.
$ BeatDetector batch [-o OUTPUT_DIR] [-s OUTPUT_SUFFIX] FILES
If no output directory is given, the program writes the files with the
detected beats 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='BeatDetector.2016')
# input/output arguments
io_arguments(p, output_suffix='.beats.txt')
ActivationsProcessor.add_arguments(p)
# signal processing arguments
SignalProcessor.add_arguments(p, norm=False, gain=0)
# beat tracking arguments
TempoEstimationProcessor.add_arguments(p, method='comb', min_bpm=40,
max_bpm=240, act_smooth=0.09,
hist_smooth=7, alpha=0.79)
BeatDetectionProcessor.add_arguments(p, look_ahead=None)
# parse arguments
args = p.parse_args()
# set immutable arguments
args.fps = 100
# 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:
# use a RNN to predict the beats
in_processor = RNNBeatProcessor(**vars(args))
# output processor
if args.save:
# save the RNN beat activations to file
out_processor = ActivationsProcessor(mode='w', **vars(args))
else:
# detect the beats in the activation function and output them
beat_processor = BeatDetectionProcessor(**vars(args))
out_processor = [beat_processor, write_beats]
# create an IOProcessor
processor = IOProcessor(in_processor, out_processor)
# and call the processing function
args.func(processor, **vars(args))
if __name__ == "__main__":
main()