History

update task.pitch.{eval,plot} update task.pitch.{eval,plot}

Paul Brossier committed 20 years ago

Commit 83376e91 parent 9610f0a1 file · +29 −12Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/aubio/task/pitch.py+29−12
@@ -12,7 +12,8 @@ class taskpitch(task): · 11 unmodified lines
12 hopsize=self.params.hopsize,12 hopsize=self.params.hopsize,
13 channels=self.channels,13 channels=self.channels,
14 samplerate=self.srate,14 samplerate=self.srate,
15 omode=self.params.omode)15 omode=self.params.omode,
16 yinthresh=self.params.yinthresh)
16 17
17 def __call__(self):18 def __call__(self):
18 from aubio.median import short_find19 from aubio.median import short_find
@@ -83,7 +84,10 @@ class taskpitch(task): · 64 unmodified lines
83 time, pitch = [], []84 time, pitch = [], []
84 for i in range(len(values)):85 for i in range(len(values)):
85 time.append(values[i][0])86 time.append(values[i][0])
86 pitch.append(aubio_freqtomidi(values[i][1]))87 if values[i][1] == 0.0:
88 pitch.append(-1.)
89 else:
90 pitch.append(aubio_freqtomidi(values[i][1]))
87 return time,pitch91 return time,pitch
88 92
89 def oldeval(self,results):93 def oldeval(self,results):
@@ -104,20 +108,29 @@ class taskpitch(task): · 14 unmodified lines
104 med = percental(res,len(res)/2) 108 med = percental(res,len(res)/2)
105 return self.truth, self.truth-med, self.truth-avg109 return self.truth, self.truth-med, self.truth-avg
106 110
107 def eval(self,pitch,tol=0.9):111 def eval(self,pitch,tol=0.5):
108 timet,pitcht = self.gettruth()112 timet,pitcht = self.gettruth()
109 pitch = [aubio_freqtomidi(i) for i in pitch]113 pitch = [aubio_freqtomidi(i) for i in pitch]
110 for i in range(len(pitch)):114 for i in range(len(pitch)):
111 if pitch[i] == "nan" or pitch[i] == -1:115 if pitch[i] == "nan" or pitch[i] == -1:
112 pitch[i] = -1116 pitch[i] = -1
113 time = [ i*self.params.step for i in range(len(pitch)) ]117 time = [ i*self.params.step for i in range(len(pitch)) ]
114 assert len(timet) == len(time) 118 #print len(timet),len(pitcht)
119 #print len(time),len(pitch)
120 if len(timet) != len(time):
121 time = time[1:len(timet)+1]
122 pitch = pitch[1:len(pitcht)+1]
123 #pitcht = [aubio_freqtomidi(i) for i in pitcht]
124 for i in range(len(pitcht)):
125 if pitcht[i] == "nan" or pitcht[i] == "-inf" or pitcht[i] == -1:
126 pitcht[i] = -1
127 assert len(timet) == len(time)
115 assert len(pitcht) == len(pitch)128 assert len(pitcht) == len(pitch)
116 osil, esil, opit, epit, echr = 0, 0, 0, 0, 0129 osil, esil, opit, epit, echr = 0, 0, 0, 0, 0
117 for i in range(len(pitcht)):130 for i in range(len(pitcht)):
118 if pitcht[i] == -1: # currently silent131 if pitcht[i] == -1: # currently silent
119 osil += 1 # count a silence132 osil += 1 # count a silence
120 if pitch[i] == -1. or pitch[i] == "nan": 133 if pitch[i] <= 0. or pitch[i] == "nan":
121 esil += 1 # found a silence134 esil += 1 # found a silence
122 else:135 else:
123 opit +=1136 opit +=1
@@ -137,11 +150,12 @@ class taskpitch(task): · 13 unmodified lines
137 import Gnuplot150 import Gnuplot
138 151
139 downtime = self.params.step*numarray.arange(len(pitch))152 downtime = self.params.step*numarray.arange(len(pitch))
140 oplots.append(Gnuplot.Data(downtime,pitch,with='linespoints',153 pitch = [aubio_freqtomidi(i) for i in pitch]
154 oplots.append(Gnuplot.Data(downtime,pitch,with='lines',
141 title=self.params.pitchmode))155 title=self.params.pitchmode))
142 156
143 157
144 def plotplot(self,wplot,oplots,outplot=None,multiplot = 0):158 def plotplot(self,wplot,oplots,outplot=None,multiplot = 1, midi = 1):
145 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot159 from aubio.gnuplot import gnuplot_init, audio_to_array, make_audio_plot
146 import re160 import re
147 import Gnuplot161 import Gnuplot
@@ -152,7 +166,6 @@ class taskpitch(task): · 4 unmodified lines
152 # check if ground truth exists166 # check if ground truth exists
153 timet,pitcht = self.gettruth()167 timet,pitcht = self.gettruth()
154 if timet and pitcht:168 if timet and pitcht:
155 pitcht = [aubio_miditofreq(i) for i in pitcht]
156 oplots = [Gnuplot.Data(timet,pitcht,with='lines',169 oplots = [Gnuplot.Data(timet,pitcht,with='lines',
157 title='ground truth')] + oplots170 title='ground truth')] + oplots
158 171
@@ -177,13 +190,17 @@ class taskpitch(task): · 18 unmodified lines
177 g('set size 1,0.7')190 g('set size 1,0.7')
178 g('set origin 0,0')191 g('set origin 0,0')
179 g('set xrange [0:%f]' % max(time))192 g('set xrange [0:%f]' % max(time))
180 g('set yrange [100:%f]' % self.params.pitchmax) 193 if not midi:
194 g('set log y')
195 #g.xlabel('time (s)')
196 g.ylabel('f0 (Hz)')
197 g('set yrange [100:%f]' % self.params.pitchmax)
198 else:
199 g.ylabel('pitch (midi)')
200 g('set yrange [%f:%f]' % (40, aubio_freqtomidi(self.params.pitchmax)))
181 g('set key right top')201 g('set key right top')
182 g('set noclip one') 202 g('set noclip one')
183 g('set format x ""')203 g('set format x ""')
184 g('set log y')
185 #g.xlabel('time (s)')
186 g.ylabel('f0 (Hz)')
187 if multiplot:204 if multiplot:
188 for i in range(len(oplots)):205 for i in range(len(oplots)):
189 # plot onset detection functions206 # plot onset detection functions

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t