changeset 47:8b2eddf686da

Fix blockSize+2 for frequency domin plugins
author fazekasgy
date Tue, 06 Oct 2009 09:27:20 +0000
parents af9c4cee95a8
children cb207d275e8e
files Example VamPy plugins/PySpectralFeatures.py PyPlugin.h PyTypeInterface.h
diffstat 3 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Example VamPy plugins/PySpectralFeatures.py	Mon Oct 05 16:14:25 2009 +0000
+++ b/Example VamPy plugins/PySpectralFeatures.py	Tue Oct 06 09:27:20 2009 +0000
@@ -35,12 +35,12 @@
 		self.m_channels = channels
 		self.m_stepSize = stepSize		
 		self.m_blockSize = blockSize
-		self.prevMag = zeros((blockSize/2)-1)
+		self.prevMag = zeros((blockSize/2))
 		return True
 		
 	def reset(self):
 		# reset any initial conditions
-		self.prevMag = zeros((blockSize/2)-1)
+		self.prevMag = zeros((blockSize/2))
 		return None
 	
 	def getMaker(self):
--- a/PyPlugin.h	Mon Oct 05 16:14:25 2009 +0000
+++ b/PyPlugin.h	Tue Oct 06 09:27:20 2009 +0000
@@ -410,7 +410,7 @@
 	PyObject *pyChannelList = NULL;
 
 	if (m_processType == numpy_bufferProcess) {
-		pyChannelList = m_ti.InputBuffers_As_SharedMemoryList(inputBuffers,m_channels,m_blockSize);
+		pyChannelList = m_ti.InputBuffers_As_SharedMemoryList(inputBuffers,m_channels,m_blockSize,m_inputDomain);
 	} 
 
 	if (m_processType == legacyProcess) {
--- a/PyTypeInterface.h	Mon Oct 05 16:14:25 2009 +0000
+++ b/PyTypeInterface.h	Tue Oct 06 09:27:20 2009 +0000
@@ -152,7 +152,7 @@
 
 	// Input buffers to Python
 	PyObject* InputBuffers_As_PythonLists(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize, const Vamp::Plugin::InputDomain& dtype);
-	PyObject* InputBuffers_As_SharedMemoryList(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize);
+	PyObject* InputBuffers_As_SharedMemoryList(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize, const Vamp::Plugin::InputDomain& dtype);
 
 	// Numpy types
 #ifdef HAVE_NUMPY
@@ -449,6 +449,12 @@
 
 		PyObject *pySampleList = PyList_New((Py_ssize_t) blockSize);
 		PyObject **pySampleListArray =  PySequence_Fast_ITEMS(pySampleList);
+		size_t arraySize;
+
+		if (dtype==Vamp::Plugin::FrequencyDomain) 
+			arraySize = blockSize + 2;
+		else 
+			arraySize = blockSize;
 		
 		// Note: passing a complex list crashes the C-style plugin
 		// when it tries to convert it to a numpy array directly.
@@ -459,7 +465,7 @@
 		{
 			case Vamp::Plugin::TimeDomain :
 
-			for (size_t j = 0; j < blockSize; ++j) {
+			for (size_t j = 0; j < arraySize; ++j) {
 				PyObject *pyFloat=PyFloat_FromDouble(
 					(double) inputBuffers[i][j]);
 				pySampleListArray[j] = pyFloat;
@@ -469,7 +475,7 @@
 			case Vamp::Plugin::FrequencyDomain :
 
 			size_t k = 0;
-			for (size_t j = 0; j < blockSize/2; ++j) {
+			for (size_t j = 0; j < arraySize/2; ++j) {
 				PyObject *pyComplex=PyComplex_FromDoubles(
 					(double) inputBuffers[i][k], 
 					(double) inputBuffers[i][k+1]);
@@ -487,7 +493,7 @@
 /// numpy buffer interface: passing the sample buffers as shared memory buffers
 /// Optimization: using sequence protocol for creating the buffer list
 inline PyObject*
-PyTypeInterface::InputBuffers_As_SharedMemoryList(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize)
+PyTypeInterface::InputBuffers_As_SharedMemoryList(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize, const Vamp::Plugin::InputDomain& dtype)
 {	
 	//create a list of buffers (returns new references)
 	PyObject *pyChannelList = PyList_New((Py_ssize_t) channels);
@@ -498,8 +504,13 @@
 	// as complex or float array using Numpy's frombuffer() method
 	// (this will not copy values just keep the starting adresses 
 	// for each channel in a list)
-	Py_ssize_t bufferSize = (Py_ssize_t) sizeof(float) * blockSize;
-
+	Py_ssize_t bufferSize;
+	
+	if (dtype==Vamp::Plugin::FrequencyDomain) 
+		bufferSize = (Py_ssize_t) sizeof(float) * (blockSize+2);
+	else 
+		bufferSize = (Py_ssize_t) sizeof(float) * blockSize;
+	
 	for (size_t i=0; i < channels; ++i) {
 		PyObject *pyBuffer = PyBuffer_FromMemory
 		((void *) (float *) inputBuffers[i],bufferSize);
@@ -547,7 +558,7 @@
 
 		case Vamp::Plugin::FrequencyDomain :
 		typenum = dtype_complex64; //NPY_CFLOAT;
-		arraySize = (int) blockSize / 2;
+		arraySize = (int) (blockSize / 2) + 1;
 		break;
 		
 		default :