-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyAmp.c
101 lines (84 loc) · 1.81 KB
/
myAmp.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
94
95
96
97
98
99
100
101
/* include libs */
#include "stddef.h"
#include "stdint.h"
#include "stdlib.h"
//#include "math.h"
#include "lv2.h"
/* class definition */
typedef struct
{
float* audio_in_ptr;
float* audio_out_ptr;
float* amp_ptr;
} MyAmp;
/* internal core methods */
static LV2_Handle instantiate (const struct LV2_Descriptor *descriptor, double sample_rate, const char *bundle_path, const LV2_Feature *const *features)
{
MyAmp* m = (MyAmp*) calloc (1, sizeof (MyAmp));
return m;
}
static void connect_port (LV2_Handle instance, uint32_t port, void *data_location)
{
MyAmp* m = (MyAmp*) instance;
if (!m) return;
switch (port)
{
case 0:
m->audio_in_ptr = (float*) data_location;
break;
case 1:
m->audio_out_ptr = (float*) data_location;
break;
case 2:
m->amp_ptr = (float*) data_location;
break;
default:
break;
}
}
static void activate (LV2_Handle instance)
{
/* not needed here */
}
static void run (LV2_Handle instance, uint32_t sample_count)
{
MyAmp* m = (MyAmp*) instance;
if (!m) return;
if ((!m->audio_in_ptr) || (!m->audio_out_ptr) || (!m->amp_ptr)) return;
for (uint32_t i = 0; i <sample_count; ++i)
{
m->audio_out_ptr[i] = m->audio_in_ptr[i] * *(m->amp_ptr);
}
}
static void deactivate (LV2_Handle instance)
{
/* not needed here */
}
static void cleanup (LV2_Handle instance)
{
MyAmp* m = (MyAmp*) instance;
if (!m) return;
free (m);
}
static const void * extension_data (const char *uri)
{
return NULL;
}
/* descriptor */
static LV2_Descriptor const descriptor =
{
"https://github.com/Inqb8tr-jp/myAmp",
instantiate,
connect_port,
activate /* or NULL */,
run,
deactivate /* or NULL */,
cleanup,
extension_data /* or NULL */
};
/* interface */
const LV2_SYMBOL_EXPORT LV2_Descriptor* lv2_descriptor (uint32_t index)
{
if (index == 0) return &descriptor;
else return NULL;
}