e@0
|
1 # -*- coding: utf-8 -*-
|
e@0
|
2 """
|
e@0
|
3 Spectral Constrast as described in Dan-Ning Jiang et al (2002)
|
e@0
|
4
|
e@0
|
5 Created on Tue Apr 14 17:31:20 2015
|
e@0
|
6
|
e@0
|
7 @author: Emmanouil Theofanis Chourdakis
|
e@0
|
8
|
e@0
|
9
|
e@0
|
10 """
|
e@0
|
11
|
e@0
|
12 import essentia
|
e@0
|
13 from essentia.streaming import *
|
e@0
|
14 from essentia.standard import YamlOutput
|
e@0
|
15 from sys import argv
|
e@0
|
16 from pylab import *
|
e@0
|
17 from numpy import *
|
e@0
|
18
|
e@0
|
19
|
e@0
|
20
|
e@0
|
21
|
e@0
|
22 if __name__=="__main__":
|
e@0
|
23 if len(argv) < 2:
|
e@0
|
24 print("Please provide an input filename.")
|
e@0
|
25 else:
|
e@0
|
26 fname = argv[1]
|
e@0
|
27 print("Onset Demo with `%s\'" % fname)
|
e@0
|
28
|
e@0
|
29 SR = 16000.0 # Sampling Rate
|
e@0
|
30 T = 1./SR # Sampling Period
|
e@0
|
31 FS = 23.0 # ms
|
e@0
|
32
|
e@0
|
33 # Describing the building blocks
|
e@0
|
34
|
e@0
|
35 loader = MonoLoader(filename = fname, sampleRate = SR)
|
e@0
|
36
|
e@0
|
37 onset = OnsetRate()
|
e@0
|
38
|
e@0
|
39 # Pool (for output purposes)
|
e@0
|
40
|
e@0
|
41 pool = essentia.Pool()
|
e@0
|
42
|
e@0
|
43
|
e@0
|
44 # Describing the connections
|
e@0
|
45
|
e@0
|
46
|
e@0
|
47 loader.audio >> onset.signal
|
e@0
|
48 loader.audio >> (pool, 'audio')
|
e@0
|
49 onset.onsetRate >> None
|
e@0
|
50 onset.onsetTimes >> (pool, 'onsettimes')
|
e@0
|
51
|
e@0
|
52
|
e@0
|
53 # Run it
|
e@0
|
54
|
e@0
|
55 essentia.run(loader)
|
e@0
|
56
|
e@0
|
57
|
e@0
|
58 # Save the pool as a yaml file.
|
e@0
|
59 output = YamlOutput(filename = "%s.yaml" % fname.partition('/')[2].partition('.')[0])(pool)
|
e@0
|
60
|
e@0
|
61
|
e@0
|
62 ons = zeros((len(pool['audio']),1))
|
e@0
|
63
|
e@0
|
64 for i in range(0,len(pool['onsettimes'])):
|
e@0
|
65 ons[pool['onsettimes'][i]*44100]= 1
|
e@0
|
66
|
e@0
|
67
|
e@0
|
68 t = linspace(0, len(pool['audio'])*T, len(pool['audio']))
|
e@0
|
69
|
e@0
|
70 plot(t, pool['audio'], t, ons);
|
e@0
|
71 xlabel('time (s)')
|
e@0
|
72 ylabel('f(t)')
|
e@0
|
73 title('Onset Detection Function')
|
e@0
|
74 savefig('output.png', dpi=600)
|
e@0
|
75
|
e@0
|
76
|
e@0
|
77 show()
|
e@0
|
78
|
e@0
|
79
|
e@0
|
80
|
e@0
|
81
|
e@0
|
82
|