comparison experiment-reverb/code/onsetdetection.py @ 0:246d5546657c

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