#include #include typedef struct plugin { float gain; char bypass; size_t delay; float sample_rate; size_t delay_line_length; float * delay_line; size_t delay_line_cur; } plugin; static void plugin_init(plugin *instance) { instance->gain = 1.f; instance->bypass = 0; } static void plugin_fini(plugin *instance) { } static void plugin_set_sample_rate(plugin *instance, float sample_rate) { instance->sample_rate = sample_rate; instance->delay_line_length = ceilf(sample_rate) + 1; } static size_t plugin_mem_req(plugin *instance) { return instance->delay_line_length * sizeof(float); } static void plugin_mem_set(plugin *instance, void *mem) { instance->delay_line = mem; } static void plugin_reset(plugin *instance) { memset(instance->delay_line, 0, instance->delay_line_length * sizeof(float)); instance->delay_line_cur = 0; } static void plugin_set_parameter(plugin *instance, size_t index, float value) { switch (index) { case 0: instance->gain = value; break; case 1: instance->delay = roundf(instance->sample_rate * 0.001f * value); break; case 2: instance->bypass = value >= 0.5f; break; } } static float plugin_get_parameter(plugin *instance, size_t index) { // no output parameters return 0.f; } static size_t calc_index(size_t cur, size_t delay, size_t len) { return (cur < delay ? cur + len : cur) - delay; } static void plugin_process(plugin *instance, const float **inputs, float **outputs, size_t n_samples) { const float g = powf(10.f, 0.05f * instance->gain); for (size_t i = 0; i < n_samples; i++) { instance->delay_line[instance->delay_line_cur] = inputs[0][i]; const float y = g * instance->delay_line[calc_index(instance->delay_line_cur, instance->delay, instance->delay_line_length)]; instance->delay_line_cur++; if (instance->delay_line_cur == instance->delay_line_length) instance->delay_line_cur = 0; outputs[0][i] = instance->bypass ? inputs[0][i] : y; } }