white noise generator
This commit is contained in:
parent
191a384483
commit
a05477f429
4 changed files with 102 additions and 1 deletions
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@ DISTNAME = crap
|
|||
VERSION = git
|
||||
|
||||
EXE = design
|
||||
SHOBJ = crap_eq.so crap_eq_const.so
|
||||
SHOBJ = crap_eq.so crap_eq_const.so crap_noise.so
|
||||
MID =
|
||||
HEADERS = crap_util.h crap_util_def.h ladspa.h
|
||||
|
||||
|
|
84
crap_noise.c
Executable file
84
crap_noise.c
Executable file
|
@ -0,0 +1,84 @@
|
|||
#include "ladspa.h"
|
||||
#include "crap_util.h"
|
||||
|
||||
typedef unsigned long ulong;
|
||||
|
||||
#define PLUG_INPUT 0
|
||||
#define PLUG_OUTPUT 1
|
||||
#define PCOUNT 2
|
||||
|
||||
const LADSPA_PortDescriptor p_discs[PCOUNT] = {
|
||||
LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO,
|
||||
LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO
|
||||
};
|
||||
const LADSPA_PortRangeHint p_hints[PCOUNT] = {
|
||||
{.HintDescriptor = 0},
|
||||
{.HintDescriptor = 0}
|
||||
};
|
||||
const char *p_names[PCOUNT] = {"Input", "Output"};
|
||||
|
||||
typedef struct {
|
||||
LADSPA_Data *input;
|
||||
LADSPA_Data *output;
|
||||
LADSPA_Data fs;
|
||||
} plug_t;
|
||||
|
||||
static void
|
||||
plug_cleanup(LADSPA_Handle instance) {
|
||||
free(instance);
|
||||
}
|
||||
|
||||
static void
|
||||
plug_connect(LADSPA_Handle instance, ulong port, LADSPA_Data *data) {
|
||||
plug_t *plug = (plug_t *)instance;
|
||||
if (port == PLUG_INPUT)
|
||||
plug->input = data;
|
||||
else if (port == PLUG_OUTPUT)
|
||||
plug->output = data;
|
||||
}
|
||||
|
||||
static LADSPA_Handle
|
||||
plug_instantiate(const LADSPA_Descriptor *descriptor, ulong s_rate) {
|
||||
plug_t *plug = (plug_t *) calloc(1, sizeof(plug_t));
|
||||
plug->fs = s_rate;
|
||||
return (LADSPA_Handle) plug;
|
||||
}
|
||||
|
||||
static void
|
||||
plug_run(LADSPA_Handle instance, ulong sample_count) {
|
||||
plug_t *plug = (plug_t *) instance;
|
||||
//const LADSPA_Data *input = plug->input;
|
||||
LADSPA_Data *output = plug->output;
|
||||
|
||||
for (ulong pos = 0; pos < sample_count; pos++)
|
||||
output[pos] = whitenoise();
|
||||
}
|
||||
|
||||
static const LADSPA_Descriptor eqDescriptor = {
|
||||
.UniqueID = 0xEC57A71C,
|
||||
.Label = "crap_noise",
|
||||
.Properties = 0,
|
||||
.Name = "crap noise generator",
|
||||
.Maker = "Connor Olding",
|
||||
.Copyright = "MIT",
|
||||
.PortCount = PCOUNT,
|
||||
.PortDescriptors = p_discs,
|
||||
.PortRangeHints = p_hints,
|
||||
.PortNames = p_names,
|
||||
|
||||
.activate = NULL,
|
||||
.cleanup = plug_cleanup,
|
||||
.connect_port = plug_connect,
|
||||
.deactivate = NULL,
|
||||
.instantiate = plug_instantiate,
|
||||
.run = plug_run,
|
||||
.run_adding = NULL,
|
||||
.set_run_adding_gain = NULL
|
||||
};
|
||||
|
||||
const LADSPA_Descriptor *
|
||||
ladspa_descriptor(ulong index) {
|
||||
if (index != 0)
|
||||
return NULL;
|
||||
return &eqDescriptor;
|
||||
}
|
|
@ -23,6 +23,9 @@ typedef struct {
|
|||
double b0, b1, b2, a0, a1, a2;
|
||||
} biquad_interim;
|
||||
|
||||
static float
|
||||
whitenoise();
|
||||
|
||||
static void
|
||||
biquad_init(biquad *bq);
|
||||
|
||||
|
|
|
@ -2,6 +2,20 @@
|
|||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* via http://www.rgba.org/articles/sfrand/sfrand.htm */
|
||||
static unsigned int mirand = 1;
|
||||
|
||||
static float
|
||||
whitenoise() {
|
||||
union either {
|
||||
float f;
|
||||
unsigned int i;
|
||||
} white;
|
||||
mirand *= 16807;
|
||||
white.i = (mirand & 0x007FFFFF) | 0x40000000;
|
||||
return white.f - 3;
|
||||
}
|
||||
|
||||
/* used to resemble https://github.com/swh/ladspa/blob/master/util/biquad.h */
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue