def ImpulseTrain(self, frameSize, factor, precision): nFrames = 16 inputData = [0]*nFrames*frameSize pos = factor*frameSize # after the first frame,every factor frames there will be an impulse of # type 1, 0.8, 0.6, 0.4, 0.2 for i in xrange(len(inputData)): mod = i%pos if i > frameSize and mod < 5: inputData[i] = 0.5*(5-mod)/2.5 # impulse: 1, 0.8, 0.6, 0.4, 0.2 size = int(nFrames/factor); expected = [0]*size for i in xrange(size): expected[i] = factor*(i+1)*frameSize/44100 gen = VectorInput(inputData) onsetRate = OnsetRate() p = Pool() gen.data >> onsetRate.signal onsetRate.onsetTimes >> (p, 'onset.times') onsetRate.onsetRate >> (p, 'onset.rate') run(gen) self.assertAlmostEqual(p['onset.rate'], len(expected)/(float(len(inputData))/44100.0), 0.05) self.assertAlmostEqualVector(p['onset.times'], expected, precision)
def testEmpty(self): gen = VectorInput([]) sor = OnsetRate() p = Pool() gen.data >> sor.signal sor.onsetTimes >> (p, 'data') sor.onsetRate >> (p, 'onset.rate') run(gen) self.assertEqual(len(p.descriptorNames()), 0)
def testZero(self): gen = VectorInput( [0]*10*1024 ) sor = OnsetRate() p = Pool() gen.data >> sor.signal sor.onsetTimes >> (p, 'onset.times') sor.onsetRate >> (p, 'onset.rate') run(gen) self.assertEqual(p['onset.rate'], 0)
def run(self): global frame_g while not self.stoprequest.isSet(): pool = essentia.Pool() self.frame_q.get() v_in2 = VectorInput(frame_g) onset = OnsetRate() v_in2.data >> onset.signal onset.onsetRate >> (pool, 'Rhythm.onsetRate') onset.onsetTimes >> None essentia.run(v_in2) self.result_q.put(pool)