Showing the changes to python (14 of 42 files). Show all
Unified · Split
| @@ -1,14 +0,0 @@ | ||
| 1 | −import unittest | |
| 2 | − | |
| 3 | −class aubiomodule_test_case(unittest.TestCase): | |
| 4 | − | |
| 5 | − def test_aubio(self): | |
| 6 | − """ try importing aubio module """ | |
| 7 | − import aubio | |
| 8 | − | |
| 9 | − def test_aubiowrapper(self): | |
| 10 | − """ try importing aubio.aubiowrapper module """ | |
| 11 | − from aubio import aubiowrapper | |
| 12 | − | |
| 13 | −if __name__ == '__main__': | |
| 14 | − unittest.main() | |
| @@ -1,44 +0,0 @@ | ||
| 1 | −export BASEDIR=../../../.. | |
| 2 | −export PYTHONPATH=$(BASEDIR)/python | |
| 3 | −export LD_LIBRARY_PATH=$(BASEDIR)/src/.libs:$(BASEDIR)/ext/.libs | |
| 4 | − | |
| 5 | −DETAILSOURCE = \ | |
| 6 | − /var/tmp/Onset-Mirex2005/poly_pitched \ | |
| 7 | − /var/tmp/Onset-Mirex2005/solo_bars_and_bells \ | |
| 8 | − /var/tmp/Onset-Mirex2005/solo_brass \ | |
| 9 | − /var/tmp/Onset-Mirex2005/solo_drums \ | |
| 10 | − /var/tmp/Onset-Mirex2005/solo_plucked_strings \ | |
| 11 | − /var/tmp/Onset-Mirex2005/solo_singing_voice \ | |
| 12 | − /var/tmp/Onset-Mirex2005/solo_sustained_strings \ | |
| 13 | − /var/tmp/Onset-Mirex2005/solo_winds \ | |
| 14 | − /var/tmp/Onset-Mirex2005/complex | |
| 15 | − | |
| 16 | −SOURCE = /var/tmp/Onset-Mirex2005 | |
| 17 | − | |
| 18 | −TESTSOURCE = \ | |
| 19 | − /var/tmp/Onset-Mirex2005/solo_bars_and_bells \ | |
| 20 | − /var/tmp/Onset-Mirex2005/solo_winds \ | |
| 21 | − /archives/samples/DB/PercussivePhrases/CM18/Samba_Audio | |
| 22 | − | |
| 23 | −test-aubiocut: $(patsubst %, %.aubiocut, $(TESTSOURCE)) | |
| 24 | −test-aubiodelay: $(patsubst %, %.aubiodelay, $(TESTSOURCE)) | |
| 25 | −test-aubiowindow: $(patsubst %, %.aubiowindow, $(TESTSOURCE)) | |
| 26 | − | |
| 27 | −final-aubiocut: $(patsubst %, %.aubiocut, $(DETAILSOURCE) $(SOURCE)) | |
| 28 | −final-aubiodelay: $(patsubst %, %.aubiodelay, $(SOURCE)) | |
| 29 | −final-aubiowindow: $(patsubst %, %.aubiowindow, $(SOURCE)) | |
| 30 | − | |
| 31 | −%.aubiocut: % | |
| 32 | − rm -f `basename $@` | |
| 33 | − ./bench-onset $< | tee `basename $@` | |
| 34 | − -diff `basename $@`.ref `basename $@` | |
| 35 | − | |
| 36 | −%.aubiodelay: % | |
| 37 | − rm -f `basename $@` | |
| 38 | − ./bench-delay $< | tee `basename $@` | |
| 39 | − -diff `basename $@`.ref `basename $@` | |
| 40 | − | |
| 41 | −%.aubiowindow: % | |
| 42 | − rm -f `basename $@` | |
| 43 | − ./bench-window $< | tee `basename $@` | |
| 44 | − -diff `basename $@`.ref `basename $@` | |
| @@ -1,62 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −from aubio.bench.onset import benchonset | |
| 4 | −from aubio.task.onset import taskonset | |
| 5 | −from aubio.task.params import taskparams | |
| 6 | − | |
| 7 | −class mybenchonset(benchonset): | |
| 8 | − | |
| 9 | − def run_bench(self,modes=['dual'],thresholds=[0.5]): | |
| 10 | − from os.path import dirname,basename | |
| 11 | − self.thresholds = thresholds | |
| 12 | − self.pretty_titles() | |
| 13 | − | |
| 14 | − for mode in modes: | |
| 15 | − d = [] | |
| 16 | − self.params.onsetmode = mode | |
| 17 | − self.params.localmin = True | |
| 18 | − self.params.delay = 1. | |
| 19 | − self.params.threshold = thresholds[0] | |
| 20 | − # | |
| 21 | − self.params.localmin = False | |
| 22 | − self.params.delay = 0. | |
| 23 | − self.dir_eval_print() | |
| 24 | − self.plotdiffs(d,plottitle="Causal") | |
| 25 | − # | |
| 26 | − self.params.localmin = True | |
| 27 | − self.params.delay = 0. | |
| 28 | − self.dir_eval_print() | |
| 29 | − self.plotdiffs(d,plottitle="Local min") | |
| 30 | − | |
| 31 | − self.params.localmin = False | |
| 32 | − self.params.delay = 6. | |
| 33 | − self.dir_eval_print() | |
| 34 | − self.plotdiffs(d,plottitle="Fixed delay") | |
| 35 | − | |
| 36 | − #self.plotplotdiffs(d) | |
| 37 | − outplot = "_-_".join(("delay",mode,basename(self.datadir) )) | |
| 38 | − for ext in ("png","svg","ps"): | |
| 39 | − self.plotplotdiffs(d,outplot=outplot,extension=ext) | |
| 40 | − | |
| 41 | −if __name__ == "__main__": | |
| 42 | − import sys | |
| 43 | − if len(sys.argv) > 1: datapath = sys.argv[1] | |
| 44 | − else: print "ERR: a path is required"; sys.exit(1) | |
| 45 | − modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual'] | |
| 46 | − #thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] | |
| 47 | − #modes = [ 'hfc' ] | |
| 48 | − thresholds = [0.5] | |
| 49 | − | |
| 50 | − #datapath = "%s%s" % (DATADIR,'/onset/DB/*/') | |
| 51 | − respath = '/var/tmp/DB-testings' | |
| 52 | − | |
| 53 | − benchonset = mybenchonset(datapath,respath,checkres=True,checkanno=True) | |
| 54 | − benchonset.params = taskparams() | |
| 55 | − benchonset.task = taskonset | |
| 56 | − benchonset.valuesdict = {} | |
| 57 | − | |
| 58 | − try: | |
| 59 | − #benchonset.auto_learn2(modes=modes) | |
| 60 | − benchonset.run_bench(modes=modes,thresholds=thresholds) | |
| 61 | − except KeyboardInterrupt: | |
| 62 | − sys.exit(1) | |
| @@ -1,68 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −from aubio.task import * | |
| 4 | − | |
| 5 | −from aubio.bench.onset import mmean, stdev, benchonset | |
| 6 | − | |
| 7 | −class mybenchonset(benchonset): | |
| 8 | − | |
| 9 | − def run_bench(self,modes=['dual'],thresholds=[0.5]): | |
| 10 | − from os.path import dirname,basename | |
| 11 | − self.thresholds = thresholds | |
| 12 | − self.pretty_titles() | |
| 13 | − d,e,f,g = [],[],[],[] | |
| 14 | − for mode in modes: | |
| 15 | − self.vlist = [] | |
| 16 | − self.params.onsetmode = mode | |
| 17 | − #self.params.localmin = True | |
| 18 | − | |
| 19 | − for threshold in self.thresholds: | |
| 20 | − self.params.threshold = threshold | |
| 21 | − self.dir_eval_print() | |
| 22 | − self.vlist.append(self.v) | |
| 23 | − self.plotroc(d) | |
| 24 | − self.plotfmeas(e) | |
| 25 | − self.plotpr(f) | |
| 26 | − #self.plothistcat(g) | |
| 27 | − | |
| 28 | − | |
| 29 | − | |
| 30 | − #self.plotplotroc(d) | |
| 31 | − #self.plotplotfmeas(e) | |
| 32 | − #self.plotplotpr(f) | |
| 33 | − outplot = basename(self.datadir) | |
| 34 | − for ext in ("png","svg","ps"): | |
| 35 | − self.plotplotroc(d,outplot=outplot,extension=ext) | |
| 36 | − self.plotplotfmeas(e,outplot=outplot,extension=ext) | |
| 37 | − self.plotplotpr(f,outplot=outplot,extension=ext) | |
| 38 | − #self.plotplothistcat(g,outplot=outplot,extension=ext) | |
| 39 | − | |
| 40 | −if __name__ == "__main__": | |
| 41 | − import sys | |
| 42 | − if len(sys.argv) > 1: datapath = sys.argv[1] | |
| 43 | − else: print "ERR: a path is required"; sys.exit(1) | |
| 44 | − modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual'] | |
| 45 | − thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] | |
| 46 | − #modes = [ 'hfc' ] | |
| 47 | − #thresholds = [0.5] | |
| 48 | − | |
| 49 | − #datapath = "%s%s" % (DATADIR,'/onset/DB/*/') | |
| 50 | − respath = '/var/tmp/DB-testings' | |
| 51 | − | |
| 52 | − benchonset = mybenchonset(datapath,respath,checkres=True,checkanno=True) | |
| 53 | − benchonset.params = taskparams() | |
| 54 | − benchonset.params.dcthreshold = -1. | |
| 55 | − benchonset.params.silence = -100. | |
| 56 | − benchonset.params.delay = 5. | |
| 57 | − benchonset.params.bufsize = 1024 | |
| 58 | − benchonset.params.hopsize = 256 | |
| 59 | − benchonset.params.step = float(benchonset.params.hopsize)/float(benchonset.params.samplerate) | |
| 60 | − benchonset.params.mintol = 4.1 | |
| 61 | − benchonset.task = taskonset | |
| 62 | − benchonset.valuesdict = {} | |
| 63 | − | |
| 64 | − try: | |
| 65 | − #benchonset.auto_learn2(modes=modes) | |
| 66 | − benchonset.run_bench(modes=modes,thresholds=thresholds) | |
| 67 | − except KeyboardInterrupt: | |
| 68 | − sys.exit(1) | |
| @@ -1,59 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −from aubio.bench.onset import benchonset | |
| 4 | −from aubio.task.onset import taskonset | |
| 5 | −from aubio.task.params import taskparams | |
| 6 | − | |
| 7 | −class mybenchonset(benchonset): | |
| 8 | − | |
| 9 | − def run_bench(self,modes=['dual'],thresholds=[0.5]): | |
| 10 | − from os.path import dirname,basename | |
| 11 | − self.thresholds = thresholds | |
| 12 | − self.pretty_titles() | |
| 13 | − | |
| 14 | − for mode in modes: | |
| 15 | − | |
| 16 | − self.params.onsetmode = mode | |
| 17 | − self.params.localmin = True | |
| 18 | − self.params.delay = 1. | |
| 19 | − self.params.threshold = thresholds[0] | |
| 20 | − self.params.localmin = False | |
| 21 | − # | |
| 22 | − for delay in (0., 4.): | |
| 23 | − d = [] | |
| 24 | − self.params.delay = delay | |
| 25 | − for buf in (2048, 1024, 512): | |
| 26 | − for hop in (buf/2, buf/4): | |
| 27 | − self.params.bufsize = buf | |
| 28 | − self.params.hopsize = hop | |
| 29 | − self.params.step = float(self.params.hopsize)/float(self.params.samplerate) | |
| 30 | − self.dir_eval_print() | |
| 31 | − self.plotdiffs(d,plottitle="%s %s" % (buf,hop)) | |
| 32 | − #plotplotdiffs(d) | |
| 33 | − outplot = "_-_".join(("window",mode,"delay-%s" % int(delay), | |
| 34 | − basename(self.datadir) )) | |
| 35 | − for ext in ("png","svg","ps"): | |
| 36 | − self.plotplotdiffs(d,outplot=outplot,extension=ext) | |
| 37 | − | |
| 38 | −if __name__ == "__main__": | |
| 39 | − import sys | |
| 40 | − if len(sys.argv) > 1: datapath = sys.argv[1] | |
| 41 | − else: print "ERR: a path is required"; sys.exit(1) | |
| 42 | − modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual'] | |
| 43 | − #thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2] | |
| 44 | − #modes = [ 'hfc' ] | |
| 45 | − thresholds = [0.5] | |
| 46 | − | |
| 47 | − #datapath = "%s%s" % (DATADIR,'/onset/DB/*/') | |
| 48 | − respath = '/var/tmp/DB-testings' | |
| 49 | − | |
| 50 | − benchonset = mybenchonset(datapath,respath,checkres=True,checkanno=True) | |
| 51 | − benchonset.params = taskparams() | |
| 52 | − benchonset.task = taskonset | |
| 53 | − benchonset.valuesdict = {} | |
| 54 | − | |
| 55 | − try: | |
| 56 | − #benchonset.auto_learn2(modes=modes) | |
| 57 | − benchonset.run_bench(modes=modes,thresholds=thresholds) | |
| 58 | − except KeyboardInterrupt: | |
| 59 | − sys.exit(1) | |
| @@ -1,59 +0,0 @@ | ||
| 1 | −export AUBIODIR=../../../.. | |
| 2 | −export PYTHONPATH=$(AUBIODIR)/python | |
| 3 | −export LD_LIBRARY_PATH=$(AUBIODIR)/src/.libs:$(AUBIODIR)/ext/.libs | |
| 4 | − | |
| 5 | −CP=cp -a | |
| 6 | − | |
| 7 | −SOURCE = \ | |
| 8 | − $(BASEDIR)/isolated/vibraphone \ | |
| 9 | − $(BASEDIR)/isolated/clavinet \ | |
| 10 | − $(BASEDIR)/isolated/elecguitar \ | |
| 11 | − $(BASEDIR)/isolated/piano \ | |
| 12 | − $(BASEDIR)/isolated/rhodes \ | |
| 13 | − $(BASEDIR)/isolated | |
| 14 | − | |
| 15 | − | |
| 16 | −MONOSOURCE = \ | |
| 17 | − $(BASEDIR)/monophonic/Mirex04/daisy \ | |
| 18 | − $(BASEDIR)/monophonic/Mirex04/midi \ | |
| 19 | − $(BASEDIR)/monophonic/Mirex04/jazz \ | |
| 20 | − $(BASEDIR)/monophonic/Mirex04/pop \ | |
| 21 | − $(BASEDIR)/monophonic/Mirex04/opera \ | |
| 22 | − $(BASEDIR)/monophonic/Mirex04 | |
| 23 | − | |
| 24 | −POLYSOURCE = \ | |
| 25 | − $(BASEDIR)/polyphonic/Mirex04/daisy \ | |
| 26 | − $(BASEDIR)/polyphonic/Mirex04/midi \ | |
| 27 | − $(BASEDIR)/polyphonic/Mirex04/jazz \ | |
| 28 | − $(BASEDIR)/polyphonic/Mirex04/pop \ | |
| 29 | − $(BASEDIR)/polyphonic/Mirex04/opera \ | |
| 30 | − $(BASEDIR)/polyphonic/Mirex04 | |
| 31 | − | |
| 32 | −test-aubiopitch-isolated: $(patsubst %, %.aubiopitch-isolated, $(SOURCE)) | |
| 33 | −test-aubiopitch-monophonic: $(patsubst %, %.aubiopitch-monophonic, $(MONOSOURCE)) | |
| 34 | −test-aubiopitch-polyphonic: $(patsubst %, %.aubiopitch-polyphonic, $(POLYSOURCE)) | |
| 35 | − | |
| 36 | −plotpitch: | |
| 37 | − ../../../aubiopitch -m fcomb,mcomb,yinfft,yin,schmitt -i jazz2REF.wav -p -t 0.2 -l 100 -M 600 -O jazz2REF.ps | |
| 38 | − ../../../aubiopitch -m fcomb,mcomb,yinfft,yin,schmitt -p -t 0.2 -l 300 -M 900 -i opera_fem2REF.wav -O opera_fem2REF.ps | |
| 39 | − | |
| 40 | −timings: | |
| 41 | − ./bench-timings $(BASEDIR)/polyphonic/Mirex04/opera | |
| 42 | − | |
| 43 | −%.aubiopitch-isolated: % | |
| 44 | − $(CP) isolated/`basename $@` isolated/`basename $@`.old | |
| 45 | − ./bench-pitch-isolated $< | tee isolated/`basename $@` | |
| 46 | − -diff isolated/`basename $@`.old isolated/`basename $@` | |
| 47 | − -diff isolated/`basename $@`.ref isolated/`basename $@` | |
| 48 | − | |
| 49 | −%.aubiopitch-monophonic: % | |
| 50 | − $(CP) monophonic/`basename $@` monophonic/`basename $@`.old | |
| 51 | − ./bench-pitch-monophonic $< | tee monophonic/`basename $@` | |
| 52 | − -diff monophonic/`basename $@`.ref monophonic/`basename $@` | |
| 53 | − -diff monophonic/`basename $@`.old monophonic/`basename $@` | |
| 54 | − | |
| 55 | −%.aubiopitch-polyphonic: % | |
| 56 | − $(CP) polyphonic/`basename $@` polyphonic/`basename $@`.old | |
| 57 | − ./bench-pitch-polyphonic $< | tee polyphonic/`basename $@` | |
| 58 | − -diff polyphonic/`basename $@`.ref polyphonic/`basename $@` | |
| 59 | − -diff polyphonic/`basename $@`.old polyphonic/`basename $@` | |
| @@ -1,198 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −from aubio.bench.node import * | |
| 4 | −from aubio.task import * | |
| 5 | − | |
| 6 | −class benchpitch(bench): | |
| 7 | − | |
| 8 | − """ list of values to store per file """ | |
| 9 | − valuenames = ['mode'] | |
| 10 | − """ list of lists to store per file """ | |
| 11 | − valuelists = ['truth', 'osil', 'esil', 'opit', 'epit', 'echr', | |
| 12 | − 'Msil', 'Mpit', 'Mchr', | |
| 13 | − 'TotalPit', 'TotalPit', 'TotalChr' ] | |
| 14 | − """ list of values to print per dir """ | |
| 15 | − printnames_total = [ 'mode', 'MinPit', 'MaxPit', 'TotalSil', 'TotalPit', 'TotalChr'] | |
| 16 | − printnames_notes = [ 'mode', 'Note', 'Sil', 'Pit', 'Chr'] | |
| 17 | − printnames = printnames_notes | |
| 18 | − | |
| 19 | − """ per dir """ | |
| 20 | − formats = {'mode': "%12s" , | |
| 21 | − 'truth': "%s", | |
| 22 | − 'osil': "%s", 'esil': "%s", | |
| 23 | − 'opit': "%s", 'epit': "%s", 'echr': "%s", | |
| 24 | − 'Note': "%s", 'Sil': "%s", 'Chr': "%s", 'Pit': "%s", | |
| 25 | − 'TotalPit': "%s", 'TotalSil': "%s", 'TotalChr': "%s", | |
| 26 | − 'MinPit': "%s", 'MaxPit': "%s", | |
| 27 | − 'Msil': "%s", 'Mpit': "%s", 'Mchr': "%s"} | |
| 28 | − | |
| 29 | − def dir_eval(self): | |
| 30 | − """ evaluate statistical data over the directory """ | |
| 31 | − v = self.v | |
| 32 | − v['mode'] = self.params.pitchmode | |
| 33 | − | |
| 34 | − def file_exec(self,input,output): | |
| 35 | − filetask = self.task(input,params=self.params) | |
| 36 | − computed_data = filetask.compute_all() | |
| 37 | − osil, esil, opit, epit, echr = filetask.eval(computed_data,tol=0.5) | |
| 38 | − self.v['truth'].append(int(filetask.truth)) | |
| 39 | − assert opit > 0 | |
| 40 | − | |
| 41 | − self.v['osil'].append(osil) | |
| 42 | − self.v['esil'].append(esil) | |
| 43 | − self.v['opit'].append(opit) | |
| 44 | − self.v['epit'].append(epit) | |
| 45 | − self.v['echr'].append(echr) | |
| 46 | − | |
| 47 | − self.v['Msil'].append(esil/float(osil)*100.) | |
| 48 | − self.v['Mpit'].append(epit/float(opit)*100.) | |
| 49 | − self.v['Mchr'].append(echr/float(opit)*100.) | |
| 50 | − #print results#, computed_data | |
| 51 | − #print input, results, results - float(input.split('.')[-2]) | |
| 52 | − | |
| 53 | − def run_bench(self,modes=['schmitt'],multiplot=0): | |
| 54 | − from os.path import basename | |
| 55 | − self.modes = modes | |
| 56 | − self.pretty_titles() | |
| 57 | − d = [] | |
| 58 | − for mode in self.modes: | |
| 59 | − self.params.pitchmode = mode | |
| 60 | − self.dir_exec() | |
| 61 | − self.dir_eval() | |
| 62 | − truth = [i for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 63 | − allOsil = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 64 | − allEsil = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 65 | − allOpit = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 66 | − allEpit = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 67 | − allEchr = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 68 | − allMsil = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 69 | − allMpit = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 70 | − allMchr = [0 for i in range(min(self.v['truth']),max(self.v['truth'])+1)] | |
| 71 | − for i in range(len(self.v['truth'])): | |
| 72 | − allOsil[self.v['truth'][i]-min(self.v['truth'])] += self.v['osil'][i] | |
| 73 | − allEsil[self.v['truth'][i]-min(self.v['truth'])] += self.v['esil'][i] | |
| 74 | − allOpit[self.v['truth'][i]-min(self.v['truth'])] += self.v['opit'][i] | |
| 75 | − allEpit[self.v['truth'][i]-min(self.v['truth'])] += self.v['epit'][i] | |
| 76 | − allEchr[self.v['truth'][i]-min(self.v['truth'])] += self.v['echr'][i] | |
| 77 | − for i in range(len(truth)): | |
| 78 | − allOsil[i] = max(1,allOsil[i]) | |
| 79 | − allOpit[i] = max(1,allOpit[i]) | |
| 80 | − allMsil[i] = allEsil[i]/float(allOsil[i])*100. | |
| 81 | − allMpit[i] = allEpit[i]/float(allOpit[i])*100. | |
| 82 | − allMchr[i] = allEchr[i]/float(allOpit[i])*100. | |
| 83 | − self.v['Sil'], self.v['Pit'], self.v['Chr'] = allMsil[i], allMpit[i], allMchr[i] | |
| 84 | − self.v['Note'] = truth[i] | |
| 85 | − #self.printnames = self.printnames_notes | |
| 86 | − self.pretty_print() | |
| 87 | − self.v['TotalSil'] = sum(allMsil)/len(truth) | |
| 88 | − self.v['TotalPit'] = sum(allMpit)/len(truth) | |
| 89 | − self.v['TotalChr'] = sum(allMchr)/len(truth) | |
| 90 | − self.v['MinPit'] = min(truth) | |
| 91 | − self.v['MaxPit'] = max(truth) | |
| 92 | − #self.printnames = self.printnames_total | |
| 93 | − #self.pretty_print() | |
| 94 | − | |
| 95 | − plot = [] | |
| 96 | − self.plotpitchtessiture(plot, | |
| 97 | − truth, | |
| 98 | − allMpit, | |
| 99 | − plottitle="%s %s" % (self.v['mode'],self.params.bufsize), | |
| 100 | − plotmode='lines') | |
| 101 | − """ | |
| 102 | − self.plotpitchtessiture(plot, | |
| 103 | − truth, | |
| 104 | − allMchr, | |
| 105 | − plottitle="%s %s" % (self.v['mode'],"%12"), | |
| 106 | − plotmode='lines') | |
| 107 | − self.plotpitchtessiture(plot, | |
| 108 | − truth, | |
| 109 | − allMsil, | |
| 110 | − plottitle="%s %s" % (self.v['mode'],"sil"), | |
| 111 | − plotmode='lines') | |
| 112 | − """ | |
| 113 | − title = basename(self.datadir) | |
| 114 | − if multiplot: | |
| 115 | − d.append(plot) | |
| 116 | − else: | |
| 117 | − d += plot | |
| 118 | − outplot = "_-_".join(('pitchtessiture',title)) | |
| 119 | − self.xmin = min(self.v['truth']) #20. | |
| 120 | − self.xmax = max(self.v['truth']) | |
| 121 | − for ext in ('ps','png','svg'): #,''): | |
| 122 | − self.plotplotpitchtessiture(d, | |
| 123 | − plottitle="".join(['Performance against MIDI Note number (', | |
| 124 | − title, | |
| 125 | − ", %s" % len(self.sndlist), " samples)"]), | |
| 126 | − outplot=outplot, | |
| 127 | − extension=ext,multiplot=multiplot) | |
| 128 | − #d.append('beta = .25,orig(x) title \"-2 octave\"') | |
| 129 | − #d.append('beta = .50,orig(x) title \"-1 octave\"') | |
| 130 | − #d.append('beta = 1.0,orig(x) title \"original\"') | |
| 131 | − #d.append('beta = 2.0,orig(x) title \"+1 octave\"') | |
| 132 | − | |
| 133 | − """ | |
| 134 | − Plot functions | |
| 135 | − """ | |
| 136 | − | |
| 137 | − def plotpitchtessiture(self,d,lx,ly,plottitle="",plotmode='linespoints'): | |
| 138 | − import Gnuplot, Gnuplot.funcutils | |
| 139 | − d.append(Gnuplot.Data(lx, ly, with=plotmode, title="%s" % (plottitle) )) | |
| 140 | − | |
| 141 | − def plotplotpitchtessiture(self,d,plottitle='',outplot=0,extension='',multiplot=1): | |
| 142 | − from aubio.gnuplot import gnuplot_create | |
| 143 | − g = gnuplot_create(outplot=outplot,extension=extension) | |
| 144 | − #g.title(plottitle) | |
| 145 | − #g('orig(x) = beta*x') | |
| 146 | − g.title(plottitle) | |
| 147 | − g('set yrange [50:100]') | |
| 148 | − # erase axis | |
| 149 | − g('set xrange [%f:%f]' % (self.xmin,self.xmax)) #(self.xmax - (self.xmax-self.xmin)*5./4.,self.xmax)) | |
| 150 | − #g.plot(*d) | |
| 151 | − g('set border 3') | |
| 152 | − g('set xtics nomirror') | |
| 153 | − g('set ytics nomirror') | |
| 154 | − g('set key bottom') | |
| 155 | − if multiplot: | |
| 156 | − g('set multiplot') | |
| 157 | − for i in range(len(d)): | |
| 158 | − # plot onset detection functions | |
| 159 | − g('set size 1,%f' % ( 1.0/float(len(d)) ) ) | |
| 160 | − g('set origin 0,%f' % ( 1.0*float(len(d)-i-1)/float(len(d)) ) ) | |
| 161 | − #g.ylabel('%Correct detections') | |
| 162 | − g('set xrange [%f:%f]' % (self.xmin,self.xmax)) #(self.xmax - (self.xmax-self.xmin)*5./4.,self.xmax)) | |
| 163 | − g.plot(*d[i]) | |
| 164 | − g('unset title') | |
| 165 | − g('unset multiplot') | |
| 166 | − else: | |
| 167 | − g.plot(*d) | |
| 168 | − | |
| 169 | − | |
| 170 | −if __name__ == "__main__": | |
| 171 | − import sys | |
| 172 | − if len(sys.argv) > 1: datapath = sys.argv[1] | |
| 173 | − else: print "error: a path is required"; sys.exit(1) | |
| 174 | − if len(sys.argv) > 2: | |
| 175 | − for each in sys.argv[3:-1]: print each | |
| 176 | − modes = ['schmitt', 'yin', 'yinfft', 'mcomb', 'fcomb'] | |
| 177 | − #modes = ['mcomb'] | |
| 178 | − | |
| 179 | − params = taskparams() | |
| 180 | − params.bufsize = 2048 # 4096 | |
| 181 | − params.hopsize = 256 | |
| 182 | − params.silence = -60. | |
| 183 | − params.pitchsmooth = 0 | |
| 184 | − params.pitchmax = 20000 | |
| 185 | − params.pitchmin = 20 | |
| 186 | − params.pitchyinfft = 0.95 | |
| 187 | − benchpitch = benchpitch(datapath,params=params) | |
| 188 | − benchpitch.task = taskpitch | |
| 189 | − | |
| 190 | − #benchpitch.titles = [ 'mode', 'thres', 'avg', 'avgdist' ] | |
| 191 | − #benchpitch.formats = ["%12s" , "| %6s", "| %6s", "| %6s", "| %6s", "| %6s" ] | |
| 192 | − try: | |
| 193 | − benchpitch.run_bench(modes=modes) | |
| 194 | − except KeyboardInterrupt: | |
| 195 | − print "Interrupted by user" | |
| 196 | − sys.exit(1) | |
| 197 | − | |
| 198 | − sys.exit(0) | |
| @@ -1,63 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −if __name__ == '__main__': | |
| 4 | − import sys, Gnuplot | |
| 5 | − from aubio.gnuplot import gnuplot_create | |
| 6 | − from aubio.txtfile import read_datafile | |
| 7 | − from aubio.plot.keyboard import draw_keyboard | |
| 8 | − lines = [] | |
| 9 | − titles = [] | |
| 10 | − for file in range(len(sys.argv)-1): | |
| 11 | − l = read_datafile(sys.argv[file+1]) | |
| 12 | − notes, score = [],[] | |
| 13 | − for i in range(len(l)): | |
| 14 | − notes.append(l[i][0]) | |
| 15 | − score.append(l[i][2]) | |
| 16 | − lines.append(Gnuplot.Data(notes,score, | |
| 17 | − with='linespoints', | |
| 18 | − title=sys.argv[file+1].split('.')[-1])) | |
| 19 | − titles.append(sys.argv[file+1].split('.')[-1]) | |
| 20 | − blacks,whites = draw_keyboard(firstnote = notes[0], lastnote = notes[-1], | |
| 21 | − y0= 40, y1 = 50) | |
| 22 | − | |
| 23 | − g = gnuplot_create(sys.argv[file+1].split('.')[-3],'ps') | |
| 24 | − #g = gnuplot_create('','') | |
| 25 | − #g = gnuplot_create('/tmp/test','eps') | |
| 26 | − g('set yrange [40:100]') | |
| 27 | − #g('set xrange [%f:%f]' % (notes[0],notes[-1]+60)) | |
| 28 | − g('set size 0.5') | |
| 29 | − g('set key outside') | |
| 30 | − | |
| 31 | − g('set border 3') | |
| 32 | − g('set xtics nomirror') | |
| 33 | − g('set ytics nomirror') | |
| 34 | − multiplot = 1 | |
| 35 | − oplots = lines | |
| 36 | − g('set size 1,2') | |
| 37 | − if multiplot: | |
| 38 | − height = 2. | |
| 39 | − g('set lmargin 10') | |
| 40 | − #g('set rmargin 15') | |
| 41 | − g('set multiplot') | |
| 42 | − g('set yrange [50:100]') | |
| 43 | − g('set xrange [%f:%f]' % (notes[0],notes[-1])) | |
| 44 | − g('set xtics %f,12' % notes[0]) | |
| 45 | − g('set nokey') | |
| 46 | − for i in range(len(oplots)): | |
| 47 | − g.ylabel(titles[i]) | |
| 48 | − g('set size %f,%f' % (1.,height*.85/float(len(oplots)))) | |
| 49 | − g('set origin 0,%f' % (height*(.15+.85*float(len(oplots)-i-1)/float(len(oplots))))) | |
| 50 | − g.plot(oplots[i]) | |
| 51 | − g('set title "Raw pitch accuracy (%) against midi note numbers"') | |
| 52 | − g('set noxtics') | |
| 53 | − g('set noytics') | |
| 54 | − g('set size %f,%f' % (1.,.15*height)) | |
| 55 | − g('set origin 0,%f' % 0) | |
| 56 | − g('set yrange [40:50]') | |
| 57 | − g('set xrange [%f:%f]' % (notes[0],notes[-1])) | |
| 58 | − g.xlabel('') | |
| 59 | − g.ylabel('') | |
| 60 | − g.plot(whites,blacks) | |
| 61 | − g('unset multiplot') | |
| 62 | − else: | |
| 63 | − g.plot(whites,blacks,*lines) | |
| @@ -1,313 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −""" this file was written by Paul Brossier | |
| 4 | − it is released under the GNU/GPL license. | |
| 5 | −""" | |
| 6 | − | |
| 7 | −import sys,time | |
| 8 | −from aubio.task import taskbeat,taskparams | |
| 9 | −from aubio.aubioclass import fvec, aubio_autocorr | |
| 10 | −from aubio.gnuplot import gnuplot_create, gnuplot_addargs | |
| 11 | −from aubio.aubiowrapper import * | |
| 12 | −from math import exp,log | |
| 13 | − | |
| 14 | −usage = "usage: %s [options] -i soundfile" % sys.argv[0] | |
| 15 | − | |
| 16 | −def parse_args(): | |
| 17 | − from optparse import OptionParser | |
| 18 | − parser = OptionParser(usage=usage) | |
| 19 | − parser.add_option("-i","--input", | |
| 20 | − action="store", dest="filename", | |
| 21 | − help="input sound file") | |
| 22 | − parser.add_option("-n","--printframe", | |
| 23 | − action="store", dest="printframe", default=-1, | |
| 24 | − help="make a plot of the n_th frame") | |
| 25 | − gnuplot_addargs(parser) | |
| 26 | − (options, args) = parser.parse_args() | |
| 27 | − if not options.filename: | |
| 28 | − print "no file name given\n", usage | |
| 29 | − sys.exit(1) | |
| 30 | − return options, args | |
| 31 | − | |
| 32 | −def plotdata(x,y,plottitle="",**keyw): | |
| 33 | − import Gnuplot | |
| 34 | − return Gnuplot.Data(x, y, title="%s" % plottitle,**keyw) | |
| 35 | − | |
| 36 | −options, args = parse_args() | |
| 37 | −filename = options.filename | |
| 38 | −xsize = float(options.xsize) | |
| 39 | −ysize = float(options.ysize) | |
| 40 | − | |
| 41 | −printframe = int(options.printframe) | |
| 42 | − | |
| 43 | −if options.outplot and printframe > 0: | |
| 44 | − extension = options.outplot.split('.')[-1] | |
| 45 | − outplot = '.'.join(options.outplot.split('.')[:-1]) | |
| 46 | −else: | |
| 47 | − extension = '' | |
| 48 | − outplot = None | |
| 49 | −f = gnuplot_create(outplot=outplot,extension=extension,options=options) | |
| 50 | − | |
| 51 | −params = taskparams() | |
| 52 | −params.onsetmode = 'specdiff' | |
| 53 | −task = taskbeat(filename,params=params) | |
| 54 | − | |
| 55 | −hopsize = params.hopsize | |
| 56 | −bufsize = params.bufsize | |
| 57 | −btstep = task.btstep | |
| 58 | −winlen = task.btwinlen | |
| 59 | −laglen = winlen/4 | |
| 60 | −step = winlen/4 | |
| 61 | − | |
| 62 | −timesig = 0 | |
| 63 | −maxnumelem = 4 | |
| 64 | −gp = 0 | |
| 65 | −counter = 0 | |
| 66 | −flagconst = 0 | |
| 67 | −constthresh = 3.901 | |
| 68 | −g_var = 3.901 | |
| 69 | −rp = 0 | |
| 70 | −rp1 = 0 | |
| 71 | −rp2 = 0 | |
| 72 | −g_mu = 0 | |
| 73 | − | |
| 74 | −rayparam = 48/512.*winlen | |
| 75 | − | |
| 76 | −#t = [i for i in range(hopsize)] | |
| 77 | −#tlong = [i for i in range(hopsize*(btstep-1))] | |
| 78 | −#tall = [i for i in range(hopsize*btstep)] | |
| 79 | −#a = [0 for i in range(hopsize*btstep)] | |
| 80 | −dfx = [i for i in range(winlen)] | |
| 81 | −dfframe = [0 for i in range(winlen)] | |
| 82 | −dfrev = [0 for i in range(winlen)] | |
| 83 | −acframe = [0 for i in range(winlen)] | |
| 84 | − | |
| 85 | −localacf = [0 for i in range(winlen)] | |
| 86 | −inds = [0 for i in range(maxnumelem)] | |
| 87 | − | |
| 88 | −acx = [i for i in range(laglen)] | |
| 89 | −acfout = [0 for i in range(laglen)] | |
| 90 | − | |
| 91 | −phwv = [0 for i in range(2*laglen)] | |
| 92 | −phwvx = [i for i in range(2*laglen)] | |
| 93 | − | |
| 94 | −dfwvnorm = exp(log(2.0)*(winlen+2.)/rayparam); | |
| 95 | −dfwv = [exp(log(2.)*(i+1.)/rayparam)/dfwvnorm for i in range(winlen)] | |
| 96 | − | |
| 97 | −gwv = [exp(-.5*(j+1.-g_mu)**2/g_var**2) for j in range(laglen)] | |
| 98 | −rwv = [(i+1.)/rayparam**2 * exp(-(i+1.)**2 / (2.*rayparam)**2) | |
| 99 | − for i in range(0,laglen)] | |
| 100 | −acf = fvec(winlen,1) | |
| 101 | − | |
| 102 | −nrframe = 0 | |
| 103 | −while (task.readsize == params.hopsize): | |
| 104 | − task() | |
| 105 | − #print task.pos2 | |
| 106 | − #a[:-hopsize] = [i for i in a[-(btstep-1)*hopsize:]] | |
| 107 | − #a[-hopsize:] = [task.myvec.get(i,0) for i in t] | |
| 108 | − | |
| 109 | − #g('set xrange [%f:%f]' % (t[0],t[-1])) | |
| 110 | − #time.sleep(.2) | |
| 111 | − if task.pos2==btstep-1: | |
| 112 | − nrframe += 1 | |
| 113 | − dfframe = [task.dfframe.get(i,0) for i in range(winlen)] | |
| 114 | − if printframe == nrframe or printframe == -1: | |
| 115 | − d = [[plotdata(range(-winlen,0),dfframe,plottitle="onset detection", with='lines')]] | |
| 116 | − # start beattracking_do | |
| 117 | − for i in range(winlen): | |
| 118 | − dfrev[winlen-1-i] = 0. | |
| 119 | − dfrev[winlen-1-i] = dfframe[i]*dfwv[i] | |
| 120 | − aubio_autocorr(task.dfframe(),acf()); | |
| 121 | − acframe = [acf.get(i,0) for i in range(winlen)] | |
| 122 | − if not timesig: | |
| 123 | − numelem = 4 | |
| 124 | − else: | |
| 125 | − numelem = timesig | |
| 126 | − | |
| 127 | − old = 0 | |
| 128 | − acfout = [0 for i in range(winlen/4)] | |
| 129 | − for i in range(1,laglen-1): | |
| 130 | − for a in range(1,numelem+1): | |
| 131 | − for b in range (1-a,a): | |
| 132 | − acfout[i] += acframe[a*(i+1)+b-1] * 1./(2.*a-1.)*rwv[i] | |
| 133 | − if old < acfout[i]: | |
| 134 | − old = acfout[i] | |
| 135 | − maxi = i | |
| 136 | − rp = max(maxi,1); | |
| 137 | − | |
| 138 | − if printframe == nrframe or printframe == -1: | |
| 139 | − rwvs = [rwv[i]*max(acframe) for i in range(len(rwv))] | |
| 140 | − d += [[plotdata(acx,acfout,plottitle="comb filterbank", with='lines', axes='x1y1'), | |
| 141 | − plotdata([rp,rp],[1.2*old,min(acfout)],plottitle="period", with='impulses', axes='x1y1'), | |
| 142 | − plotdata(acx,rwvs,plottitle="L_w", with='lines', axes='x1y1')]] | |
| 143 | − | |
| 144 | − # getperiod | |
| 145 | − inds = [0 for i in range(maxnumelem)] | |
| 146 | − localacf = [0 for i in range(winlen)] | |
| 147 | − period = 0 | |
| 148 | − for a in range(1,4+1): | |
| 149 | − for b in range(1-a,a): | |
| 150 | − localacf[a*rp+b-1] = acframe[a*rp+b-1] | |
| 151 | − for i in range(numelem): | |
| 152 | − maxindex = 0 | |
| 153 | − maxval = 0.0 | |
| 154 | − for j in range(rp*(i+1)+i): | |
| 155 | − if localacf[j] > maxval: | |
| 156 | − maxval = localacf[j] | |
| 157 | − maxind = j | |
| 158 | − localacf[j] = 0 | |
| 159 | − inds[i] = maxind | |
| 160 | − for i in range(numelem): | |
| 161 | − period += inds[i]/(i+1.) | |
| 162 | − period = period/numelem | |
| 163 | − #print "period", period | |
| 164 | − | |
| 165 | − # checkstate | |
| 166 | − if gp: | |
| 167 | − # context dependant model | |
| 168 | − acfout = [0 for i in range(winlen/4)] | |
| 169 | − old = 0 | |
| 170 | − for i in range(laglen-1): | |
| 171 | − for a in range(timesig): | |
| 172 | − for b in range(1-a,a): | |
| 173 | − acfout[i] += acframe[a*(i+1)+b-1] * gwv[i] | |
| 174 | − if old < acfout[i]: | |
| 175 | − old = acfout[i] | |
| 176 | − maxi = i | |
| 177 | − gp = maxi | |
| 178 | − else: | |
| 179 | − # general model | |
| 180 | − gp = 0 | |
| 181 | − #print "gp", gp | |
| 182 | − if printframe == nrframe or printframe == -1: | |
| 183 | − gwvs = [gwv[i]*max(acfout) for i in range(len(gwv))] | |
| 184 | − d += [[plotdata(acx,acfout,plottitle="comb filterbank", with='lines', axes='x1y1'), | |
| 185 | − plotdata(gp,old,plottitle="period", with='impulses', axes='x1y1'), | |
| 186 | − plotdata(acx,gwvs,plottitle="L_{gw}", with='lines', axes='x1y1')]] | |
| 187 | − | |
| 188 | − if counter == 0: | |
| 189 | − # initial step | |
| 190 | − if abs(gp-rp) > 2.*constthresh: | |
| 191 | − flagstep = 1 | |
| 192 | − counter = 3 | |
| 193 | − else: | |
| 194 | − flagstep = 0 | |
| 195 | − #print "flagstep", flagstep | |
| 196 | − #print "rp2,rp1,rp", rp2,rp1,rp | |
| 197 | − acfw = [dfframe[i]*dfwv[i] for i in range(winlen)] | |
| 198 | − | |
| 199 | − if counter == 1 and flagstep == 1: | |
| 200 | − # "3rd frame after flagstep set" | |
| 201 | − if abs(2.*rp-rp1- rp2) < constthresh: | |
| 202 | − flagconst = 1 | |
| 203 | − counter = 0 | |
| 204 | − else: | |
| 205 | − flagconst = 0 | |
| 206 | − counter = 2 | |
| 207 | − elif counter > 0: | |
| 208 | − counter -= 1 | |
| 209 | − | |
| 210 | − rp2 = rp1; rp1 = rp | |
| 211 | − | |
| 212 | − if flagconst: | |
| 213 | − # "first run of new hypothesis" | |
| 214 | − gp = rp | |
| 215 | − g_mu = gp | |
| 216 | − timesig = 4 #FIXME | |
| 217 | − gwv = [exp(-.5*(j+1.-g_mu)**2/g_var**2) for j in range(laglen)] | |
| 218 | − flagconst = 0 | |
| 219 | − bp = gp | |
| 220 | − phwv = [1 for i in range(2*laglen)] | |
| 221 | − elif timesig: | |
| 222 | − # "contex dependant" | |
| 223 | − bp = gp | |
| 224 | − if step > lastbeat: | |
| 225 | − phwv = [exp(-.5*(1.+j-step+lastbeat)**2/(bp/8.)) for j in range(2*laglen)] | |
| 226 | − else: | |
| 227 | − print "NOT using phase weighting" | |
| 228 | − phwv = [1 for i in range(2*laglen)] | |
| 229 | − else: | |
| 230 | − # "initial state" | |
| 231 | − bp = rp | |
| 232 | − phwv = [1 for i in range(2*laglen)] | |
| 233 | − | |
| 234 | − while bp < 25: | |
| 235 | − print "WARNING, doubling the beat period" | |
| 236 | − bp *= 2 | |
| 237 | − | |
| 238 | − # | |
| 239 | − phout = [0. for i in range(winlen)] | |
| 240 | − | |
| 241 | − kmax = int(winlen/float(bp)); | |
| 242 | − | |
| 243 | − old = 0 | |
| 244 | − for i in range(bp): | |
| 245 | − phout[i] = 0. | |
| 246 | − for k in range(kmax): | |
| 247 | − phout[i] += dfrev[i+bp*k] * phwv[i] | |
| 248 | − if phout[i] > old: | |
| 249 | − old = phout[i] | |
| 250 | − maxi = i | |
| 251 | − maxindex = maxi | |
| 252 | − if (maxindex == winlen - 1): maxindex = 0 | |
| 253 | − phase = 1 + maxindex | |
| 254 | − i = 1 | |
| 255 | − beat = bp - phase | |
| 256 | − beats= [] | |
| 257 | − if beat >= 0: beats.append(beat) | |
| 258 | − while beat+bp < step: | |
| 259 | − beat += bp | |
| 260 | − beats.append(beat) | |
| 261 | − lastbeat = beat | |
| 262 | − #print beats, | |
| 263 | − #print "the lastbeat is", lastbeat | |
| 264 | − | |
| 265 | − # plot all this | |
| 266 | − if printframe == nrframe or printframe == -1: | |
| 267 | − phwvs = [phwv[i]*max(phout) for i in range(len(phwv))] | |
| 268 | − d += [[plotdata(range(-laglen,0),phwvs[laglen:0:-1],plottitle="A_{gw}", with='lines',axes='x1y1'), | |
| 269 | − plotdata(range(-laglen,0),phout[laglen:0:-1],plottitle="df", with='lines'), | |
| 270 | − plotdata(-phase,old,plottitle="phase", with='impulses', axes='x1y1'), | |
| 271 | − plotdata([i for i in beats],[old for i in beats],plottitle="predicted", with='impulses') | |
| 272 | − ]] | |
| 273 | − #d += [[plotdata(dfx,dfwv,plottitle="phase weighting", with='lines', axes='x1y2'), | |
| 274 | − # plotdata(dfx,dfrev,plottitle="df reverse", with='lines', axes='x1y1')]] | |
| 275 | − #d += [[plotdata(dfx,phout,plottitle="phase", with='lines', axes='x1y2')]] | |
| 276 | − #d += [[plotdata(dfx,dfwv,plottitle="phase weighting", with='lines', axes='x1y2'), | |
| 277 | − # plotdata(dfx,dfrev,plottitle="df reverse", with='lines', axes='x1y1')]] | |
| 278 | − #d += [[plotdata(dfx,phout,plottitle="phase", with='lines', axes='x1y2')]] | |
| 279 | − | |
| 280 | − f('set lmargin 4') | |
| 281 | − f('set rmargin 4') | |
| 282 | − f('set size %f,%f' % (1.0*xsize,1.0*ysize) ) | |
| 283 | − f('set key spacing 1.3') | |
| 284 | − f('set multiplot') | |
| 285 | − | |
| 286 | − f('set size %f,%f' % (1.0*xsize,0.33*ysize) ) | |
| 287 | − f('set orig %f,%f' % (0.0*xsize,0.66*ysize) ) | |
| 288 | − f('set xrange [%f:%f]' % (-winlen,0) ) | |
| 289 | − f.title('Onset detection function') | |
| 290 | − f.xlabel('time (df samples)') | |
| 291 | − f.plot(*d[0]) | |
| 292 | − f('set size %f,%f' % (0.5*xsize,0.33*ysize) ) | |
| 293 | − f('set orig %f,%f' % (0.0*xsize,0.33*ysize) ) | |
| 294 | − f('set xrange [%f:%f]' % (0,laglen) ) | |
| 295 | − f.title('Period detection: Rayleygh weighting') | |
| 296 | − f.xlabel('lag (df samples)') | |
| 297 | − f.plot(*d[1]) | |
| 298 | − f('set size %f,%f' % (0.5*xsize,0.33*ysize) ) | |
| 299 | − f('set orig %f,%f' % (0.5*xsize,0.33*ysize) ) | |
| 300 | − f('set xrange [%f:%f]' % (0,laglen) ) | |
| 301 | − f.title('Period detection: Gaussian weighting') | |
| 302 | − f.xlabel('lag (df samples)') | |
| 303 | − f.plot(*d[2]) | |
| 304 | − f('set size %f,%f' % (1.0*xsize,0.33*ysize) ) | |
| 305 | − f('set orig %f,%f' % (0.0*xsize,0.00*ysize) ) | |
| 306 | − f('set xrange [%f:%f]' % (-laglen,laglen) ) | |
| 307 | − f.title('Phase detection and predicted beats') | |
| 308 | − f.xlabel('time (df samples)') | |
| 309 | − f.plot(*d[3]) | |
| 310 | − f('set nomultiplot') | |
| 311 | − if printframe == -1: a = sys.stdin.read() | |
| 312 | − elif 0 < printframe and printframe < nrframe: | |
| 313 | − break | |
| @@ -1,157 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −""" this file was written by Paul Brossier | |
| 4 | − it is released under the GNU/GPL license. | |
| 5 | −""" | |
| 6 | − | |
| 7 | −import sys,time | |
| 8 | −from aubio.task import taskbeat,taskparams | |
| 9 | −from aubio.aubioclass import fvec, aubio_autocorr | |
| 10 | −from aubio.gnuplot import gnuplot_create, gnuplot_addargs | |
| 11 | −from aubio.aubiowrapper import * | |
| 12 | −from math import exp,log | |
| 13 | − | |
| 14 | −usage = "usage: %s [options] -i soundfile" % sys.argv[0] | |
| 15 | − | |
| 16 | −def parse_args(): | |
| 17 | − from optparse import OptionParser | |
| 18 | − parser = OptionParser(usage=usage) | |
| 19 | − parser.add_option("-i","--input", | |
| 20 | − action="store", dest="filename", | |
| 21 | − help="input sound file") | |
| 22 | − parser.add_option("-n","--printframe", | |
| 23 | − action="store", dest="printframe", default=-1, | |
| 24 | − help="make a plot of the n_th frame") | |
| 25 | − gnuplot_addargs(parser) | |
| 26 | − (options, args) = parser.parse_args() | |
| 27 | − if not options.filename: | |
| 28 | − print "no file name given\n", usage | |
| 29 | − sys.exit(1) | |
| 30 | − return options, args | |
| 31 | − | |
| 32 | −def plotdata(x,y,plottitle="",**keyw): | |
| 33 | − import Gnuplot | |
| 34 | − return Gnuplot.Data(x, y, title="%s" % plottitle,**keyw) | |
| 35 | − | |
| 36 | −options, args = parse_args() | |
| 37 | −filename = options.filename | |
| 38 | −xsize = float(options.xsize) | |
| 39 | −ysize = float(options.ysize) | |
| 40 | − | |
| 41 | −printframe = int(options.printframe) | |
| 42 | − | |
| 43 | −if options.outplot and printframe > 0: | |
| 44 | − extension = options.outplot.split('.')[-1] | |
| 45 | − outplot = '.'.join(options.outplot.split('.')[:-1]) | |
| 46 | −else: | |
| 47 | − extension = '' | |
| 48 | − outplot = None | |
| 49 | −f = gnuplot_create(outplot,extension,options) | |
| 50 | − | |
| 51 | −params = taskparams() | |
| 52 | −params.onsetmode = 'specdiff' | |
| 53 | −task = taskbeat(filename,params=params) | |
| 54 | − | |
| 55 | −hopsize = params.hopsize | |
| 56 | −bufsize = params.bufsize | |
| 57 | −btstep = task.btstep | |
| 58 | −winlen = task.btwinlen | |
| 59 | −laglen = winlen/4 | |
| 60 | −step = winlen/4 | |
| 61 | − | |
| 62 | −timesig = 0 | |
| 63 | −maxnumelem = 4 | |
| 64 | −gp = 0 | |
| 65 | −counter = 0 | |
| 66 | −flagconst = 0 | |
| 67 | −constthresh = 3.901 | |
| 68 | −g_var = 3.901 | |
| 69 | −rp = 0 | |
| 70 | −rp1 = 0 | |
| 71 | −rp2 = 0 | |
| 72 | −g_mu = 0 | |
| 73 | − | |
| 74 | −rayparam = 48/512.*winlen | |
| 75 | − | |
| 76 | −t = [i for i in range(hopsize)] | |
| 77 | −#tlong = [i for i in range(hopsize*(btstep-1))] | |
| 78 | −#tall = [i for i in range(hopsize*btstep)] | |
| 79 | −sig = [0 for i in range(hopsize*btstep*4)] | |
| 80 | −dfx = [i for i in range(winlen)] | |
| 81 | −dfframe = [0 for i in range(winlen)] | |
| 82 | −dfrev = [0 for i in range(winlen)] | |
| 83 | −acframe = [0 for i in range(winlen/2)] | |
| 84 | − | |
| 85 | −localacf = [0 for i in range(winlen)] | |
| 86 | −inds = [0 for i in range(maxnumelem)] | |
| 87 | − | |
| 88 | −acx = [i for i in range(laglen)] | |
| 89 | −acfout = [0 for i in range(laglen)] | |
| 90 | − | |
| 91 | −phwv = [0 for i in range(2*laglen)] | |
| 92 | −phwvx = [i for i in range(2*laglen)] | |
| 93 | − | |
| 94 | −dfwvnorm = exp(log(2.0)*(winlen+2.)/rayparam); | |
| 95 | −dfwv = [exp(log(2.)*(i+1.)/rayparam)/dfwvnorm for i in range(winlen)] | |
| 96 | − | |
| 97 | −gwv = [exp(-.5*(j+1.-g_mu)**2/g_var**2) for j in range(laglen)] | |
| 98 | −rwv = [(i+1.)/rayparam**2 * exp(-(i+1.)**2 / (2.*rayparam)**2) | |
| 99 | − for i in range(0,laglen)] | |
| 100 | −acf = fvec(winlen,1) | |
| 101 | − | |
| 102 | −nrframe = 0 | |
| 103 | −while (task.readsize == params.hopsize): | |
| 104 | − task() | |
| 105 | − #print task.pos2 | |
| 106 | − sig[:-hopsize] = [i for i in sig[-(btstep*4-1)*hopsize:]] | |
| 107 | − sig[-hopsize:] = [task.myvec.get(i,0) for i in t] | |
| 108 | − | |
| 109 | − #g('set xrange [%f:%f]' % (t[0],t[-1])) | |
| 110 | − #time.sleep(.2) | |
| 111 | − if task.pos2==btstep-1: | |
| 112 | − nrframe += 1 | |
| 113 | − dfframe = [task.dfframe.get(i,0) for i in range(winlen)] | |
| 114 | − # start beattracking_do | |
| 115 | − for i in range(winlen): | |
| 116 | − dfrev[winlen-1-i] = 0. | |
| 117 | − dfrev[winlen-1-i] = dfframe[i]*dfwv[i] | |
| 118 | − aubio_autocorr(task.dfframe(),acf()); | |
| 119 | − acframe = [acf.get(i,0) for i in range(winlen/2)] | |
| 120 | − if printframe == nrframe or printframe == -1: | |
| 121 | − d = [[plotdata(range(0,btstep*hopsize*4,4),sig[0:-1:4],plottitle="input signal", with='lines')]] | |
| 122 | − d += [[plotdata(range(-winlen,0),dfframe,plottitle="onset detection", with='lines')]] | |
| 123 | − d += [[plotdata(range(winlen/2),acframe,plottitle="autocorrelation", with='lines')]] | |
| 124 | − | |
| 125 | − # plot all this | |
| 126 | − if printframe == nrframe or printframe == -1: | |
| 127 | − | |
| 128 | − f('set lmargin 4') | |
| 129 | − f('set rmargin 4') | |
| 130 | − f('set size %f,%f' % (1.0*xsize,1.0*ysize) ) | |
| 131 | − f('set key spacing 1.3') | |
| 132 | − f('set multiplot') | |
| 133 | − | |
| 134 | − f('set size %f,%f' % (1.0*xsize,0.33*ysize) ) | |
| 135 | − f('set orig %f,%f' % (0.0*xsize,0.66*ysize) ) | |
| 136 | − f('set xrange [%f:%f]' % (0,btstep*hopsize*4) ) | |
| 137 | − f('set yrange [%f:%f]' % (-1.2*max(sig),1.2*max(sig)) ) | |
| 138 | − f.title('Input signal') | |
| 139 | − f.xlabel('time (samples)') | |
| 140 | − f.plot(*d[0]) | |
| 141 | − f('set size %f,%f' % (1.0*xsize,0.33*ysize) ) | |
| 142 | − f('set orig %f,%f' % (0.0*xsize,0.33*ysize) ) | |
| 143 | − f('set xrange [%f:%f]' % (-winlen,0) ) | |
| 144 | − f('set autoscale y') | |
| 145 | − f.title('Onset detection function') | |
| 146 | − f.xlabel('time (df samples)') | |
| 147 | − f.plot(*d[1]) | |
| 148 | − f('set size %f,%f' % (1.0*xsize,0.33*ysize) ) | |
| 149 | − f('set orig %f,%f' % (0.0*xsize,0.00*ysize) ) | |
| 150 | − f('set xrange [%f:%f]' % (0,winlen/2) ) | |
| 151 | − f.title('Autocorrelation') | |
| 152 | − f.xlabel('lag (df samples)') | |
| 153 | − f.plot(*d[2]) | |
| 154 | − f('set nomultiplot') | |
| 155 | − if printframe == -1: a = sys.stdin.read() | |
| 156 | − elif 0 < printframe and printframe < nrframe: | |
| 157 | − break | |
| @@ -1,51 +0,0 @@ | ||
| 1 | −import unittest | |
| 2 | − | |
| 3 | −from aubio.aubiowrapper import * | |
| 4 | − | |
| 5 | −buf_size = 2048 | |
| 6 | −channels = 3 | |
| 7 | − | |
| 8 | −class cvec_test_case(unittest.TestCase): | |
| 9 | − | |
| 10 | − def setUp(self): | |
| 11 | − self.vector = new_cvec(buf_size, channels) | |
| 12 | − | |
| 13 | − def tearDown(self): | |
| 14 | − del_cvec(self.vector) | |
| 15 | − | |
| 16 | − def test_cvec(self): | |
| 17 | − """ create and delete cvec """ | |
| 18 | − pass | |
| 19 | − | |
| 20 | − def test_cvec_read_norm(self): | |
| 21 | − """ check new cvec norm elements are set to 0. """ | |
| 22 | − for index in range(buf_size/2+1): | |
| 23 | − for channel in range(channels): | |
| 24 | − self.assertEqual(cvec_read_norm(self.vector,channel,index),0.) | |
| 25 | − | |
| 26 | − def test_cvec_read_phas(self): | |
| 27 | − """ check new cvec phas elements are set to 0. """ | |
| 28 | − for index in range(buf_size/2+1): | |
| 29 | − for channel in range(channels): | |
| 30 | − self.assertEqual(cvec_read_phas(self.vector,channel,index),0.) | |
| 31 | − | |
| 32 | − def test_cvec_write_norm(self): | |
| 33 | − """ check new cvec norm elements are set with cvec_write_norm """ | |
| 34 | − for index in range(buf_size/2+1): | |
| 35 | − for channel in range(channels): | |
| 36 | − cvec_write_norm(self.vector,1.,channel,index) | |
| 37 | − for index in range(buf_size/2+1): | |
| 38 | − for channel in range(channels): | |
| 39 | − self.assertEqual(cvec_read_norm(self.vector,channel,index),1.) | |
| 40 | − | |
| 41 | − def test_cvec_write_phas(self): | |
| 42 | − """ check new cvec phas elements are set with cvec_write_phas """ | |
| 43 | − for index in range(buf_size/2+1): | |
| 44 | − for channel in range(channels): | |
| 45 | − cvec_write_phas(self.vector,1.,channel,index) | |
| 46 | − for index in range(buf_size/2+1): | |
| 47 | − for channel in range(channels): | |
| 48 | − self.assertEqual(cvec_read_phas(self.vector,channel,index),1.) | |
| 49 | − | |
| 50 | −if __name__ == '__main__': | |
| 51 | − unittest.main() | |
| @@ -1,36 +0,0 @@ | ||
| 1 | −import unittest | |
| 2 | − | |
| 3 | −from aubio.aubiowrapper import * | |
| 4 | − | |
| 5 | −buf_size = 2048 | |
| 6 | −channels = 3 | |
| 7 | − | |
| 8 | −class fvec_test_case(unittest.TestCase): | |
| 9 | − | |
| 10 | − def setUp(self): | |
| 11 | − self.vector = new_fvec(buf_size, channels) | |
| 12 | − | |
| 13 | − def tearDown(self): | |
| 14 | − del_fvec(self.vector) | |
| 15 | − | |
| 16 | − def test_fvec(self): | |
| 17 | − """ create and delete fvec """ | |
| 18 | − pass | |
| 19 | − | |
| 20 | − def test_fvec_read_sample(self): | |
| 21 | − """ check new fvec elements are set to 0. """ | |
| 22 | − for index in range(buf_size): | |
| 23 | − for channel in range(channels): | |
| 24 | − self.assertEqual(fvec_read_sample(self.vector,channel,index),0.) | |
| 25 | − | |
| 26 | − def test_fvec_write_sample(self): | |
| 27 | − """ check new fvec elements are set with fvec_write_sample """ | |
| 28 | − for index in range(buf_size): | |
| 29 | − for channel in range(channels): | |
| 30 | − fvec_write_sample(self.vector,1.,channel,index) | |
| 31 | − for index in range(buf_size): | |
| 32 | − for channel in range(channels): | |
| 33 | − self.assertEqual(fvec_read_sample(self.vector,channel,index),1.) | |
| 34 | − | |
| 35 | −if __name__ == '__main__': | |
| 36 | − unittest.main() | |
| @@ -1,30 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −from glob import glob | |
| 4 | −from os.path import splitext, exists | |
| 5 | −import sys | |
| 6 | − | |
| 7 | −if len(sys.argv) > 1: verbose = True | |
| 8 | −else: verbose = False | |
| 9 | − | |
| 10 | −cfiles = [ file.split('/')[-1] for file in glob('../../src/*.c') ] | |
| 11 | −cfiles.sort() | |
| 12 | − | |
| 13 | −for cfile in cfiles: | |
| 14 | − pythonfile=splitext(cfile)[0]+'.py' | |
| 15 | − if not exists(pythonfile): | |
| 16 | − print "[X] %30s" % cfile, "[ ] %30s" % pythonfile | |
| 17 | − #print cfile, "has NO test", pythonfile | |
| 18 | − elif verbose: | |
| 19 | − print "[X] %30s" % cfile, "[X] %30s" % pythonfile | |
| 20 | − | |
| 21 | −pythonfiles = [ file.split('/')[-1] for file in glob('*.py') ] | |
| 22 | −pythonfiles.sort() | |
| 23 | − | |
| 24 | −for pythonfile in pythonfiles: | |
| 25 | − cfile=splitext(pythonfile)[0]+'.c' | |
| 26 | − if not exists('../../'+cfile): | |
| 27 | − print "[ ] %30s" % cfile, "[X] %30s" % pythonfile | |
| 28 | − #print pythonfile, "has NO source", cfile | |
| 29 | − elif verbose: | |
| 30 | − print "[X] %30s" % cfile, "[X] %30s" % pythonfile | |
| @@ -1,15 +0,0 @@ | ||
| 1 | −#! /usr/bin/python | |
| 2 | − | |
| 3 | −# add ${src}/python and ${src}/python/aubio/.libs to python path | |
| 4 | −# so the script is runnable from a compiled source tree. | |
| 5 | −import sys, os | |
| 6 | −sys.path.append('..') | |
| 7 | −sys.path.append(os.path.join('..','aubio','.libs')) | |
| 8 | − | |
| 9 | −import unittest | |
| 10 | − | |
| 11 | −modules_to_test = ['aubiomodule', 'fvec', 'cvec'] | |
| 12 | − | |
| 13 | −if __name__ == '__main__': | |
| 14 | − for module in modules_to_test: exec('from %s import *' % module) | |
| 15 | − unittest.main() | |