Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ladspa.h"
- #include <math.h>
- #include <string.h>
- #define INPUT 0
- #define OUTPUT 1
- static LADSPA_Descriptor * descriptor;
- struct Distorter
- {
- LADSPA_Data * input;
- LADSPA_Data * output;
- unsigned long sample_rate;
- unsigned long position;
- LADSPA_Data run_adding_gain;
- };
- LADSPA_Handle instantiate_distorter(const LADSPA_Descriptor * descriptor, unsigned long sample_rate)
- {
- Distorter * distorter = NULL;
- distorter = new Distorter;
- distorter->sample_rate = sample_rate;
- distorter->run_adding_gain = 1.0f;
- LADSPA_Handle handle = distorter;
- return handle;
- }
- void connect_port_distorter(LADSPA_Handle instance, unsigned long port, LADSPA_Data * data_location)
- {
- Distorter * distorter = static_cast<Distorter*>(instance);
- switch(port)
- {
- case INPUT:
- distorter->input = data_location;
- break;
- case OUTPUT:
- distorter->output = data_location;
- break;
- }
- }
- void activate_distorter(LADSPA_Handle instance)
- {
- }
- void run_distorter(LADSPA_Handle instance, unsigned long sample_count)
- {
- Distorter * distorter = static_cast<Distorter*>(instance);
- for (unsigned long i = 0; i<sample_count; i++)
- {
- LADSPA_Data input = distorter->input[i];
- distorter->output[i] = input * 2.0f;
- if (distorter->output[i] > 0.5f)
- {
- distorter->output[i] = 0.5f;
- }
- if (distorter->output[i] < -0.5f)
- {
- distorter->output[i] = -0.5f;
- }
- if ((distorter->output[i] < 0.2f) && (distorter->output[i] > -0.2f))
- {
- distorter->output[i] = 0.0f;
- }
- }
- }
- void set_run_adding_gain_distorter(LADSPA_Handle instance, LADSPA_Data gain)
- {
- Distorter *distorter = static_cast<Distorter*>(instance);
- distorter->run_adding_gain = gain;
- }
- void cleanup_distorter(LADSPA_Handle instance)
- {
- Distorter * distorter = static_cast<Distorter*>(instance);
- delete distorter;
- }
- void
- delete_descriptor(LADSPA_Descriptor * descriptor) {
- delete descriptor->PortDescriptors;
- delete descriptor->PortNames;
- delete descriptor;
- }
- extern "C" __declspec(dllexport) const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index) {
- switch (Index) {
- case 0:
- static const char * label = "spark_distortion";
- static const char * maker = "Nick";
- static const char * copyright = "None";
- static const char * input_string = "Input";
- static const char * output_string = "Output";
- descriptor = new LADSPA_Descriptor;
- descriptor->UniqueID = 7778;
- descriptor->Label = label;
- descriptor->Properties= LADSPA_PROPERTY_HARD_RT_CAPABLE;
- descriptor->Name = label;
- descriptor->Maker = maker;
- descriptor->Copyright = copyright;
- descriptor->PortCount = 2;
- static LADSPA_PortDescriptor port_descriptors[2];
- descriptor->PortDescriptors = port_descriptors;
- port_descriptors[INPUT] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
- port_descriptors[OUTPUT] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
- static const char * port_names[2];
- descriptor->PortNames = port_names;
- port_names[INPUT] = input_string;
- port_names[OUTPUT] = output_string;
- descriptor->instantiate = &instantiate_distorter;
- descriptor->connect_port = &connect_port_distorter;
- descriptor->activate = &activate_distorter;
- descriptor->run = &run_distorter;
- descriptor->run_adding = NULL;
- descriptor->set_run_adding_gain = NULL;
- descriptor->deactivate = NULL;
- descriptor->cleanup = &cleanup_distorter;
- return descriptor;
- default:
- return NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement