Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/fluidsynth/src/utils/fluidsynth_priv.h
4396 views
1
/* FluidSynth - A Software Synthesizer
2
*
3
* Copyright (C) 2003 Peter Hanappe and others.
4
*
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public License
7
* as published by the Free Software Foundation; either version 2.1 of
8
* the License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free
17
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
* 02110-1301, USA
19
*/
20
21
/*
22
* @file fluidsynth_priv.h
23
*
24
* lightweight part of fluid_sys.h, containing forward declarations of fluidsynth's private types and private macros
25
*
26
* include this one file in fluidsynth's private header files
27
*/
28
29
#ifndef _FLUIDSYNTH_PRIV_H
30
#define _FLUIDSYNTH_PRIV_H
31
32
#include "config.h"
33
34
#include <glib.h>
35
36
#if HAVE_STDLIB_H
37
#include <stdlib.h> // malloc, free
38
#endif
39
40
#if HAVE_STDIO_H
41
#include <stdio.h> // printf
42
#endif
43
44
#if HAVE_STRING_H
45
#include <string.h>
46
#endif
47
48
#if HAVE_STRINGS_H
49
#include <strings.h>
50
#endif
51
52
#include "fluidsynth.h"
53
54
#include "wine/debug.h"
55
56
WINE_DEFAULT_DEBUG_CHANNEL(fluidsynth);
57
58
#ifdef __cplusplus
59
extern "C" {
60
#endif
61
62
/***************************************************************
63
*
64
* BASIC TYPES
65
*/
66
67
#if defined(WITH_FLOAT)
68
typedef float fluid_real_t;
69
#else
70
typedef double fluid_real_t;
71
#endif
72
73
#if defined(SUPPORTS_VLA)
74
# define FLUID_DECLARE_VLA(_type, _name, _len) \
75
_type _name[_len]
76
#else
77
# define FLUID_DECLARE_VLA(_type, _name, _len) \
78
_type* _name = g_newa(_type, (_len))
79
#endif
80
81
82
/** Atomic types */
83
typedef int fluid_atomic_int_t;
84
typedef unsigned int fluid_atomic_uint_t;
85
typedef float fluid_atomic_float_t;
86
87
88
/***************************************************************
89
*
90
* FORWARD DECLARATIONS
91
*/
92
typedef struct _fluid_env_data_t fluid_env_data_t;
93
typedef struct _fluid_adriver_definition_t fluid_adriver_definition_t;
94
typedef struct _fluid_channel_t fluid_channel_t;
95
typedef struct _fluid_tuning_t fluid_tuning_t;
96
typedef struct _fluid_hashtable_t fluid_hashtable_t;
97
typedef struct _fluid_client_t fluid_client_t;
98
typedef struct _fluid_server_socket_t fluid_server_socket_t;
99
typedef struct _fluid_sample_timer_t fluid_sample_timer_t;
100
typedef struct _fluid_zone_range_t fluid_zone_range_t;
101
typedef struct _fluid_rvoice_eventhandler_t fluid_rvoice_eventhandler_t;
102
103
/* Declare rvoice related typedefs here instead of fluid_rvoice.h, as it's needed
104
* in fluid_lfo.c and fluid_adsr.c as well */
105
typedef union _fluid_rvoice_param_t
106
{
107
void *ptr;
108
int i;
109
fluid_real_t real;
110
} fluid_rvoice_param_t;
111
enum { MAX_EVENT_PARAMS = 7 }; /**< Maximum number of #fluid_rvoice_param_t to be passed to an #fluid_rvoice_function_t */
112
typedef void (*fluid_rvoice_function_t)(void *obj, const fluid_rvoice_param_t param[MAX_EVENT_PARAMS]);
113
114
/* Macro for declaring an rvoice event function (#fluid_rvoice_function_t). The functions may only access
115
* those params that were previously set in fluid_voice.c
116
*/
117
#define DECLARE_FLUID_RVOICE_FUNCTION(name) void name(void* obj, const fluid_rvoice_param_t param[MAX_EVENT_PARAMS])
118
119
120
/***************************************************************
121
*
122
* CONSTANTS
123
*/
124
125
#define FLUID_BUFSIZE 64 /**< FluidSynth internal buffer size (in samples) */
126
#define FLUID_MIXER_MAX_BUFFERS_DEFAULT (8192/FLUID_BUFSIZE) /**< Number of buffers that can be processed in one rendering run */
127
#define FLUID_MAX_EVENTS_PER_BUFSIZE 1024 /**< Maximum queued MIDI events per #FLUID_BUFSIZE */
128
#define FLUID_MAX_RETURN_EVENTS 1024 /**< Maximum queued synthesis thread return events */
129
#define FLUID_MAX_EVENT_QUEUES 16 /**< Maximum number of unique threads queuing events */
130
#define FLUID_DEFAULT_AUDIO_RT_PRIO 60 /**< Default setting for audio.realtime-prio */
131
#define FLUID_DEFAULT_MIDI_RT_PRIO 50 /**< Default setting for midi.realtime-prio */
132
#define FLUID_NUM_MOD 64 /**< Maximum number of modulators in a voice */
133
134
/***************************************************************
135
*
136
* SYSTEM INTERFACE
137
*/
138
139
/* Math constants */
140
#ifndef M_PI
141
#define M_PI 3.1415926535897932384626433832795
142
#endif
143
144
#ifndef M_LN2
145
#define M_LN2 0.69314718055994530941723212145818
146
#endif
147
148
#ifndef M_LN10
149
#define M_LN10 2.3025850929940456840179914546844
150
#endif
151
152
#define FLUID_M_PI ((fluid_real_t)M_PI)
153
#define FLUID_M_LN2 ((fluid_real_t)M_LN2)
154
#define FLUID_M_LN10 ((fluid_real_t)M_LN10)
155
156
/* Math functions */
157
#if defined WITH_FLOAT && defined HAVE_SINF
158
#define FLUID_SIN sinf
159
#else
160
#define FLUID_SIN (fluid_real_t)sin
161
#endif
162
163
#if defined WITH_FLOAT && defined HAVE_COSF
164
#define FLUID_COS cosf
165
#else
166
#define FLUID_COS (fluid_real_t)cos
167
#endif
168
169
#if defined WITH_FLOAT && defined HAVE_FABSF
170
#define FLUID_FABS fabsf
171
#else
172
#define FLUID_FABS (fluid_real_t)fabs
173
#endif
174
175
#if defined WITH_FLOAT && defined HAVE_POWF
176
#define FLUID_POW powf
177
#else
178
#define FLUID_POW (fluid_real_t)pow
179
#endif
180
181
#if defined WITH_FLOAT && defined HAVE_SQRTF
182
#define FLUID_SQRT sqrtf
183
#else
184
#define FLUID_SQRT (fluid_real_t)sqrt
185
#endif
186
187
#if defined WITH_FLOAT && defined HAVE_LOGF
188
#define FLUID_LOGF logf
189
#else
190
#define FLUID_LOGF (fluid_real_t)log
191
#endif
192
193
/* Memory allocation */
194
#define FLUID_MALLOC(_n) fluid_alloc(_n)
195
#define FLUID_REALLOC(_p,_n) realloc(_p,_n)
196
#define FLUID_FREE(_p) fluid_free(_p)
197
#define FLUID_NEW(_t) (_t*)FLUID_MALLOC(sizeof(_t))
198
#define FLUID_ARRAY_ALIGNED(_t,_n,_a) (_t*)FLUID_MALLOC((_n)*sizeof(_t) + ((unsigned int)_a - 1u))
199
#define FLUID_ARRAY(_t,_n) FLUID_ARRAY_ALIGNED(_t,_n,1u)
200
201
void* fluid_alloc(size_t len);
202
203
/* File access */
204
#define FLUID_FOPEN(_f,_m) fluid_fopen(_f,_m)
205
#define FLUID_FCLOSE(_f) fclose(_f)
206
#define FLUID_FREAD(_p,_s,_n,_f) fread(_p,_s,_n,_f)
207
208
FILE *fluid_fopen(const char *filename, const char *mode);
209
210
#ifdef _WIN32
211
#define FLUID_FSEEK(_f,_n,_set) _fseeki64(_f,_n,_set)
212
#else
213
#define FLUID_FSEEK(_f,_n,_set) fseek(_f,_n,_set)
214
#endif
215
216
#define FLUID_FTELL(_f) fluid_file_tell(_f)
217
218
/* Memory functions */
219
#define FLUID_MEMCPY(_dst,_src,_n) memcpy(_dst,_src,_n)
220
#define FLUID_MEMSET(_s,_c,_n) memset(_s,_c,_n)
221
222
/* String functions */
223
#define FLUID_STRLEN(_s) strlen(_s)
224
#define FLUID_STRCMP(_s,_t) strcmp(_s,_t)
225
#define FLUID_STRNCMP(_s,_t,_n) strncmp(_s,_t,_n)
226
#define FLUID_STRCPY(_dst,_src) strcpy(_dst,_src)
227
#define FLUID_STRTOL(_s,_e,_b) strtol(_s,_e,_b)
228
229
#define FLUID_STRNCPY(_dst,_src,_n) \
230
do { strncpy(_dst,_src,_n-1); \
231
(_dst)[(_n)-1]='\0'; \
232
}while(0)
233
234
#define FLUID_STRCHR(_s,_c) strchr(_s,_c)
235
#define FLUID_STRRCHR(_s,_c) strrchr(_s,_c)
236
237
#ifdef strdup
238
#define FLUID_STRDUP(s) strdup(s)
239
#else
240
#define FLUID_STRDUP(s) FLUID_STRCPY(FLUID_MALLOC(FLUID_STRLEN(s) + 1), s)
241
#endif
242
243
#define FLUID_SPRINTF sprintf
244
#define FLUID_FPRINTF fprintf
245
246
#if (defined(_WIN32) && _MSC_VER < 1900) || defined(MINGW32)
247
/* need to make sure we use a C99 compliant implementation of (v)snprintf(),
248
* i.e. not microsofts non compliant extension _snprintf() as it doesn't
249
* reliably null-terminate the buffer
250
*/
251
#define FLUID_SNPRINTF g_snprintf
252
#else
253
#define FLUID_SNPRINTF snprintf
254
#endif
255
256
#if (defined(_WIN32) && _MSC_VER < 1500) || defined(MINGW32)
257
#define FLUID_VSNPRINTF g_vsnprintf
258
#else
259
#define FLUID_VSNPRINTF vsnprintf
260
#endif
261
262
#if defined(_WIN32) && !defined(MINGW32)
263
#define FLUID_STRCASECMP _stricmp
264
#else
265
#define FLUID_STRCASECMP strcasecmp
266
#endif
267
268
#if defined(_WIN32) && !defined(MINGW32)
269
#define FLUID_STRNCASECMP _strnicmp
270
#else
271
#define FLUID_STRNCASECMP strncasecmp
272
#endif
273
274
275
#define fluid_clip(_val, _min, _max) \
276
{ (_val) = ((_val) < (_min))? (_min) : (((_val) > (_max))? (_max) : (_val)); }
277
278
#if WITH_FTS
279
#define FLUID_PRINTF post
280
#define FLUID_FLUSH()
281
#else
282
#define FLUID_PRINTF WINE_TRACE
283
#define FLUID_FLUSH()
284
#endif
285
286
/* People who want to reduce the size of the may do this by entirely
287
* removing the logging system. This will cause all log messages to
288
* be discarded at compile time, allowing to save about 80 KiB for
289
* the compiled binary.
290
*/
291
#if 0
292
#define FLUID_LOG (void)sizeof
293
#else
294
#define WINE_FLUID_DBG WINE_TRACE
295
#define WINE_FLUID_INFO WINE_TRACE
296
#define WINE_FLUID_WARN WINE_WARN
297
#define WINE_FLUID_ERR WINE_ERR
298
#define WINE_FLUID_PANIC WINE_ERR
299
#define FLUID_LOG( x, msg, ... ) do { WINE_ ## x( msg, ## __VA_ARGS__ ); WINE_ ## x( "\n" ); } while (0)
300
#endif
301
302
#if defined(DEBUG) && !defined(NDEBUG)
303
#define FLUID_ASSERT(a) g_assert(a)
304
#else
305
#define FLUID_ASSERT(a)
306
#endif
307
308
#define FLUID_LIKELY G_LIKELY
309
#define FLUID_UNLIKELY G_UNLIKELY
310
311
/* Misc */
312
#if defined(__INTEL_COMPILER)
313
#define FLUID_RESTRICT restrict
314
#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
315
#define FLUID_RESTRICT __restrict__
316
#elif defined(_MSC_VER) && _MSC_VER >= 1400
317
#define FLUID_RESTRICT __restrict
318
#else
319
#warning "Dont know how this compiler handles restrict pointers, refuse to use them."
320
#define FLUID_RESTRICT
321
#endif
322
323
#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0]))
324
#define FLUID_MEMBER_SIZE(struct, member) ( sizeof (((struct *)0)->member) )
325
326
327
#define fluid_return_if_fail(cond) \
328
if(cond) \
329
; \
330
else \
331
return
332
333
#define fluid_return_val_if_fail(cond, val) \
334
fluid_return_if_fail(cond) (val)
335
336
#ifdef __cplusplus
337
}
338
#endif
339
340
#endif /* _FLUIDSYNTH_PRIV_H */
341
342