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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
|
#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
#line 10 "pointer_cast_1910.xml"
#include <limits.h>
#include "ladspa-util.h"
#include "util/biquad.h"
typedef union {
LADSPA_Data fp;
int in;
} pcast;
#define POINTERCASTDISTORTION_CUTOFF 0
#define POINTERCASTDISTORTION_WET 1
#define POINTERCASTDISTORTION_INPUT 2
#define POINTERCASTDISTORTION_OUTPUT 3
static LADSPA_Descriptor *pointerCastDistortionDescriptor = NULL;
typedef struct {
LADSPA_Data *cutoff;
LADSPA_Data *wet;
LADSPA_Data *input;
LADSPA_Data *output;
biquad * filt;
float fs;
LADSPA_Data run_adding_gain;
} PointerCastDistortion;
_WINDOWS_DLL_EXPORT_
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
#ifdef WIN32
if (bIsFirstTime) {
_init();
bIsFirstTime = 0;
}
#endif
switch (index) {
case 0:
return pointerCastDistortionDescriptor;
default:
return NULL;
}
}
static void activatePointerCastDistortion(LADSPA_Handle instance) {
PointerCastDistortion *plugin_data = (PointerCastDistortion *)instance;
biquad *filt = plugin_data->filt;
float fs = plugin_data->fs;
#line 36 "pointer_cast_1910.xml"
biquad_init(filt);
plugin_data->filt = filt;
plugin_data->fs = fs;
}
static void cleanupPointerCastDistortion(LADSPA_Handle instance) {
#line 59 "pointer_cast_1910.xml"
PointerCastDistortion *plugin_data = (PointerCastDistortion *)instance;
free(plugin_data->filt);
free(instance);
}
static void connectPortPointerCastDistortion(
LADSPA_Handle instance,
unsigned long port,
LADSPA_Data *data) {
PointerCastDistortion *plugin;
plugin = (PointerCastDistortion *)instance;
switch (port) {
case POINTERCASTDISTORTION_CUTOFF:
plugin->cutoff = data;
break;
case POINTERCASTDISTORTION_WET:
plugin->wet = data;
break;
case POINTERCASTDISTORTION_INPUT:
plugin->input = data;
break;
case POINTERCASTDISTORTION_OUTPUT:
plugin->output = data;
break;
}
}
static LADSPA_Handle instantiatePointerCastDistortion(
const LADSPA_Descriptor *descriptor,
unsigned long s_rate) {
PointerCastDistortion *plugin_data = (PointerCastDistortion *)malloc(sizeof(PointerCastDistortion));
biquad *filt = NULL;
float fs;
#line 31 "pointer_cast_1910.xml"
filt = malloc(sizeof(biquad));
fs = s_rate;
plugin_data->filt = filt;
plugin_data->fs = fs;
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 runPointerCastDistortion(LADSPA_Handle instance, unsigned long sample_count) {
PointerCastDistortion *plugin_data = (PointerCastDistortion *)instance;
/* Effect cutoff freq (Hz) (float value) */
const LADSPA_Data cutoff = *(plugin_data->cutoff);
/* Dry/wet mix (float value) */
const LADSPA_Data wet = *(plugin_data->wet);
/* 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;
biquad * filt = plugin_data->filt;
float fs = plugin_data->fs;
#line 40 "pointer_cast_1910.xml"
unsigned long pos;
const float filt_scale = cutoff < 50.0f ? cutoff / 50.0f : 1.0f;
lp_set_params(filt, cutoff, 1.0f, fs);
for (pos = 0; pos < sample_count; pos++) {
pcast val;
float sign, filt_val, dist_val;
filt_val = biquad_run(filt, input[pos]) * filt_scale;
sign = filt_val < 0.0f ? -1.0f : 1.0f;
val.fp = fabs(filt_val);
dist_val = sign * (LADSPA_Data)val.in / (LADSPA_Data)INT_MAX +
(input[pos] - filt_val);
buffer_write(output[pos], LIN_INTERP(wet, input[pos], dist_val));
}
}
#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 setRunAddingGainPointerCastDistortion(LADSPA_Handle instance, LADSPA_Data gain) {
((PointerCastDistortion *)instance)->run_adding_gain = gain;
}
static void runAddingPointerCastDistortion(LADSPA_Handle instance, unsigned long sample_count) {
PointerCastDistortion *plugin_data = (PointerCastDistortion *)instance;
LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
/* Effect cutoff freq (Hz) (float value) */
const LADSPA_Data cutoff = *(plugin_data->cutoff);
/* Dry/wet mix (float value) */
const LADSPA_Data wet = *(plugin_data->wet);
/* 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;
biquad * filt = plugin_data->filt;
float fs = plugin_data->fs;
#line 40 "pointer_cast_1910.xml"
unsigned long pos;
const float filt_scale = cutoff < 50.0f ? cutoff / 50.0f : 1.0f;
lp_set_params(filt, cutoff, 1.0f, fs);
for (pos = 0; pos < sample_count; pos++) {
pcast val;
float sign, filt_val, dist_val;
filt_val = biquad_run(filt, input[pos]) * filt_scale;
sign = filt_val < 0.0f ? -1.0f : 1.0f;
val.fp = fabs(filt_val);
dist_val = sign * (LADSPA_Data)val.in / (LADSPA_Data)INT_MAX +
(input[pos] - filt_val);
buffer_write(output[pos], LIN_INTERP(wet, input[pos], dist_val));
}
}
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
pointerCastDistortionDescriptor =
(LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
if (pointerCastDistortionDescriptor) {
pointerCastDistortionDescriptor->UniqueID = 1910;
pointerCastDistortionDescriptor->Label = "pointerCastDistortion";
pointerCastDistortionDescriptor->Properties =
LADSPA_PROPERTY_HARD_RT_CAPABLE;
pointerCastDistortionDescriptor->Name =
D_("Pointer cast distortion");
pointerCastDistortionDescriptor->Maker =
"Steve Harris <steve@plugin.org.uk>";
pointerCastDistortionDescriptor->Copyright =
"GPL";
pointerCastDistortionDescriptor->PortCount = 4;
port_descriptors = (LADSPA_PortDescriptor *)calloc(4,
sizeof(LADSPA_PortDescriptor));
pointerCastDistortionDescriptor->PortDescriptors =
(const LADSPA_PortDescriptor *)port_descriptors;
port_range_hints = (LADSPA_PortRangeHint *)calloc(4,
sizeof(LADSPA_PortRangeHint));
pointerCastDistortionDescriptor->PortRangeHints =
(const LADSPA_PortRangeHint *)port_range_hints;
port_names = (char **)calloc(4, sizeof(char*));
pointerCastDistortionDescriptor->PortNames =
(const char **)port_names;
/* Parameters for Effect cutoff freq (Hz) */
port_descriptors[POINTERCASTDISTORTION_CUTOFF] =
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
port_names[POINTERCASTDISTORTION_CUTOFF] =
D_("Effect cutoff freq (Hz)");
port_range_hints[POINTERCASTDISTORTION_CUTOFF].HintDescriptor =
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_LOGARITHMIC | LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_DEFAULT_LOW;
port_range_hints[POINTERCASTDISTORTION_CUTOFF].LowerBound = 0.0001;
port_range_hints[POINTERCASTDISTORTION_CUTOFF].UpperBound = 0.3;
/* Parameters for Dry/wet mix */
port_descriptors[POINTERCASTDISTORTION_WET] =
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
port_names[POINTERCASTDISTORTION_WET] =
D_("Dry/wet mix");
port_range_hints[POINTERCASTDISTORTION_WET].HintDescriptor =
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
port_range_hints[POINTERCASTDISTORTION_WET].LowerBound = 0;
port_range_hints[POINTERCASTDISTORTION_WET].UpperBound = 1;
/* Parameters for Input */
port_descriptors[POINTERCASTDISTORTION_INPUT] =
LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
port_names[POINTERCASTDISTORTION_INPUT] =
D_("Input");
port_range_hints[POINTERCASTDISTORTION_INPUT].HintDescriptor = 0;
/* Parameters for Output */
port_descriptors[POINTERCASTDISTORTION_OUTPUT] =
LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[POINTERCASTDISTORTION_OUTPUT] =
D_("Output");
port_range_hints[POINTERCASTDISTORTION_OUTPUT].HintDescriptor = 0;
pointerCastDistortionDescriptor->activate = activatePointerCastDistortion;
pointerCastDistortionDescriptor->cleanup = cleanupPointerCastDistortion;
pointerCastDistortionDescriptor->connect_port = connectPortPointerCastDistortion;
pointerCastDistortionDescriptor->deactivate = NULL;
pointerCastDistortionDescriptor->instantiate = instantiatePointerCastDistortion;
pointerCastDistortionDescriptor->run = runPointerCastDistortion;
pointerCastDistortionDescriptor->run_adding = runAddingPointerCastDistortion;
pointerCastDistortionDescriptor->set_run_adding_gain = setRunAddingGainPointerCastDistortion;
}
}
void _fini() {
if (pointerCastDistortionDescriptor) {
free((LADSPA_PortDescriptor *)pointerCastDistortionDescriptor->PortDescriptors);
free((char **)pointerCastDistortionDescriptor->PortNames);
free((LADSPA_PortRangeHint *)pointerCastDistortionDescriptor->PortRangeHints);
free(pointerCastDistortionDescriptor);
}
}
|