-
Notifications
You must be signed in to change notification settings - Fork 13
/
virtual_int.h
315 lines (271 loc) · 9.69 KB
/
virtual_int.h
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*-
* Copyright (c) 2012-2022 Hans Petter Selasky
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _VIRTUAL_INT_H_
#define _VIRTUAL_INT_H_
#include <samplerate.h>
#define VMAX_CHAN 64
#define VMAX_STRING 64 /* characters */
#define VTYPE_OSS_DAT 0
#define VTYPE_WAV_HDR 1
#define VTYPE_WAV_DAT 2
#define VPREFERRED_SNE_AFMT \
(AFMT_S8 | AFMT_S16_NE | AFMT_S24_NE | AFMT_S32_NE)
#define VPREFERRED_UNE_AFMT \
(AFMT_U8 | AFMT_U16_NE | AFMT_U24_NE | AFMT_U32_NE)
#define VPREFERRED_SLE_AFMT \
(AFMT_S8 | AFMT_S16_LE | AFMT_S24_LE | AFMT_S32_LE)
#define VPREFERRED_SBE_AFMT \
(AFMT_S8 | AFMT_S16_BE | AFMT_S24_BE | AFMT_S32_BE)
#define VPREFERRED_ULE_AFMT \
(AFMT_U8 | AFMT_U16_LE | AFMT_U24_LE | AFMT_U32_LE)
#define VPREFERRED_UBE_AFMT \
(AFMT_U8 | AFMT_U16_BE | AFMT_U24_BE | AFMT_U32_BE)
#define VSUPPORTED_AFMT \
(AFMT_S16_BE | AFMT_S16_LE | AFMT_U16_BE | AFMT_U16_LE | \
AFMT_S24_BE | AFMT_S24_LE | AFMT_U24_BE | AFMT_U24_LE | \
AFMT_S32_BE | AFMT_S32_LE | AFMT_U32_BE | AFMT_U32_LE | \
AFMT_U8 | AFMT_S8)
#define VVOLUME_UNIT_SHIFT 7
struct virtual_profile;
#if 0
{
#endif
typedef TAILQ_ENTRY(virtual_profile) vprofile_entry_t;
typedef TAILQ_HEAD(, virtual_profile) vprofile_head_t;
typedef struct virtual_profile vprofile_t;
struct virtual_client;
typedef TAILQ_ENTRY(virtual_client) vclient_entry_t;
typedef TAILQ_HEAD(, virtual_client) vclient_head_t;
typedef struct virtual_client vclient_t;
struct virtual_monitor;
typedef TAILQ_ENTRY(virtual_monitor) vmonitor_entry_t;
typedef TAILQ_HEAD(, virtual_monitor) vmonitor_head_t;
typedef struct virtual_monitor vmonitor_t;
struct virtual_resample;
typedef struct virtual_resample vresample_t;
#if 0
}
#endif
struct cuse_methods;
struct virtual_compressor {
uint8_t enabled; /* 0..1 */
uint8_t knee; /* 0..255 */
uint8_t attack; /* 0..62 */
uint8_t decay; /* 0..62 */
};
struct virtual_profile {
vprofile_entry_t entry;
vclient_head_t head;
char oss_name[VMAX_STRING];
char wav_name[VMAX_STRING];
uint32_t rx_filter_size;
uint32_t tx_filter_size;
double *rx_filter_data[VMAX_CHAN];
double *tx_filter_data[VMAX_CHAN];
int64_t rx_peak_value[VMAX_CHAN];
int64_t tx_peak_value[VMAX_CHAN];
int8_t rx_shift[VMAX_CHAN];
int8_t tx_shift[VMAX_CHAN];
uint8_t rx_src[VMAX_CHAN];
uint8_t tx_dst[VMAX_CHAN];
uint8_t rx_mute[VMAX_CHAN];
uint8_t tx_mute[VMAX_CHAN];
uint8_t rx_pol[VMAX_CHAN];
uint8_t tx_pol[VMAX_CHAN];
uint8_t bits;
uint8_t channels;
struct virtual_compressor rx_compressor_param;
double rx_compressor_gain[VMAX_CHAN];
uint8_t synchronized;
uint32_t rec_delay;
int fd_sta;
struct {
const char * host;
const char * port;
const char * rtp_ifname;
const char * rtp_port;
volatile struct http_state * state;
size_t nstate;
int rtp_fd;
int rtp_vlanid;
uint32_t rtp_ts;
uint16_t rtp_seqnum;
} http;
};
struct virtual_ring {
uint8_t *buf_start;
uint32_t pos_read;
uint32_t total_size;
uint32_t len_write;
};
struct virtual_resample {
SRC_DATA data;
SRC_STATE *state;
float *data_in;
float *data_out;
};
struct virtual_client {
vclient_entry_t entry;
uint32_t tx_filter_offset;
uint32_t rx_filter_offset;
int64_t *tx_filter_in[VMAX_CHAN];
int64_t *rx_filter_in[VMAX_CHAN];
double *tx_filter_out[VMAX_CHAN];
double *rx_filter_out[VMAX_CHAN];
struct virtual_ring rx_ring[2];
struct virtual_ring tx_ring[2];
vresample_t rx_resample;
vresample_t tx_resample;
struct virtual_profile *profile;
uint64_t rx_samples;
uint64_t rx_timestamp;
uint64_t tx_samples;
uint64_t tx_timestamp;
uint32_t buffer_frags;
uint32_t buffer_size;
uint32_t low_water;
uint32_t rec_delay;
uint32_t rx_noise_rem;
uint32_t tx_noise_rem;
int rx_busy;
int tx_busy;
int channels;
int format;
int rx_enabled;
int tx_enabled;
int rx_volume;
int tx_volume;
int type; /* VTYPE_XXX */
int sample_rate;
int buffer_size_set:1;
int buffer_frags_set:1;
int sync_busy:1;
int sync_wakeup:1;
int padding:28;
};
struct virtual_monitor {
vmonitor_entry_t entry;
int64_t peak_value;
uint8_t src_chan;
uint8_t dst_chan;
uint8_t pol;
uint8_t mute;
int8_t shift;
};
extern vprofile_head_t virtual_profile_client_head;
extern vprofile_head_t virtual_profile_loopback_head;
extern vmonitor_head_t virtual_monitor_input;
extern vmonitor_head_t virtual_monitor_local;
extern vmonitor_head_t virtual_monitor_output;
extern const struct cuse_methods vctl_methods;
extern struct virtual_compressor voss_output_compressor_param;
extern double voss_output_compressor_gain[VMAX_CHAN];
extern int64_t voss_output_peak[VMAX_CHAN];
extern int64_t voss_input_peak[VMAX_CHAN];
extern uint32_t voss_jitter_up;
extern uint32_t voss_jitter_down;
extern uint32_t voss_max_channels;
extern uint32_t voss_mix_channels;
extern uint32_t voss_dsp_samples;
extern uint32_t voss_dsp_max_channels;
extern uint32_t voss_dsp_sample_rate;
extern uint32_t voss_dsp_bits;
extern uint8_t voss_libsamplerate_enable;
extern uint8_t voss_libsamplerate_quality;
extern int voss_is_recording;
extern int voss_has_synchronization;
extern char voss_dsp_rx_device[VMAX_STRING];
extern char voss_dsp_tx_device[VMAX_STRING];
extern char voss_ctl_device[VMAX_STRING];
extern char voss_sta_device[VMAX_STRING];
extern void atomic_lock(void);
extern void atomic_unlock(void);
extern void atomic_wait(void);
extern void atomic_wakeup(void);
extern int vring_alloc(struct virtual_ring *, size_t);
extern void vring_free(struct virtual_ring *);
extern void vring_reset(struct virtual_ring *);
extern void vring_get_read(struct virtual_ring *, uint8_t **, size_t *);
extern void vring_get_write(struct virtual_ring *, uint8_t **, size_t *);
extern void vring_inc_read(struct virtual_ring *, size_t);
extern void vring_inc_write(struct virtual_ring *, size_t);
extern size_t vring_total_read_len(struct virtual_ring *);
extern size_t vring_total_write_len(struct virtual_ring *);
extern size_t vring_write_linear(struct virtual_ring *, const uint8_t *, size_t);
extern size_t vring_read_linear(struct virtual_ring *, uint8_t *, size_t);
extern size_t vring_write_zero(struct virtual_ring *, size_t);
extern vclient_t *vclient_alloc(void);
extern void vclient_free(vclient_t *);
extern int vclient_get_default_fmt(vprofile_t *, int type);
extern int vclient_setup_buffers(vclient_t *, int size, int frags,
int channels, int format, int sample_rate);
extern int vclient_export_read_locked(vclient_t *);
extern void vclient_import_write_locked(vclient_t *);
extern uint32_t vclient_sample_bytes(vclient_t *);
extern uint32_t vclient_bufsize_internal(vclient_t *);
extern uint32_t vclient_bufsize_scaled(vclient_t *);
extern int64_t vclient_noise(uint32_t *, int64_t, int8_t);
extern vmonitor_t *vmonitor_alloc(int *, vmonitor_head_t *);
extern uint32_t format_best(uint32_t);
extern void format_import(uint32_t, const uint8_t *, uint32_t, int64_t *);
extern void format_export(uint32_t, const int64_t *, uint8_t *, uint32_t);
extern int64_t format_max(uint32_t);
extern void format_maximum(const int64_t *, int64_t *, uint32_t, uint32_t, int8_t);
extern void format_remix(int64_t *, uint32_t, uint32_t, uint32_t);
extern void format_silence(uint32_t, uint8_t *, uint32_t);
extern void *virtual_oss_process(void *);
/* Audio Delay prototypes */
extern uint32_t voss_ad_last_delay;
extern uint32_t voss_dsp_rx_refresh;
extern uint32_t voss_dsp_tx_refresh;
extern uint8_t voss_ad_enabled;
extern uint8_t voss_ad_output_signal;
extern uint8_t voss_ad_input_channel;
extern uint8_t voss_ad_output_channel;
extern void voss_ad_reset(void);
extern void voss_ad_init(uint32_t);
extern double voss_ad_getput_sample(double);
/* Add audio options prototype */
extern void voss_add_options(char *);
/* Get current timestamp */
extern uint64_t virtual_oss_delay_ns(void);
extern void virtual_oss_wait(void);
extern uint64_t virtual_oss_timestamp(void);
/* Fast array multiplication */
extern void voss_x3_multiply_double(const int64_t *, const double *, double *, const size_t);
/* Equalizer support */
extern void vclient_tx_equalizer(struct virtual_client *, int64_t *, size_t);
extern void vclient_rx_equalizer(struct virtual_client *, int64_t *, size_t);
extern int vclient_eq_alloc(struct virtual_client *);
extern void vclient_eq_free(struct virtual_client *);
/* Internal utilities */
extern int bt_speaker_main(int argc, char **argv);
extern int equalizer_main(int argc, char **argv);
/* Internal compressor */
extern void voss_compressor(int64_t *, double *, const struct virtual_compressor *,
const unsigned, const unsigned, const int64_t);
/* HTTP daemon support */
extern const char *voss_httpd_start(vprofile_t *);
#endif /* _VIRTUAL_INT_H_ */