-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamingTempo3.py
49 lines (36 loc) · 1004 Bytes
/
streamingTempo3.py
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
import sys
import essentia
from essentia.streaming import *
import numpy as np
import math as m
import matplotlib.pyplot as plt
from matplotlib.colors import *
import matplotlib
infile = sys.argv[1]
ws = 4096
loader = MonoLoader(filename = infile)
framecutter = FrameCutter(frameSize = ws, hopSize = (ws/2))
windowing = Windowing(type = "hann")
fft = FFT(size = ws)
cartopol = CartesianToPolar()
od = OnsetDetection()
tempotap = TempoTapDegara()
diff = Derivative()
# use pool to store data
pool = essentia.Pool()
# connect algorithms together
loader.audio >> framecutter.signal
framecutter.frame >> windowing.frame >> fft.frame
fft.fft >> cartopol.complex
cartopol.magnitude >> od.spectrum
cartopol.phase >> od.phase
od.onsetDetection >> tempotap.onsetDetections
tempotap.ticks >> diff.signal
diff.signal >> (pool, 'data')
# network is ready, run it
essentia.run(loader)
data = pool['data']
median = np.median(data)
tempo = 60.0/median
print '\n', len(data), "elements"
print tempo, 'bpm'