Mercurial > hg > flattendynamics
changeset 15:7bb35203a7bd
Make object accessible as a standalone class as well as through LADSPA
author | Chris Cannam |
---|---|
date | Tue, 22 Jul 2014 16:11:02 +0100 |
parents | 0e28664bc4fc |
children | c12cab43141d |
files | flattendynamics-ladspa.cpp flattendynamics-ladspa.h |
diffstat | 2 files changed, 65 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/flattendynamics-ladspa.cpp Tue Jul 22 15:40:45 2014 +0100 +++ b/flattendynamics-ladspa.cpp Tue Jul 22 16:11:02 2014 +0100 @@ -56,14 +56,14 @@ portNames, hints, 0, // Implementation data - instantiate, - connectPort, - activate, - run, + ladspaInstantiate, + ladspaConnectPort, + ladspaActivate, + ladspaRun, 0, // Run adding 0, // Set run adding gain - deactivate, - cleanup + ladspaDeactivate, + ladspaCleanup }; const LADSPA_Descriptor * @@ -99,54 +99,72 @@ } LADSPA_Handle -FlattenDynamics::instantiate(const LADSPA_Descriptor *, unsigned long rate) +FlattenDynamics::ladspaInstantiate(const LADSPA_Descriptor *, unsigned long rate) { FlattenDynamics *flatten = new FlattenDynamics(rate); return flatten; } void -FlattenDynamics::connectPort(LADSPA_Handle handle, - unsigned long port, LADSPA_Data *location) +FlattenDynamics::ladspaConnectPort(LADSPA_Handle handle, + unsigned long port, + LADSPA_Data *location) { FlattenDynamics *flatten = (FlattenDynamics *)handle; - - float **ports[PortCount] = { - &flatten->m_input, - &flatten->m_output, - &flatten->m_pgain, - }; - - *ports[port] = (float *)location; + if (ports[port] & LADSPA_PORT_INPUT) { + flatten->connectInputPort(Port(port), location); + } else { + flatten->connectOutputPort(Port(port), location); + } } void -FlattenDynamics::activate(LADSPA_Handle handle) +FlattenDynamics::ladspaActivate(LADSPA_Handle handle) { FlattenDynamics *flatten = (FlattenDynamics *)handle; flatten->reset(); } void -FlattenDynamics::run(LADSPA_Handle handle, unsigned long samples) +FlattenDynamics::ladspaRun(LADSPA_Handle handle, unsigned long samples) { FlattenDynamics *flatten = (FlattenDynamics *)handle; - flatten->runImpl(samples); + flatten->process(samples); } void -FlattenDynamics::deactivate(LADSPA_Handle handle) +FlattenDynamics::ladspaDeactivate(LADSPA_Handle handle) { - activate(handle); // both functions just reset the plugin + ladspaActivate(handle); // both functions just reset the plugin } void -FlattenDynamics::cleanup(LADSPA_Handle handle) +FlattenDynamics::ladspaCleanup(LADSPA_Handle handle) { delete (FlattenDynamics *)handle; } void +FlattenDynamics::connectInputPort(Port p, const float *location) +{ + const float **ports[PortCount] = { + &m_input, 0, 0, + }; + + *ports[int(p)] = location; +} + +void +FlattenDynamics::connectOutputPort(Port p, float *location) +{ + float **ports[PortCount] = { + 0, &m_output, &m_pgain, + }; + + *ports[int(p)] = location; +} + +void FlattenDynamics::reset() { delete[] m_history; @@ -175,7 +193,7 @@ } void -FlattenDynamics::runImpl(unsigned long sampleCount) +FlattenDynamics::process(int sampleCount) { if (!m_input || !m_output) return; updateParameters(); @@ -186,12 +204,12 @@ // We aim to take M seconds to move to our target gain for (int i = 0; i < sampleCount; ++i) { - m_output[i] = process(m_input[i]); + m_output[i] = processSingle(m_input[i]); } } float -FlattenDynamics::process(float f) +FlattenDynamics::processSingle(float f) { updateRMS(f);
--- a/flattendynamics-ladspa.h Tue Jul 22 15:40:45 2014 +0100 +++ b/flattendynamics-ladspa.h Tue Jul 22 16:11:02 2014 +0100 @@ -10,38 +10,44 @@ public: static const LADSPA_Descriptor *getDescriptor(unsigned long index); -private: - FlattenDynamics(int sampleRate); - ~FlattenDynamics(); - - enum { + enum Port { AudioInputPort = 0, AudioOutputPort = 1, GainOutputPort = 2, PortCount = 3, }; + // Rest of the public interface is for use when constructing the + // class directly, rather than through LADSPA + + FlattenDynamics(int sampleRate); + ~FlattenDynamics(); + + void connectInputPort(Port p, const float *addr); + void connectOutputPort(Port p, float *addr); + void reset(); + void process(int nsamples); + +private: static const char *const portNames[PortCount]; static const LADSPA_PortDescriptor ports[PortCount]; static const LADSPA_PortRangeHint hints[PortCount]; static const LADSPA_Properties properties; static const LADSPA_Descriptor ladspaDescriptor; - static LADSPA_Handle instantiate(const LADSPA_Descriptor *, unsigned long); - static void connectPort(LADSPA_Handle, unsigned long, LADSPA_Data *); - static void activate(LADSPA_Handle); - static void run(LADSPA_Handle, unsigned long); - static void deactivate(LADSPA_Handle); - static void cleanup(LADSPA_Handle); + static LADSPA_Handle ladspaInstantiate(const LADSPA_Descriptor *, unsigned long); + static void ladspaConnectPort(LADSPA_Handle, unsigned long, LADSPA_Data *); + static void ladspaActivate(LADSPA_Handle); + static void ladspaRun(LADSPA_Handle, unsigned long); + static void ladspaDeactivate(LADSPA_Handle); + static void ladspaCleanup(LADSPA_Handle); - void reset(); - void runImpl(unsigned long); - float process(float); + float processSingle(float sample); void updateRMS(float); void updateParameters(); int m_sampleRate; - float *m_input; + const float *m_input; float *m_output; float *m_pgain;