changeset 68:44d56a3d16b7

Various fixes to the example plugins
author Chris Cannam
date Mon, 17 Nov 2014 11:44:15 +0000
parents 146d14ab15e7
children f5b8646494d2
files Example VamPy plugins/PyMFCC.py Example VamPy plugins/PySpectralCentroid.py Example VamPy plugins/PySpectralFeatures.py Example VamPy plugins/PyZeroCrossing.py Example VamPy plugins/examples.cat
diffstat 5 files changed, 31 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Example VamPy plugins/PyMFCC.py	Mon Nov 17 10:03:44 2014 +0000
+++ b/Example VamPy plugins/PyMFCC.py	Mon Nov 17 11:44:15 2014 +0000
@@ -39,29 +39,34 @@
 		self.sampleRate = sampleRate
 		self.NqHz = sampleRate / 2.0
 		self.minHz = minHz
-		if maxHz is None : maxHz = self.NqHz
+		if maxHz is None : maxHz = 11025
 		self.maxHz = maxHz
 		self.inputSize = inputSize
 		self.numBands = numBands
 		self.valid = False
 		self.updated = False
 		
+	def reset(self):
+		# reset any initial conditions
+                self.updated = False
+		return None
+		
 	def update(self): 
 		# make sure this will run only once 
 		# if called from a vamp process
 		if self.updated: return self.valid
 		self.updated = True
 		self.valid = False
-#		print 'Updating parameters and recalculating filters: '
-#		print 'Nyquist: ',self.NqHz
-		
-		if self.maxHz > self.NqHz : 
-			raise Exception('Maximum frequency must be smaller than the Nyquist frequency')
-		
-		self.maxMel = 1000*log(1+self.maxHz/700.0)/log(1+1000.0/700.0)
-		self.minMel = 1000*log(1+self.minHz/700.0)/log(1+1000.0/700.0)
-#		print 'minHz:%s\nmaxHz:%s\nminMel:%s\nmaxMel:%s\n' \
-#		%(self.minHz,self.maxHz,self.minMel,self.maxMel)
+                # print 'Updating parameters and recalculating filters: '
+                # print 'Nyquist: ',self.NqHz
+                maxHz = self.maxHz
+		if maxHz > self.NqHz : maxHz = self.NqHz
+		minHz = self.minHz
+                if minHz > self.NqHz : minHz = self.NqHz
+		self.maxMel = 1000*log(1+maxHz/700.0)/log(1+1000.0/700.0)
+		self.minMel = 1000*log(1+minHz/700.0)/log(1+1000.0/700.0)
+                # print 'minHz:%s\nmaxHz:%s\nminMel:%s\nmaxMel:%s\n' \
+                # %(self.minHz,self.maxHz,self.minMel,self.maxMel)
 		self.filterMatrix = self.getFilterMatrix(self.inputSize,self.numBands)
 		self.DCTMatrix = self.getDCTMatrix(self.numBands)
 		self.filterIter = self.filterMatrix.__iter__()
@@ -114,9 +119,10 @@
 		
 	def getMFCCs(self,warpedSpectrum,cn=True):
 		'''Compute MFCC coefficients from Mel warped magnitude spectrum.'''
-		mfccs=self.dct(numpy.log(warpedSpectrum))
-		if cn is False : mfccs[0] = 0.0
-		return mfccs
+                eps = 1e-8
+                mfccs=self.dct(numpy.log(warpedSpectrum + eps))
+                if cn is False : mfccs[0] = 0.0
+                return mfccs
 	
 
 class PyMFCC(melScaling): 
@@ -272,13 +278,9 @@
 	def setParameter(self,paramid,newval):
 		self.valid = False
 		if paramid == 'minHz' :
-			if newval < self.maxHz and newval < self.NqHz :
-				self.minHz = float(newval)
+                        self.minHz = float(newval)
 		if paramid == 'maxHz' :
-			if newval < self.NqHz and newval > self.minHz+1000 :
-				self.maxHz = float(newval)
-			else :
-				self.maxHz = self.NqHz
+                        self.maxHz = float(newval)
 		if paramid == 'cnull' :
 			self.cnull = int(not int(newval))
 		if paramid == 'melbands' :
--- a/Example VamPy plugins/PySpectralCentroid.py	Mon Nov 17 10:03:44 2014 +0000
+++ b/Example VamPy plugins/PySpectralCentroid.py	Mon Nov 17 11:44:15 2014 +0000
@@ -41,7 +41,7 @@
 		self.m_channels = 0
 		self.previousSample = 0.0
 		self.m_inputSampleRate = inputSampleRate
-		self.threshold = 0.00
+		self.threshold = 0.05
 		
 	def initialise(self,channels,stepSize,blockSize):
 		self.m_channels = channels
@@ -83,7 +83,7 @@
 		thd = ParameterDescriptor()
 		thd.identifier='threshold'
 		thd.name='Noise threshold'
-		thd.description='Return null or delete this function if not needed.'
+		thd.description='Magnitude below which a process block will be disregarded and zero returned'
 		thd.unit='v'
 		thd.minValue=0.0
 		thd.maxValue=0.5
--- a/Example VamPy plugins/PySpectralFeatures.py	Mon Nov 17 10:03:44 2014 +0000
+++ b/Example VamPy plugins/PySpectralFeatures.py	Mon Nov 17 11:44:15 2014 +0000
@@ -40,7 +40,7 @@
 		
 	def reset(self):
 		# reset any initial conditions
-		self.prevMag = zeros((blockSize/2))
+		self.prevMag = zeros((self.m_blockSize/2))
 		return None
 	
 	def getMaker(self):
@@ -102,7 +102,7 @@
 		threshold = ParameterDescriptor()
 		threshold.identifier='threshold'
 		threshold.name='Noise threshold'
-		threshold.description='Noise threshold'
+		threshold.description='Magnitude below which a process block will be disregarded and zeroes returned'
 		threshold.unit='v'
 		threshold.minValue=0
 		threshold.maxValue=1
--- a/Example VamPy plugins/PyZeroCrossing.py	Mon Nov 17 10:03:44 2014 +0000
+++ b/Example VamPy plugins/PyZeroCrossing.py	Mon Nov 17 11:44:15 2014 +0000
@@ -86,7 +86,7 @@
 		paramlist1={
 		'identifier':'threshold',
 		'name':'Noise threshold',
-		'description':'',
+		'description':'Magnitude below which a process block will be considered to be all zero',
 		'unit':'v',
 		'minValue':0.0,
 		'maxValue':0.5,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Example VamPy plugins/examples.cat	Mon Nov 17 11:44:15 2014 +0000
@@ -0,0 +1,4 @@
+vamp:vampy:vampy-mfcc::Low Level Features
+vamp:vampy:vampy-sc3::Low Level Features
+vamp:vampy:vampy-sf3::Low Level Features
+vamp:vampy:vampy-zc2::Low Level Features