def onset(self, **options): onsetAlgorithm = options.get("onsetAlgorithm") or "default" onsetThreshold = options.get("onsetThreshold") or -90 sourceBuffer = source(self.audioFilename, self.samplerate, self.hopSize) onsetSampler = aubio_onset(onsetAlgorithm, self.fftWindowSize, self.hopSize, self.samplerate) # onsetSampler = aubio_level_detection(-70) # list of onsets, in samples onsets = [] timings = [] frames = [] # total number of frames read totalFrames = 0 while True: samples, read = sourceBuffer() if onsetSampler(samples): # print "%f" % onsetSampler.get_last_s() timings.append(onsetSampler.get_last_s()) frames += [totalFrames] onsets.append(onsetSampler.get_last()) totalFrames += read if read < self.hopSize: break return { "timings": timings, "frames": frames, "onsets": onsets }
def notes(self, **options): onsetAlgorithm = options.get("onsetAlgorithm") or "default" algorithm = options.get("algorithm") or "yinfft" pitchUnit = options.get("pitchUnit") or "freq" tolerance = options.get("tolerance") or 0.85 sourceBuffer = source(self.audioFilename, self.samplerate, self.hopSize) onsetSampler = aubio_onset(onsetAlgorithm, self.fftWindowSize, self.hopSize, self.samplerate) pitchSampler = aubio_pitch(algorithm, self.fftWindowSize * 4, self.hopSize, self.samplerate) pitchSampler.set_unit(pitchUnit) pitchSampler.set_tolerance(tolerance) median = 6 isReady = 0 note_buffer = [] timeStarts = [] timeStops = [] frameStarts = [] frameStops = [] pitches = [] confidences = [] isOn = False totalFrames = 0 while True: samples, read = sourceBuffer() new_pitch = pitchSampler(samples)[0] curlevel = aubio_level_detection(samples, -90) note_buffer.insert(0, new_pitch) if len(note_buffer) > median: note_buffer.pop() if onsetSampler(samples): if curlevel == 1.: isReady = 0 else: isReady = 1 else: if isReady > 0: isReady += 1 if isReady == median: new_note = self.pseudo_median(note_buffer) if isOn: timeStops += [float(totalFrames) / self.samplerate] frameStops += [totalFrames] isOn = False if new_note > 45: confidence = pitchSampler.get_confidence() timeStarts += [float(totalFrames) / self.samplerate] frameStarts += [totalFrames] pitches += [new_note] confidences += [confidence] isOn = True totalFrames += read if read < self.hopSize: break if len(frameStops) < len(frameStarts): frameStops += [totalFrames] if len(timeStops) < len(timeStarts): timeStops += [timeStops] # timeStops += [timeStops] return { "timeStarts": timeStarts, "timeStops": timeStops, "frameStarts": frameStarts, "frameStops": frameStops, "pitches": pitches, "confidences": confidences }