Mercurial > hg > chourdakisreiss2016
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/experiment-reverb/code/onsetdetection.py Wed Dec 14 13:15:48 2016 +0000 @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +""" +Spectral Constrast as described in Dan-Ning Jiang et al (2002) + +Created on Tue Apr 14 17:31:20 2015 + +@author: Emmanouil Theofanis Chourdakis + + +""" + +import essentia +from essentia.streaming import * +from essentia.standard import YamlOutput +from sys import argv +from pylab import * +from numpy import * + + + + +if __name__=="__main__": + if len(argv) < 2: + print("Please provide an input filename.") + else: + fname = argv[1] + print("Onset Demo with `%s\'" % fname) + + SR = 16000.0 # Sampling Rate + T = 1./SR # Sampling Period + FS = 23.0 # ms + + # Describing the building blocks + + loader = MonoLoader(filename = fname, sampleRate = SR) + + onset = OnsetRate() + + # Pool (for output purposes) + + pool = essentia.Pool() + + + # Describing the connections + + + loader.audio >> onset.signal + loader.audio >> (pool, 'audio') + onset.onsetRate >> None + onset.onsetTimes >> (pool, 'onsettimes') + + + # Run it + + essentia.run(loader) + + + # Save the pool as a yaml file. + output = YamlOutput(filename = "%s.yaml" % fname.partition('/')[2].partition('.')[0])(pool) + + + ons = zeros((len(pool['audio']),1)) + + for i in range(0,len(pool['onsettimes'])): + ons[pool['onsettimes'][i]*44100]= 1 + + + t = linspace(0, len(pool['audio'])*T, len(pool['audio'])) + + plot(t, pool['audio'], t, ons); + xlabel('time (s)') + ylabel('f(t)') + title('Onset Detection Function') + savefig('output.png', dpi=600) + + + show() + + + + +