-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnap-smash.c
93 lines (74 loc) · 1.81 KB
/
nap-smash.c
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
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "lv2.h"
#define AMP_URI "https://lv2.naptastic.com/nap-smash.lv2";
#define AMP_INPUT 0
#define AMP_OUTPUT 1
static LV2_Descriptor *ampDescriptor = NULL;
typedef struct {
float *input;
float *output;
} Amp;
static void cleanupAmp(LV2_Handle instance)
{
free(instance);
}
static void connectPortAmp(LV2_Handle instance, uint32_t port,
void *data)
{
Amp *plugin = (Amp *)instance;
switch (port) {
case AMP_INPUT:
plugin->input = data;
break;
case AMP_OUTPUT:
plugin->output = data;
break;
}
}
static LV2_Handle instantiateAmp(const LV2_Descriptor *descriptor,
double s_rate, const char *path,
const LV2_Feature * const* features)
{
Amp *plugin_data = (Amp *)malloc(sizeof(Amp));
return (LV2_Handle)plugin_data;
}
#define DB_CO(g) ((g) > -90.0f ? powf(10.0f, (g) * 0.05f) : 0.0f)
static void runAmp(LV2_Handle instance, uint32_t sample_count)
{
Amp *plugin_data = (Amp *)instance;
const float * const input = plugin_data->input;
float * const output = plugin_data->output;
int pos;
float amp;
for (pos = 0; pos < sample_count; pos++) {
amp = input[pos] * 4;
amp = amp - pow( amp, 3 ) / 3;
output[pos] = amp;
}
}
static void init()
{
ampDescriptor =
(LV2_Descriptor *)malloc(sizeof(LV2_Descriptor));
ampDescriptor->URI = AMP_URI;
ampDescriptor->activate = NULL;
ampDescriptor->cleanup = cleanupAmp;
ampDescriptor->connect_port = connectPortAmp;
ampDescriptor->deactivate = NULL;
ampDescriptor->instantiate = instantiateAmp;
ampDescriptor->run = runAmp;
ampDescriptor->extension_data = NULL;
}
LV2_SYMBOL_EXPORT
const LV2_Descriptor *lv2_descriptor(uint32_t index)
{
if (!ampDescriptor) init();
switch (index) {
case 0:
return ampDescriptor;
default:
return NULL;
}
}