/* * * This file was machine-generated by ladspapluginmaker 0.0d. * * This file comes with NO RESTRICTIONS OR WARRANTY. * * See http://www.ffem.org/gdam/ladspa.html for more details. */ #include "pluckedstring.h" #include #include #include enum { PLUGIN_input, PLUGIN_output, PLUGIN_igain_1, PLUGIN_pitch_1, PLUGIN_reverb_1, LAST_PLUGIN }; static LADSPA_Handle instantiate_plucked_string (const LADSPA_Descriptor* descriptor, unsigned long sample_rate) { PluckedString* plucked_string; plucked_string = (PluckedString*) calloc(sizeof(PluckedString), 1); if (plucked_string == NULL) return NULL; plucked_string->default_control_value_1 = 0.16046512; plucked_string->igain_1 = &(plucked_string->default_control_value_1); plucked_string->default_control_value_2 = 0.69767439; plucked_string->pitch_1 = &(plucked_string->default_control_value_2); plucked_string->base_delay_1 = (LADSPA_Data) 0.001743478 * sample_rate; plucked_string->delay_fluc_1 = (LADSPA_Data) 0.01200293 * sample_rate; plucked_string->max_delay_1 = ceil((LADSPA_Data)0.04644014 * sample_rate) + 1; plucked_string->buffer_1 = (LADSPA_Data*) calloc(sizeof(LADSPA_Data),plucked_string->max_delay_1); plucked_string->delay_buffer_1 = (LADSPA_Data*) calloc(sizeof(LADSPA_Data), 1); plucked_string->delay_index_1 = 0; plucked_string->default_control_value_3 = 0.020930231; plucked_string->reverb_1 = &(plucked_string->default_control_value_3); return plucked_string; } static void activate_plucked_string (LADSPA_Handle instance) { PluckedString* plucked_string; plucked_string = (PluckedString*) instance; plucked_string->igain_1 = &(plucked_string->default_control_value_1); plucked_string->pitch_1 = &(plucked_string->default_control_value_2); memset(plucked_string->buffer_1, 0, sizeof(LADSPA_Data) * plucked_string->max_delay_1); memset(plucked_string->delay_buffer_1, 0, sizeof(LADSPA_Data) * 1); plucked_string->delay_index_1 = 0; plucked_string->reverb_1 = &(plucked_string->default_control_value_3); } static void connect_port_plucked_string (LADSPA_Handle instance, unsigned long port, LADSPA_Data* data) { PluckedString* plucked_string = (PluckedString*) instance; switch (port) { case PLUGIN_input: plucked_string->input_buffer = data; break; case PLUGIN_output: plucked_string->output_buffer = data; break; case PLUGIN_igain_1: plucked_string->igain_1 = data; break; case PLUGIN_pitch_1: plucked_string->pitch_1 = data; break; case PLUGIN_reverb_1: plucked_string->reverb_1 = data; break; } } static void run_plucked_string (LADSPA_Handle instance, unsigned long length) { PluckedString* plucked_string = (PluckedString*) instance; unsigned long i; LADSPA_Data control_output_1; LADSPA_Data* input_buffer = plucked_string->input_buffer; LADSPA_Data input_output_1; LADSPA_Data modulator_output_1; LADSPA_Data control_output_2; LADSPA_Data* buffer_1; int buffer_index_1; float base_delay_1; float delay_fluc_1; int max_delay_1; float delay_length_1; float delay_frac_1; int delay_whole_1; int delay_index_1; int last_delay_index_1; float allpass_coeff_1; LADSPA_Data variable_delay_output_1; LADSPA_Data gain_output_1; int delay_index_2; LADSPA_Data* delay_buffer_1; LADSPA_Data delay_output_1; LADSPA_Data mix_output_1; LADSPA_Data* output_buffer = plucked_string->output_buffer; LADSPA_Data control_output_3; LADSPA_Data constant_output_1; LADSPA_Data mix_output_2; LADSPA_Data modulator_output_2; control_output_1 = *(plucked_string->igain_1); control_output_2 = *(plucked_string->pitch_1); buffer_1 = plucked_string->buffer_1; buffer_index_1 = plucked_string->buffer_index_1; base_delay_1 = plucked_string->base_delay_1; delay_fluc_1 = plucked_string->delay_fluc_1; max_delay_1 = plucked_string->max_delay_1; delay_length_1 = base_delay_1 + delay_fluc_1 * control_output_2; delay_whole_1 = floor(delay_length_1); delay_frac_1 = delay_length_1 - delay_whole_1; variable_delay_output_1 = plucked_string->last_output_1; delay_index_1 = (buffer_index_1 - delay_whole_1) % max_delay_1; if (delay_index_1 < 0) delay_index_1 += max_delay_1; last_delay_index_1 = delay_index_1 - 1; if (last_delay_index_1 < 0) last_delay_index_1 += max_delay_1; allpass_coeff_1 = (1.0 - delay_frac_1) / (1.0 + delay_frac_1); delay_index_2 = plucked_string->delay_index_1; delay_buffer_1 = plucked_string->delay_buffer_1; control_output_3 = *(plucked_string->reverb_1); constant_output_1 = 0.707059; for (i = 0; i < length; i++) { input_output_1 = input_buffer[i]; modulator_output_1 = control_output_1 * input_output_1; variable_delay_output_1 = (-allpass_coeff_1) * variable_delay_output_1 + buffer_1[last_delay_index_1] + allpass_coeff_1 * buffer_1[delay_index_1]; last_delay_index_1 = delay_index_1; if (++delay_index_1 >= max_delay_1) delay_index_1 = 0; gain_output_1 = variable_delay_output_1 * 0.581395; delay_output_1 = delay_buffer_1[delay_index_2]; mix_output_1 = modulator_output_1 + gain_output_1 + delay_output_1; output_buffer[i] = mix_output_1; mix_output_2 = control_output_3 + constant_output_1; modulator_output_2 = mix_output_2 * mix_output_1; buffer_1[buffer_index_1++] = modulator_output_2; if (buffer_index_1 == max_delay_1) buffer_index_1 = 0; delay_buffer_1[delay_index_2] = gain_output_1; if (++delay_index_2 == 1) delay_index_2 = 0; } plucked_string->buffer_index_1 = buffer_index_1; plucked_string->last_output_1 = variable_delay_output_1; plucked_string->delay_index_1 = delay_index_2; } static void cleanup_plucked_string (LADSPA_Handle instance) { PluckedString* plucked_string; plucked_string = (PluckedString*) instance; free(plucked_string->buffer_1); free(plucked_string->delay_buffer_1); free(instance); } const LADSPA_Descriptor* ladspa_descriptor(unsigned long index) { static LADSPA_Descriptor* the_descriptor = NULL; LADSPA_PortDescriptor* port_descriptors; LADSPA_PortRangeHint* port_range_hints; char** port_names; if (index != 0) return NULL; if (the_descriptor != NULL) return the_descriptor; the_descriptor = (LADSPA_Descriptor*) malloc(sizeof(LADSPA_Descriptor)); if (the_descriptor == NULL) return NULL; port_descriptors = (LADSPA_PortDescriptor*) calloc(sizeof(LADSPA_PortDescriptor), 5); port_range_hints = (LADSPA_PortRangeHint*) calloc(sizeof(LADSPA_PortRangeHint), 5); port_names = (char**) calloc(sizeof(char*), 5); if (port_descriptors == NULL || port_range_hints == NULL || port_names == NULL) { if (port_descriptors != NULL) free(port_descriptors); if (port_range_hints != NULL) free(port_range_hints); if (port_names != NULL) free(port_names); return NULL; } /* * Initialize the descriptor's members. */ the_descriptor->UniqueID = 10; the_descriptor->Label = "PluckedString"; the_descriptor->Properties = 0; the_descriptor->Name = "Karplus-Strong Plucked-String Filter"; the_descriptor->Maker = "gdam ladspa plugin maker"; the_descriptor->Copyright = "None"; the_descriptor->PortCount = 5; the_descriptor->PortDescriptors = port_descriptors; the_descriptor->PortRangeHints = port_range_hints; the_descriptor->PortNames = (const char*const*) port_names; /* The virtual functions. */ the_descriptor->instantiate = instantiate_plucked_string; the_descriptor->connect_port = connect_port_plucked_string; the_descriptor->activate = activate_plucked_string; the_descriptor->run = run_plucked_string; the_descriptor->run_adding = NULL; the_descriptor->set_run_adding_gain = NULL; the_descriptor->deactivate = NULL; the_descriptor->cleanup = cleanup_plucked_string; /* * Initialize the port names. */ port_names[PLUGIN_input] = "Input"; port_names[PLUGIN_output] = "Output"; port_names[PLUGIN_igain_1] = "Input Gain"; port_names[PLUGIN_pitch_1] = "Pitch Control"; port_names[PLUGIN_reverb_1] = "Reverbation"; /* * Initialize the port descriptors. */ port_descriptors[PLUGIN_input] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO; port_descriptors[PLUGIN_output] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO; port_descriptors[PLUGIN_igain_1] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL; port_descriptors[PLUGIN_pitch_1] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL; port_descriptors[PLUGIN_reverb_1] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL; /* * Initialize the port range hints. */ port_range_hints[PLUGIN_input].HintDescriptor = 0; port_range_hints[PLUGIN_output].HintDescriptor = 0; port_range_hints[PLUGIN_igain_1].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE; port_range_hints[PLUGIN_igain_1].LowerBound = 0; port_range_hints[PLUGIN_igain_1].UpperBound = 1; port_range_hints[PLUGIN_pitch_1].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE; port_range_hints[PLUGIN_pitch_1].LowerBound = 0; port_range_hints[PLUGIN_pitch_1].UpperBound = 1; port_range_hints[PLUGIN_reverb_1].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE; port_range_hints[PLUGIN_reverb_1].LowerBound = -0.5; port_range_hints[PLUGIN_reverb_1].UpperBound = 0.5; return the_descriptor; }