1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
|
#include <stdlib.h>
#include <string.h>
#ifndef WIN32
#include "config.h"
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
#define _ISOC9X_SOURCE 1
#define _ISOC99_SOURCE 1
#define __USE_ISOC99 1
#define __USE_ISOC9X 1
#include <math.h>
#include "ladspa.h"
#ifdef WIN32
#define _WINDOWS_DLL_EXPORT_ __declspec(dllexport)
int bIsFirstTime = 1;
void _init(); // forward declaration
#else
#define _WINDOWS_DLL_EXPORT_
#endif
#define FOVERDRIVE_DRIVE 0
#define FOVERDRIVE_INPUT 1
#define FOVERDRIVE_OUTPUT 2
static LADSPA_Descriptor *foverdriveDescriptor = NULL;
typedef struct {
LADSPA_Data *drive;
LADSPA_Data *input;
LADSPA_Data *output;
LADSPA_Data run_adding_gain;
} Foverdrive;
_WINDOWS_DLL_EXPORT_
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
#ifdef WIN32
if (bIsFirstTime) {
_init();
bIsFirstTime = 0;
}
#endif
switch (index) {
case 0:
return foverdriveDescriptor;
default:
return NULL;
}
}
static void cleanupFoverdrive(LADSPA_Handle instance) {
free(instance);
}
static void connectPortFoverdrive(
LADSPA_Handle instance,
unsigned long port,
LADSPA_Data *data) {
Foverdrive *plugin;
plugin = (Foverdrive *)instance;
switch (port) {
case FOVERDRIVE_DRIVE:
plugin->drive = data;
break;
case FOVERDRIVE_INPUT:
plugin->input = data;
break;
case FOVERDRIVE_OUTPUT:
plugin->output = data;
break;
}
}
static LADSPA_Handle instantiateFoverdrive(
const LADSPA_Descriptor *descriptor,
unsigned long s_rate) {
Foverdrive *plugin_data = (Foverdrive *)malloc(sizeof(Foverdrive));
plugin_data->run_adding_gain = 1.0f;
return (LADSPA_Handle)plugin_data;
}
#undef buffer_write
#undef RUN_ADDING
#undef RUN_REPLACING
#define buffer_write(b, v) (b = v)
#define RUN_ADDING 0
#define RUN_REPLACING 1
static void runFoverdrive(LADSPA_Handle instance, unsigned long sample_count) {
Foverdrive *plugin_data = (Foverdrive *)instance;
/* Drive level (float value) */
const LADSPA_Data drive = *(plugin_data->drive);
/* Input (array of floats of length sample_count) */
const LADSPA_Data * const input = plugin_data->input;
/* Output (array of floats of length sample_count) */
LADSPA_Data * const output = plugin_data->output;
#line 16 "foverdrive_1196.xml"
unsigned long pos;
const float drivem1 = drive - 1.0f;
for (pos = 0; pos < sample_count; pos++) {
LADSPA_Data x = input[pos];
const float fx = fabs(x);
buffer_write(output[pos], x*(fx + drive)/(x*x + drivem1*fx + 1.0f));
}
}
#undef buffer_write
#undef RUN_ADDING
#undef RUN_REPLACING
#define buffer_write(b, v) (b += (v) * run_adding_gain)
#define RUN_ADDING 1
#define RUN_REPLACING 0
static void setRunAddingGainFoverdrive(LADSPA_Handle instance, LADSPA_Data gain) {
((Foverdrive *)instance)->run_adding_gain = gain;
}
static void runAddingFoverdrive(LADSPA_Handle instance, unsigned long sample_count) {
Foverdrive *plugin_data = (Foverdrive *)instance;
LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
/* Drive level (float value) */
const LADSPA_Data drive = *(plugin_data->drive);
/* Input (array of floats of length sample_count) */
const LADSPA_Data * const input = plugin_data->input;
/* Output (array of floats of length sample_count) */
LADSPA_Data * const output = plugin_data->output;
#line 16 "foverdrive_1196.xml"
unsigned long pos;
const float drivem1 = drive - 1.0f;
for (pos = 0; pos < sample_count; pos++) {
LADSPA_Data x = input[pos];
const float fx = fabs(x);
buffer_write(output[pos], x*(fx + drive)/(x*x + drivem1*fx + 1.0f));
}
}
void _init() {
char **port_names;
LADSPA_PortDescriptor *port_descriptors;
LADSPA_PortRangeHint *port_range_hints;
#ifdef ENABLE_NLS
#define D_(s) dgettext(PACKAGE, s)
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
#else
#define D_(s) (s)
#endif
foverdriveDescriptor =
(LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
if (foverdriveDescriptor) {
foverdriveDescriptor->UniqueID = 1196;
foverdriveDescriptor->Label = "foverdrive";
foverdriveDescriptor->Properties =
LADSPA_PROPERTY_HARD_RT_CAPABLE;
foverdriveDescriptor->Name =
D_("Fast overdrive");
foverdriveDescriptor->Maker =
"Steve Harris <steve@plugin.org.uk>";
foverdriveDescriptor->Copyright =
"GPL";
foverdriveDescriptor->PortCount = 3;
port_descriptors = (LADSPA_PortDescriptor *)calloc(3,
sizeof(LADSPA_PortDescriptor));
foverdriveDescriptor->PortDescriptors =
(const LADSPA_PortDescriptor *)port_descriptors;
port_range_hints = (LADSPA_PortRangeHint *)calloc(3,
sizeof(LADSPA_PortRangeHint));
foverdriveDescriptor->PortRangeHints =
(const LADSPA_PortRangeHint *)port_range_hints;
port_names = (char **)calloc(3, sizeof(char*));
foverdriveDescriptor->PortNames =
(const char **)port_names;
/* Parameters for Drive level */
port_descriptors[FOVERDRIVE_DRIVE] =
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
port_names[FOVERDRIVE_DRIVE] =
D_("Drive level");
port_range_hints[FOVERDRIVE_DRIVE].HintDescriptor =
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM;
port_range_hints[FOVERDRIVE_DRIVE].LowerBound = 1;
port_range_hints[FOVERDRIVE_DRIVE].UpperBound = 3;
/* Parameters for Input */
port_descriptors[FOVERDRIVE_INPUT] =
LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
port_names[FOVERDRIVE_INPUT] =
D_("Input");
port_range_hints[FOVERDRIVE_INPUT].HintDescriptor = 0;
/* Parameters for Output */
port_descriptors[FOVERDRIVE_OUTPUT] =
LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[FOVERDRIVE_OUTPUT] =
D_("Output");
port_range_hints[FOVERDRIVE_OUTPUT].HintDescriptor = 0;
foverdriveDescriptor->activate = NULL;
foverdriveDescriptor->cleanup = cleanupFoverdrive;
foverdriveDescriptor->connect_port = connectPortFoverdrive;
foverdriveDescriptor->deactivate = NULL;
foverdriveDescriptor->instantiate = instantiateFoverdrive;
foverdriveDescriptor->run = runFoverdrive;
foverdriveDescriptor->run_adding = runAddingFoverdrive;
foverdriveDescriptor->set_run_adding_gain = setRunAddingGainFoverdrive;
}
}
void _fini() {
if (foverdriveDescriptor) {
free((LADSPA_PortDescriptor *)foverdriveDescriptor->PortDescriptors);
free((char **)foverdriveDescriptor->PortNames);
free((LADSPA_PortRangeHint *)foverdriveDescriptor->PortRangeHints);
free(foverdriveDescriptor);
}
}
|