Mercurial > hg > vampy
view Example VamPy plugins/PyZeroCrossing.py @ 1:dc88002ce687
some typos corrected
author | fazekasgy |
---|---|
date | Tue, 11 Mar 2008 20:24:58 +0000 |
parents | e20e214bdfb5 |
children | e1b508f2f914 |
line wrap: on
line source
'''PyZeroCrossing.py - Example plugin demonstrates''' '''how to call a python class using the VamPy VAMP plugin''' #from time import * #import sys class PyZeroCrossing: def __init__(self): self.m_imputSampleRate = 44100 self.m_stepSize = 0 self.m_blockSize = 0 self.m_channels = 0 self.previousSample = 0.0 self.threshold = 0.05 def initialise(self,channels,stepSize,blockSize,inputSampleRate): self.m_channels = channels self.m_stepSize = stepSize self.m_blockSize = blockSize self.m_inputSampleRate = inputSampleRate return True def getMaker(self): return 'VamPy Example Plugins' def getName(self): return 'Zero Crossing (VamPy)' def getIdentifier(self): return 'python-zc' def getMaxChannelCount(self): return 1 def getInputDomain(self): return 'TimeDomain' def getOutputDescriptors(self): #descriptors are python dictionary output0={ 'identifier':'vampy-counts', 'name':'Number of Zero Crossings', 'description':'Number of zero crossings per audio frame', 'unit':' ', 'hasFixedBinCount':True, 'binCount':1, #'binNames':['1 Hz',1.5,'2 Hz',3,'4 Hz'], 'hasKnownExtents':False, #'minValue':0.0, #'maxValue':0.0, 'isQuantized':True, 'quantizeStep':1.0, 'sampleType':'OneSamplePerStep' #'sampleRate':48000.0 } output1={ 'identifier':'vampy-crossings', 'name':'Zero Crossing Locations', 'description':'The locations of zero crossing points', 'unit':'discrete', 'hasFixedBinCount':True, 'binCount':0, 'sampleType':'VariableSampleRate' #'sampleRate':48000.0 } #return a list of dictionaries return [output0,output1] def getParameterDescriptors(self): paramlist1={ 'identifier':'threshold', 'name':'Noise threshold: ', 'description':'Return null or delete this function if not needed.', 'unit':'v', 'minValue':0.0, 'maxValue':0.5, 'defaultValue':0.05, 'isQuantized':False } return [paramlist1] def setParameter(self,paramid,newval): if paramid == 'threshold' : self.threshold = newval return def getParameter(self,paramid): if paramid == 'threshold' : return self.threshold else: return 0.0 def process(self,inbuf): crossing = False prev = self.previousSample count = 0.0; #we have two outputs defined thus we have to declare #them as empty dictionaries in our output list #in order to be able to return variable rate outputs output0=[] output1=[] if abs(sum(inbuf)) > self.threshold : for x in range(len(inbuf)-1) : crossing = False sample = inbuf[x] if sample <= 0.0 : if prev > 0.0 : crossing = True else : if sample > 0.0 : if prev <= 0.0 : crossing = True if crossing == True : count = count + 1 feature1={ 'hasTimestamp':True, #for now return sample position and convert to RealTime in C code 'timeStamp':x #'values':[count] #'label':label } output1.append(feature1) prev = sample self.previousSample = prev else : count = 0.0 self.previousSample = inbuf[len(inbuf)-2] feature0={ 'hasTimestamp':False, 'values':[count], #strictly must be a list 'label':str(count) } output0.append(feature0) #return a LIST of list of dictionaries return [output0,output1]