Mercurial > hg > piper-vamp-js
changeset 82:5bd5d48a1c21
Introduce "raw" process call in which the input is not serialised
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Fri, 09 Sep 2016 15:41:35 +0100 |
parents | 5e6ff69b4209 |
children | a6ab5fd80eb7 |
files | Makefile.example.emscripten VamPipePluginLibrary.cpp VamPipePluginLibrary.h example.cpp vampipe.map |
diffstat | 5 files changed, 48 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.example.emscripten Thu Sep 08 15:27:48 2016 +0100 +++ b/Makefile.example.emscripten Fri Sep 09 15:41:35 2016 +0100 @@ -35,7 +35,7 @@ -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ -s DISABLE_EXCEPTION_CATCHING=0 \ -s EXPORT_NAME="'ExampleModule'" \ - -s EXPORTED_FUNCTIONS="['_vampipeRequestJson','_vampipeFreeJson']" + -s EXPORTED_FUNCTIONS="['_vampipeRequestJson','_vampipeProcess','_vampipeFreeJson']" # -s NO_FILESYSTEM=1 \ # no longer exists? -s NO_BROWSER=1
--- a/VamPipePluginLibrary.cpp Thu Sep 08 15:27:48 2016 +0100 +++ b/VamPipePluginLibrary.cpp Fri Sep 09 15:41:35 2016 +0100 @@ -193,6 +193,36 @@ } string +VamPipePluginLibrary::processImpl(int pluginHandle, + const float *const *inputBuffers, + int sec, + int nsec) +{ + RequestOrResponse response; + response.direction = RequestOrResponse::Response; + response.type = RRType::Process; + + try { + if (!m_mapper.isConfigured(pluginHandle)) { + throw runtime_error("plugin has not been configured"); + } + + Vamp::Plugin *plugin = m_mapper.handleToPlugin(pluginHandle); + Vamp::RealTime timestamp(sec, nsec); + + response.processResponse.features = plugin->process(inputBuffers, timestamp); + response.success = true; + + return writeResponse(response); + + } catch (const std::exception &e) { + return VampJson::fromException(e, RRType::Process).dump(); + } + + m_useBase64 = true; //!!! todo: return something raw as well! +} + +string VamPipePluginLibrary::requestJsonImpl(string req) { RequestOrResponse request; @@ -200,7 +230,6 @@ try { request = readRequest(req); } catch (const std::exception &e) { - std::cerr << "FAILURE" << std::endl; return VampJson::fromException(e, RRType::NotValid).dump(); } @@ -254,7 +283,7 @@ if (channels != m_mapper.getChannelCount(h)) { throw runtime_error("wrong number of channels supplied to process"); } - + const float **fbuffers = new const float *[channels]; for (int i = 0; i < channels; ++i) { if (int(preq.inputBuffers[i].size()) != m_mapper.getBlockSize(h)) {
--- a/VamPipePluginLibrary.h Thu Sep 08 15:27:48 2016 +0100 +++ b/VamPipePluginLibrary.h Fri Sep 09 15:41:35 2016 +0100 @@ -58,12 +58,18 @@ return strdup(requestJsonImpl(request).c_str()); } + const char *process(int handle, const float *const *inputBuffers, + int sec, int nsec) { + return strdup(processImpl(handle, inputBuffers, sec, nsec).c_str()); + } + void freeJson(const char *json) { free(const_cast<char *>(json)); } private: std::string requestJsonImpl(std::string req); + std::string processImpl(int, const float *const *, int, int); RequestOrResponse readRequest(std::string req); std::string writeResponse(const RequestOrResponse &resp) const;
--- a/example.cpp Thu Sep 08 15:27:48 2016 +0100 +++ b/example.cpp Fri Sep 09 15:41:35 2016 +0100 @@ -69,6 +69,15 @@ return library.requestJson(request); } + //!!! naming problem -- returns json as well, it's just that + //!!! unlike the others, it doesn't take json as input +const char *vampipeProcess(int pluginHandle, + const float *const *inputBuffers, + int sec, + int nsec) { + return library.process(pluginHandle, inputBuffers, sec, nsec); +} + void vampipeFreeJson(const char *json) { return library.freeJson(json); }