comparison PyPlugin.h @ 72:ffaa1fb3d7de vampyhost

inline is not a useful keyword with contemporary compilers
author Chris Cannam
date Mon, 24 Nov 2014 09:50:49 +0000
parents 40a01bb24209
children
comparison
equal deleted inserted replaced
71:40a01bb24209 72:ffaa1fb3d7de
361 return rValue; 361 return rValue;
362 } 362 }
363 363
364 }; 364 };
365 365
366 /// optimised process call
367 inline PyPlugin::FeatureSet
368 PyPlugin::processMethodCall(const float *const *inputBuffers,Vamp::RealTime timestamp)
369 {
370
371 /// Optimizations: 1) we avoid ...ObjArg functions since we know
372 /// the number of arguments, and we don't like va_list parsing
373 /// in the process. 2) Also: we're supposed to incref args,
374 /// but instead, we let the arguments tuple steal the references
375 /// and decref them when it is deallocated.
376 /// 3) all conversions are now using the fast sequence protocol
377 /// (indexing the underlying object array).
378
379 FeatureSet rFeatureSet;
380 PyObject *pyChannelList = NULL;
381
382 if (m_processType == numpy_bufferProcess) {
383 pyChannelList = m_ti.InputBuffers_As_SharedMemoryList(
384 inputBuffers,m_channels,m_blockSize,m_inputDomain);
385 }
386
387 if (m_processType == legacyProcess) {
388 pyChannelList = m_ti.InputBuffers_As_PythonLists(
389 inputBuffers,m_channels,m_blockSize,m_inputDomain);
390 }
391
392 #ifdef HAVE_NUMPY
393 if (m_processType == numpy_arrayProcess) {
394 pyChannelList = m_ti.InputBuffers_As_NumpyArray(
395 inputBuffers,m_channels,m_blockSize,m_inputDomain);
396 }
397 #endif 366 #endif
398
399 /// we don't expect these to fail unless out of memory (which is very unlikely on modern systems)
400 #ifdef _DEBUG
401 if (!pyChannelList) {
402 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();}
403 std::string method = PyString_AsString(m_pyProcess);
404 cerr << PLUGIN_ERROR << "Failed to create channel list." << endl;
405 return rFeatureSet;
406 }
407 #endif
408
409 PyObject *pyTimeStamp = NULL;
410
411 if (m_useRealTimeFlag) {
412 //(1) pass TimeStamp as PyRealTime object
413 pyTimeStamp = PyRealTime_FromRealTime(timestamp);
414
415 } else {
416 //(2) pass TimeStamp as frame count (long Sample Count)
417 pyTimeStamp = PyLong_FromLong(Vamp::RealTime::realTime2Frame
418 (timestamp, (unsigned int) m_inputSampleRate));
419 }
420
421
422 #ifdef _DEBUG
423 if (!pyTimeStamp) {
424 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();}
425 std::string method = PyString_AsString(m_pyProcess);
426 cerr << PLUGIN_ERROR << "Failed to create RealTime time stamp." << endl;
427 Py_DECREF(pyChannelList);
428 return rFeatureSet;
429 }
430 #endif
431
432 /// Old method: Call python process (returns new reference)
433 /// PyObject *pyValue = PyObject_CallMethodObjArgs
434 /// (m_pyInstance,m_pyProcess,pyChannelList,pyTimeStamp,NULL);
435
436 PyObject *pyArgs = PyTuple_New(2);
437 PyTuple_SET_ITEM(pyArgs, 0, pyChannelList);
438 PyTuple_SET_ITEM(pyArgs, 1, pyTimeStamp);
439
440 /// Call python process (returns new reference) {kwArgs = NULL}
441 PyObject *pyValue = PyObject_Call(m_pyProcessCallable,pyArgs,NULL);
442
443 if (!pyValue) {
444 if (PyErr_Occurred()) {PyErr_Print(); PyErr_Clear();}
445 std::string method = PyString_AsString(m_pyProcess);
446 cerr << PLUGIN_ERROR << "An error occurred while evaluating Python process." << endl;
447 Py_CLEAR(pyValue);
448 Py_CLEAR(pyArgs);
449 return rFeatureSet;
450 }
451
452 rFeatureSet = m_ti.PyValue_To_FeatureSet(pyValue);
453 if (!m_ti.error) {
454 Py_DECREF(pyValue);
455 Py_DECREF(pyArgs);
456 } else {
457 typeErrorHandler(PyString_AsString(m_pyProcess),true);
458 Py_CLEAR(pyValue);
459 Py_CLEAR(pyArgs);
460 }
461 return rFeatureSet;
462 }
463
464 #endif