-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannelSwitch.c
105 lines (88 loc) · 2.37 KB
/
channelSwitch.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
102
103
104
105
/* 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_a_ptr;
float* audio_out_b_ptr;
float* channel_ptr;
} channelSwitch;
/* internal core methods */
static LV2_Handle instantiate (const struct LV2_Descriptor *descriptor, double sample_rate, const char *bundle_path, const LV2_Feature *const *features){
channelSwitch* m = (channelSwitch*) calloc (1, sizeof (channelSwitch));
return m;
}
static void connect_port (LV2_Handle instance, uint32_t port, void *data_location){
channelSwitch* m = (channelSwitch*) instance;
if (!m) return;
switch (port){
case 0:
m->audio_in_ptr = (float*) data_location;
break;
case 1:
m->audio_out_a_ptr = (float*) data_location;
break;
case 2:
m->audio_out_b_ptr = (float*) data_location;
break;
case 3:
m->channel_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){
channelSwitch* m = (channelSwitch*) instance;
if (!m) return;
if ((!m->audio_in_ptr) || (!m->audio_out_a_ptr) || (!m->audio_out_b_ptr) || (!m->channel_ptr)) return;
for (uint32_t i = 0; i < sample_count; ++i){
if (*(m->channel_ptr) <= 0.5){
m->audio_out_a_ptr[i] = m->audio_in_ptr[i];
m->audio_out_b_ptr[i] = 0;
}
else{
m->audio_out_b_ptr[i] = m->audio_in_ptr[i];
m->audio_out_a_ptr[i] = 0;
}
}
}
static void deactivate (LV2_Handle instance)
{
/* not needed here */
}
static void cleanup (LV2_Handle instance)
{
channelSwitch* m = (channelSwitch*) 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/hmollercl/channelSwitch",
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;
}