Mercurial > hg > vampy
comparison PyTypeInterface.h @ 51:c1e4f706ca9a
Fix numpy version incompatibility issues and updated some example plugins.
author | fazekasgy |
---|---|
date | Thu, 08 Oct 2009 08:47:28 +0000 |
parents | 8b2eddf686da |
children | 74703a562ce3 |
comparison
equal
deleted
inserted
replaced
50:3868da185d73 | 51:c1e4f706ca9a |
---|---|
122 } | 122 } |
123 }; | 123 }; |
124 | 124 |
125 // Utilities | 125 // Utilities |
126 void setStrictTypingFlag(bool b) {m_strict = b;} | 126 void setStrictTypingFlag(bool b) {m_strict = b;} |
127 void setNumpyInstalled(bool b) {m_numpyInstalled = b;} | |
127 ValueError getError() const; | 128 ValueError getError() const; |
128 std::string PyValue_Get_TypeName(PyObject*) const; | 129 std::string PyValue_Get_TypeName(PyObject*) const; |
129 bool initMaps() const; | 130 bool initMaps() const; |
130 | 131 |
131 // Basic type conversion: Python to C++ | 132 // Basic type conversion: Python to C++ |
390 private: | 391 private: |
391 bool m_strict; | 392 bool m_strict; |
392 mutable bool m_error; | 393 mutable bool m_error; |
393 mutable std::queue<ValueError> m_errorQueue; | 394 mutable std::queue<ValueError> m_errorQueue; |
394 unsigned int m_inputSampleRate; | 395 unsigned int m_inputSampleRate; |
396 bool m_numpyInstalled; | |
395 | 397 |
396 void setValueError(std::string,bool) const; | 398 void setValueError(std::string,bool) const; |
397 ValueError& lastError() const; | 399 ValueError& lastError() const; |
398 | 400 |
399 /* Overloaded _convert(), bypasses error checking to avoid doing it twice in internals. */ | 401 /* Overloaded _convert(), bypasses error checking to avoid doing it twice in internals. */ |
430 | 432 |
431 }; | 433 }; |
432 | 434 |
433 /* Convert Sample Buffers to Python */ | 435 /* Convert Sample Buffers to Python */ |
434 | 436 |
435 /// passing the sample buffers as buitin python lists | 437 /// passing the sample buffers as builtin python lists |
436 /// Optimization: using fast sequence protocol | 438 /// Optimization: using fast sequence protocol |
437 inline PyObject* | 439 inline PyObject* |
438 PyTypeInterface::InputBuffers_As_PythonLists(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize, const Vamp::Plugin::InputDomain& dtype) | 440 PyTypeInterface::InputBuffers_As_PythonLists(const float *const *inputBuffers,const size_t& channels, const size_t& blockSize, const Vamp::Plugin::InputDomain& dtype) |
439 { | 441 { |
440 //create a list of lists (new references) | 442 //create a list of lists (new references) |
444 // pyFloat/pyComplex types will always be new references, | 446 // pyFloat/pyComplex types will always be new references, |
445 // they will be freed when the lists are deallocated. | 447 // they will be freed when the lists are deallocated. |
446 | 448 |
447 PyObject **pyChannelListArray = PySequence_Fast_ITEMS(pyChannelList); | 449 PyObject **pyChannelListArray = PySequence_Fast_ITEMS(pyChannelList); |
448 for (size_t i=0; i < channels; ++i) { | 450 for (size_t i=0; i < channels; ++i) { |
449 | 451 |
450 PyObject *pySampleList = PyList_New((Py_ssize_t) blockSize); | 452 size_t arraySize; |
451 PyObject **pySampleListArray = PySequence_Fast_ITEMS(pySampleList); | |
452 size_t arraySize; | |
453 | |
454 if (dtype==Vamp::Plugin::FrequencyDomain) | 453 if (dtype==Vamp::Plugin::FrequencyDomain) |
455 arraySize = blockSize + 2; | 454 arraySize = (blockSize / 2) + 1; //blockSize + 2; if cplx list isn't used |
456 else | 455 else |
457 arraySize = blockSize; | 456 arraySize = blockSize; |
457 | |
458 PyObject *pySampleList = PyList_New((Py_ssize_t) arraySize); | |
459 PyObject **pySampleListArray = PySequence_Fast_ITEMS(pySampleList); | |
458 | 460 |
459 // Note: passing a complex list crashes the C-style plugin | 461 // Note: passing a complex list crashes the C-style plugin |
460 // when it tries to convert it to a numpy array directly. | 462 // when it tries to convert it to a numpy array directly. |
461 // This plugin will be obsolete, but we have to find a way | 463 // This plugin will be obsolete, but we have to find a way |
462 // to prevent such crash. | 464 // to prevent such crash: possibly a numpy bug, |
463 | 465 // works fine above 1.0.4 |
464 switch (Vamp::Plugin::TimeDomain) //(dtype) | 466 |
467 switch (dtype) //(Vamp::Plugin::TimeDomain) | |
465 { | 468 { |
466 case Vamp::Plugin::TimeDomain : | 469 case Vamp::Plugin::TimeDomain : |
467 | 470 |
468 for (size_t j = 0; j < arraySize; ++j) { | 471 for (size_t j = 0; j < arraySize; ++j) { |
469 PyObject *pyFloat=PyFloat_FromDouble( | 472 PyObject *pyFloat=PyFloat_FromDouble( |
473 break; | 476 break; |
474 | 477 |
475 case Vamp::Plugin::FrequencyDomain : | 478 case Vamp::Plugin::FrequencyDomain : |
476 | 479 |
477 size_t k = 0; | 480 size_t k = 0; |
478 for (size_t j = 0; j < arraySize/2; ++j) { | 481 for (size_t j = 0; j < arraySize; ++j) { |
479 PyObject *pyComplex=PyComplex_FromDoubles( | 482 PyObject *pyComplex=PyComplex_FromDoubles( |
480 (double) inputBuffers[i][k], | 483 (double) inputBuffers[i][k], |
481 (double) inputBuffers[i][k+1]); | 484 (double) inputBuffers[i][k+1]); |
482 pySampleListArray[j] = pyComplex; | 485 pySampleListArray[j] = pyComplex; |
483 k += 2; | 486 k += 2; |