Added ProcessorSpec.

looper
Ben Niemann 5 years ago
parent 160516866e
commit 3638db9b57
  1. 12
      CMakeLists.txt
  2. 2
      bin/setup_env.sh
  3. 6
      noisicaa/audioproc/CMakeLists.txt
  4. 4
      noisicaa/core/CMakeLists.txt
  5. 5
      noisicore/CMakeLists.txt
  6. 2
      noisicore/misc.cpp
  7. 24
      noisicore/processor.cpp
  8. 13
      noisicore/processor.h
  9. 6
      noisicore/processor.pxd
  10. 17
      noisicore/processor_ladspa.cpp
  11. 5
      noisicore/processor_ladspa.h
  12. 13
      noisicore/processor_ladspa_test.pyx
  13. 45
      noisicore/processor_spec.cpp
  14. 89
      noisicore/processor_spec.h
  15. 41
      noisicore/processor_spec.pxd

@ -48,7 +48,7 @@ macro(add_cython_module mod lang)
set(${mod}.so ${pkg_target}.${mod})
endmacro(add_cython_module)
macro(add_capnp src)
macro(add_py_capnp src)
add_custom_command(
OUTPUT ${src}
COMMAND ln -sf ${CMAKE_CURRENT_LIST_DIR}/${src} ${src}
@ -57,7 +57,15 @@ macro(add_capnp src)
file(RELATIVE_PATH pkg_path ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR})
string(REGEX REPLACE "/" "." pkg_target ${pkg_path})
add_custom_target(${pkg_target}.${src} ALL DEPENDS ${src})
endmacro(add_capnp)
endmacro(add_py_capnp)
macro(add_cpp_capnp src)
add_custom_command(
OUTPUT ${src}.c++ ${src}.h
COMMAND capnp compile --verbose --output=c++:${CMAKE_BINARY_DIR} --src-prefix=${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_LIST_DIR}/${src}
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${src}
)
endmacro(add_cpp_capnp)
add_subdirectory(noisicore)
add_subdirectory(noisicaa)

@ -11,7 +11,7 @@ LIBSDIR="$BASEDIR/libs"
LILV_DEPS="libserd-dev libsord-dev libsratom-dev lv2-examples mda-lv2"
LADSPA_DEPS="ladspa-sdk swh-plugins"
CSOUND_DEPS="libsndfile1-dev libsamplerate0-dev libboost-dev flex bison cmake"
CAPNP_DEPS="capnproto libcapnp-0.5.3"
CAPNP_DEPS="capnproto libcapnp-0.5.3 libcapnp-dev"
PYVERSION=3.5

@ -16,9 +16,9 @@ add_python_package(
resample_test.py
)
add_capnp(frame_data.capnp)
add_capnp(entity.capnp)
add_capnp(pipeline_mutations.capnp)
add_py_capnp(frame_data.capnp)
add_py_capnp(entity.capnp)
add_py_capnp(pipeline_mutations.capnp)
add_cython_module(resample C)
target_link_libraries(${resample.so} PRIVATE swresample)

@ -19,7 +19,7 @@ add_python_package(
storage_test.py
)
add_capnp(message.capnp)
add_capnp(perf_stats.capnp)
add_py_capnp(message.capnp)
add_py_capnp(perf_stats.capnp)
add_subdirectory(stats)

@ -6,6 +6,7 @@ set(LIB_SRCS
misc.cpp
opcodes.cpp
processor.cpp
processor_spec.cpp
processor_ladspa.cpp
spec.cpp
vm.cpp
@ -23,7 +24,7 @@ set(TEST_SRCS
include_directories(${CMAKE_CURRENT_LIST_DIR})
add_library(noisicore STATIC ${LIB_SRCS})
target_compile_options(noisicore PRIVATE -fPIC -g)
target_compile_options(noisicore PRIVATE -fPIC -g -std=c++11 -Wall -Werror -pedantic)
target_link_libraries(noisicore PRIVATE portaudio)
foreach(TEST_SRC ${TEST_SRCS})
@ -31,3 +32,5 @@ foreach(TEST_SRC ${TEST_SRCS})
add_cython_module(${TEST_MOD} CXX)
target_link_libraries(${${TEST_MOD}.so} noisicore)
endforeach(TEST_SRC)

@ -15,6 +15,8 @@ string sprintf(const string &fmt, ...) {
int size = std::vsnprintf(nullptr, 0, fmt.c_str(), args) + 1;
unique_ptr<char> buf(new char[size]);
va_start(args, fmt);
std::vsnprintf(buf.get(), size, fmt.c_str(), args);
return string(buf.get());
}

@ -1,5 +1,6 @@
#include "processor.h"
#include "misc.h"
#include "processor_ladspa.h"
namespace noisicaa {
@ -11,6 +12,24 @@ Processor::~Processor() {
cleanup();
}
Status Processor::get_string_parameter(const string& name, string* value) {
ParameterSpec* param_spec;
Status status = _spec->get_parameter(name, &param_spec);
if (status.is_error()) { return status; }
if (param_spec->type() != ParameterType::String) {
return Status::Error(
sprintf("Parameter '%s' is not of type string.", name.c_str()));
}
StringParameterSpec* string_param_spec =
dynamic_cast<StringParameterSpec*>(param_spec);
assert(string_param_spec != nullptr);
*value = string_param_spec->default_value();
return Status::Ok();
}
Processor* Processor::create(const string& name) {
if (name == "ladspa") {
return new ProcessorLadspa();
@ -19,11 +38,14 @@ Processor* Processor::create(const string& name) {
}
}
Status Processor::setup() {
Status Processor::setup(const ProcessorSpec* spec) {
_spec.reset(spec);
return Status::Ok();
}
void Processor::cleanup() {
_spec.reset();
}
} // namespace noisicaa

@ -1,13 +1,17 @@
#ifndef _NOISICORE_PROCESSOR_H
#define _NOISICORE_PROCESSOR_H
#include <memory>
#include <string>
#include <stdint.h>
#include "status.h"
#include "buffers.h"
#include "block_context.h"
#include "processor_spec.h"
using std::string;
using std::unique_ptr;
namespace noisicaa {
@ -18,11 +22,16 @@ class Processor {
static Processor* create(const string& name);
virtual Status setup();
Status get_string_parameter(const string& name, string* value);
virtual Status setup(const ProcessorSpec* spec);
virtual void cleanup();
virtual Status connect_port(int port_idx, BufferPtr buf) = 0;
virtual Status connect_port(uint32_t port_idx, BufferPtr buf) = 0;
virtual Status run(BlockContext* ctxt) = 0;
protected:
unique_ptr<const ProcessorSpec> _spec;
};
} // namespace noisicaa

@ -1,17 +1,19 @@
from libc.stdint cimport uint32_t
from libcpp.string cimport string
from .status cimport *
from .buffers cimport *
from .block_context cimport *
from .processor_spec cimport *
cdef extern from "processor.h" namespace "noisicaa" nogil:
cppclass Processor:
@staticmethod
Processor* create(const string& name)
Status setup()
Status setup(const ProcessorSpec* spec)
void cleanup()
Status connect_port(int port_idx, BufferPtr buf)
Status connect_port(uint32_t port_idx, BufferPtr buf)
Status run(BlockContext* ctxt)

@ -1,6 +1,7 @@
#include "processor_ladspa.h"
#include <dlfcn.h>
#include <stdint.h>
#include "misc.h"
namespace noisicaa {
@ -14,12 +15,17 @@ ProcessorLadspa::ProcessorLadspa()
ProcessorLadspa::~ProcessorLadspa() {
}
Status ProcessorLadspa::setup() {
Status status = Processor::setup();
Status ProcessorLadspa::setup(const ProcessorSpec* spec) {
Status status = Processor::setup(spec);
if (status.is_error()) { return status; }
string library_path = "/usr/lib/ladspa/amp.so";
string label = "amp_mono";
string library_path;
status = get_string_parameter("ladspa_library_path", &library_path);
if (status.is_error()) { return status; }
string label;
status = get_string_parameter("ladspa_plugin_label", &label);
if (status.is_error()) { return status; }
_library = dlopen(library_path.c_str(), RTLD_NOW);
if (_library == nullptr) {
@ -84,8 +90,7 @@ void ProcessorLadspa::cleanup() {
Processor::cleanup();
}
Status ProcessorLadspa::connect_port(int port_idx, BufferPtr buf) {
assert(port_idx >= 0);
Status ProcessorLadspa::connect_port(uint32_t port_idx, BufferPtr buf) {
assert(port_idx < _descriptor->PortCount);
_descriptor->connect_port(_instance, port_idx, (LADSPA_Data*)buf);
return Status::Ok();

@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <stdint.h>
#include "ladspa.h"
#include "status.h"
@ -20,10 +21,10 @@ class ProcessorLadspa : public Processor {
ProcessorLadspa();
~ProcessorLadspa() override;
Status setup() override;
Status setup(const ProcessorSpec* spec) override;
void cleanup() override;
Status connect_port(int port_idx, BufferPtr buf) override;
Status connect_port(uint32_t port_idx, BufferPtr buf) override;
Status run(BlockContext* ctxt) override;
private:

@ -1,12 +1,15 @@
from libcpp.string cimport string
from libcpp.memory cimport unique_ptr
from .status cimport *
from .block_context cimport *
from .buffers cimport *
from .processor cimport *
from .processor_spec cimport *
import unittest
import sys
class TestProcessorLadspa(unittest.TestCase):
def test_ladspa(self):
cdef Status status
@ -17,7 +20,15 @@ class TestProcessorLadspa(unittest.TestCase):
cdef Processor* processor = processor_ptr.get()
status = processor.setup()
cdef unique_ptr[ProcessorSpec] spec
spec.reset(new ProcessorSpec())
spec.get().add_port(b'gain', PortType.kRateControl, PortDirection.Input)
spec.get().add_port(b'in', PortType.audio, PortDirection.Input)
spec.get().add_port(b'out', PortType.audio, PortDirection.Output)
spec.get().add_parameter(new StringParameterSpec(b'ladspa_library_path', b'/usr/lib/ladspa/amp.so'))
spec.get().add_parameter(new StringParameterSpec(b'ladspa_plugin_label', b'amp_mono'))
status = processor.setup(spec.release())
self.assertFalse(status.is_error(), status.message())
cdef float gain

@ -0,0 +1,45 @@
#include "processor_spec.h"
#include <iostream>
#include "misc.h"
namespace noisicaa {
PortSpec::PortSpec(const string& name, PortType type, PortDirection direction)
: _name(name), _type(type), _direction(direction) {}
ParameterSpec::ParameterSpec(ParameterType type, const string& name)
: _type(type),
_name(name) {}
ParameterSpec::~ParameterSpec() {}
StringParameterSpec::StringParameterSpec(
const string& name, const string& default_value)
: ParameterSpec(ParameterType::String, name),
_default_value(default_value) {}
ProcessorSpec::ProcessorSpec() {
}
Status ProcessorSpec::add_port(
const string& name, PortType type, PortDirection direction) {
_ports.emplace_back(PortSpec(name, type, direction));
return Status::Ok();
}
Status ProcessorSpec::add_parameter(ParameterSpec* param) {
_parameters[param->name()].reset(param);
return Status::Ok();
}
Status ProcessorSpec::get_parameter(const string& name, ParameterSpec** param) const {
const auto& it = _parameters.find(name);
if (it != _parameters.end()) {
*param = it->second.get();
return Status::Ok();
}
return Status::Error(sprintf("Parameter '%s' not found.", name.c_str()));
}
} // namespace noisicaa

@ -0,0 +1,89 @@
#ifndef _NOISICORE_PROCESSOR_SPEC_H
#define _NOISICORE_PROCESSOR_SPEC_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <stdint.h>
#include "status.h"
using std::map;
using std::string;
using std::unique_ptr;
using std::vector;
namespace noisicaa {
enum PortType {
audio,
aRateControl,
kRateControl,
atomData,
};
enum PortDirection {
Input,
Output,
};
class PortSpec {
public:
PortSpec(const string& name, PortType type, PortDirection direction);
string name() const { return _name; }
PortType type() const { return _type; }
PortDirection direction() const { return _direction; }
private:
string _name;
PortType _type;
PortDirection _direction;
};
enum ParameterType {
String,
};
class ParameterSpec {
public:
ParameterSpec(ParameterType type, const string& name);
virtual ~ParameterSpec();
ParameterType type() const { return _type; }
string name() const { return _name; }
private:
ParameterType _type;
string _name;
};
class StringParameterSpec : public ParameterSpec {
public:
StringParameterSpec(const string& name, const string& default_value);
string default_value() const { return _default_value; }
private:
string _default_value;
};
class ProcessorSpec {
public:
ProcessorSpec();
Status add_port(const string& name, PortType type, PortDirection direction);
int num_ports() const { return _ports.size(); }
PortSpec get_port(int idx) const { return _ports[idx]; }
Status add_parameter(ParameterSpec* param);
Status get_parameter(const string& name, ParameterSpec** param) const;
private:
vector<PortSpec> _ports;
map<string, unique_ptr<ParameterSpec>> _parameters;
};
} // namespace noisicaa
#endif

@ -0,0 +1,41 @@
from libcpp.string cimport string
from .status cimport *
cdef extern from "processor_spec.h" namespace "noisicaa" nogil:
enum PortType:
audio
aRateControl
kRateControl
atomData
enum PortDirection:
Input
Output
cppclass PortSpec:
string name() const
PortType type() const
PortDirection direction() const
enum ParameterType:
String
cppclass ParameterSpec:
string name() const
ParameterType type() const
cppclass StringParameterSpec(ParameterSpec):
StringParameterSpec(const string& name, const string& default_value)
string default_value() const
cppclass ProcessorSpec:
ProcessorSpec()
Status add_port(const string& name, PortType type, PortDirection direction);
int num_ports() const
PortSpec get_port(int idx) const
Status add_parameter(ParameterSpec* param)
Status get_parameter(const string& name, ParameterSpec** param) const
Loading…
Cancel
Save