#main def calculate(self): threshold = 0.15 self.performance = audionset.AudioPiece(WAVE_OUTPUT_FILENAME, threshold) while self.performance.onset_count != self.usultemplate.onset_count: if self.performance.onset_count < self.usultemplate.onset_count: print("Decrease threshold.", threshold) if threshold - 0.02 <= 0: print("Signal not good.") break else: threshold -= 0.02 else: print("Increase threshold.", threshold) threshold += 0.035 q = Queue.Queue() tt = threading.Thread(target=audionset.AudioPiece, args=[WAVE_OUTPUT_FILENAME, threshold, q]) tt.start() tt.join() self.performance = q.get() print(self.performance.onset_count, self.usultemplate.onset_count) self.performance.stretchtimes(self.usultemplate) print(self.performance.stretched_onset_times) print(self.usultemplate.onset_times) score = self.performance.compare(self.usultemplate, self.checkbox_stretch.isChecked()) #HERE IS THE COMPARISON ----------------- #audionset class @staticmethod def similarityscore(difflist, bpm): diffrange = 60/bpm #time for 1/4th beat scorelist = [] for diff_ in difflist: diff = abs(diff_) if diff < diffrange/32: #128th scorelist.append(1) elif diff < diffrange/16: #64th scorelist.append(0.9) elif diff < diffrange/8: #32th scorelist.append(0.8) elif diff < diffrange/4: #16th scorelist.append(0.3) elif diff < diffrange/2: #4th scorelist.append(0.2) else: scorelist.append(0.1) print(scorelist) score = float(sum(scorelist[1:-1]))/(len(scorelist)-2) print(score) return score def compare(self, other, stretch): difflist = [] if stretch == 1: print("Time align: ", stretch) self.final_onset_signal = self.stretched_onset_signal self.final_onset_times = self.stretched_onset_times else: print("Time align: ", stretch) self.final_onset_signal = self.shifted_onset_signal self.final_onset_times = self.shifted_onset_times for i in range(0, other.onset_count): difflist.append(other.onset_times[i] - self.final_onset_times[i]) print("Difflist:") print(difflist) return self.similarityscore(difflist, other.onset_bpm)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question