Last active
August 29, 2015 14:15
-
-
Save falkTX/45f8c2f441bc37848583 to your computer and use it in GitHub Desktop.
eg-amp c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lv2.hpp" | |
#include <cmath> // for std::pow | |
// #define AMP_URI "http://lv2plug.in/plugins/eg-amp" | |
/** Define a macro for converting a gain in dB to a coefficient. */ | |
#define DB_CO(g) ((g) > -90.0f ? std::pow(10.0f, (g) * 0.05f) : 0.0f) | |
class EG_Amp : public LV2_Plugin | |
{ | |
public: | |
EG_Amp(double sampleRate, const char* bundlePath) | |
: LV2_Plugin(sampleRate, bundlePath) {} | |
protected: | |
void connectPort(uint32_t port, void* dataLocation) override | |
{ | |
buffers.connectPort(port, dataLocation); | |
} | |
void run(uint32_t sampleCount) | |
{ | |
const float coef = DB_CO(*buffers.gain); | |
for (uint32_t i = 0; i < sampleCount; ++i) | |
buffers.output[i] = buffers.input[i] * coef; | |
} | |
private: | |
enum PortIndexes { | |
kPortGain = 0, | |
kPortInput = 1, | |
kPortOutput = 2 | |
}; | |
struct PortBuffers { | |
const float* gain; | |
const float* input; | |
float* output; | |
PortBuffers() | |
: gain(nullptr), | |
input(nullptr), | |
output(nullptr) {} | |
void connectPort(uint32_t port, void* dataLocation) | |
{ | |
switch (port) | |
{ | |
case kPortGain: | |
gain = (const float*)dataLocation; | |
break; | |
case kPortInput: | |
input = (const float*)dataLocation; | |
break; | |
case kPortOutput: | |
output = (float*)dataLocation; | |
break; | |
} | |
} | |
}; | |
PortBuffers buffers; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment