-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudio-link.cpp
180 lines (157 loc) · 3.72 KB
/
studio-link.cpp
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
#include "studio-link.h"
#include "re/re.h"
#include "baresip.h"
#define DEFAULT_PROG "Default"
#define UNIQUE_ID 'studiolinkonair'
#define EFFECT_NAME "StudioLinkOnAir"
#define PRODUCT_STRING "StudioLinkOnAir"
#define VENDOR_STRING "IT-Service Sebastian Reimers"
#define VENDOR_VERSION 1
#define MAX_GAIN 1
#ifdef WINDOWS
DWORD dwThreadId;
HANDLE hThread;
#else
#include <pthread.h>
pthread_t tid;
#endif
bool running = false;
static void ua_exit_handler(void *arg)
{
(void)arg;
debug("ua exited -- stopping main runloop\n");
/* The main run-loop can be stopped now */
re_cancel();
}
#ifdef WINDOWS
DWORD WINAPI MyThreadFunction(LPVOID lpParam)
{
re_main(NULL);
warning("EXIT THREAD\n");
return 0;
}
#endif
AudioEffect* createEffectInstance(audioMasterCallback audioMaster)
{
return new vstplugin (audioMaster);
}
// Constructor
vstplugin::vstplugin(audioMasterCallback audiomaster)
: AudioEffectX(audioMaster, 1,1)
{
#ifdef WINDOWS
DWORD dwThreadId, dwThrdParam = 1;
#endif
setNumInputs(2);
setNumOutputs(2);
setUniqueID(UNIQUE_ID);
canProcessReplacing();
resume();
vst_strncpy(programName,DEFAULT_PROG,kVstMaxProgNameLen);
if (!running) {
(void)sys_coredump_set(true);
libre_init();
conf_configure(false);
baresip_init(conf_config());
ua_init("baresip v" BARESIP_VERSION " (" ARCH "/" OS ")",
true, true, true);
conf_modules();
uag_set_exit_handler(ua_exit_handler, NULL);
#ifdef WINDOWS
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadFunction, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
#else
pthread_create(&tid, NULL, (void*(*)(void*))&re_main, NULL);
#endif
sys_msleep(200);
running = true;
}
gain = 1;
}
// Destructor
vstplugin::~vstplugin()
{
if (running) {
ua_stop_all(false);
#ifdef WINDOWS
WaitForSingleObject(hThread, 2000);
TerminateThread(hThread, NULL);
#else
sys_msleep(500);
#endif
ua_close();
module_app_unload();
conf_close();
baresip_close();
mod_close();
libre_close();
tmr_debug();
mem_debug();
#ifdef WINDOWS
CloseHandle(hThread);
#endif
running = false;
}
}
// Processing
void vstplugin::processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames)
{
float *input0 = inputs[0];
float *output0 = outputs[0];
float *input1 = inputs[1];
float *output1 = outputs[1];
effectlive_src(input0, input1, sampleFrames);
}
//Parameters
void vstplugin::setParameter(VstInt32 index, float value)
{
gain = value*MAX_GAIN;
}
float vstplugin::getParameter(VstInt32 index)
{
float param = 0.0;
param = gain/MAX_GAIN;
return param;
}
void vstplugin::getParameterName(VstInt32 index, char* label)
{
vst_strncpy(label,"Gain",kVstMaxParamStrLen);
}
void vstplugin::getParameterDisplay(VstInt32 index, char* text)
{
dB2string(gain, text, kVstMaxParamStrLen);
}
void vstplugin::getParameterLabel(VstInt32 index, char* label)
{
vst_strncpy(label, "dB", kVstMaxParamStrLen);
}
// Plugin name set/get
void vstplugin::setProgramName(char* name)
{
vst_strncpy(programName, name, kVstMaxProgNameLen);
}
void vstplugin::getProgramName(char* name)
{
vst_strncpy(name, programName, kVstMaxProgNameLen);
}
//VST host functions
bool vstplugin::getEffectName(char* name) {
vst_strncpy (name, EFFECT_NAME, kVstMaxEffectNameLen);
return true;
}
bool vstplugin::getProductString(char* text) {
vst_strncpy (text, PRODUCT_STRING, kVstMaxProductStrLen);
return true;
}
bool vstplugin::getVendorString(char* text) {
vst_strncpy (text, VENDOR_STRING, kVstMaxVendorStrLen);
return true;
}
VstInt32 vstplugin::getVendorVersion() {
return VENDOR_VERSION;
}