-
Notifications
You must be signed in to change notification settings - Fork 16
/
fluidsynth-no-glib.patch
491 lines (441 loc) · 16.2 KB
/
fluidsynth-no-glib.patch
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
From 9491c60ddeddcc9ed14963a1ec8aff733797763e Mon Sep 17 00:00:00 2001
From: Ghabry
Date: Fri, 17 Mar 2023 14:00:45 +0100
Subject: [PATCH 1/2] Shim glib
---
CMakeLists.txt | 4 +-
src/CMakeLists.txt | 3 +-
src/bindings/fluid_cmd.c | 3 ++
src/glib_shim.c | 12 +++++
src/glib_shim.h | 90 ++++++++++++++++++++++++++++++++
src/rvoice/fluid_rvoice_mixer.c | 10 ----
src/sfloader/fluid_defsfont.c | 5 --
src/sfloader/fluid_samplecache.c | 2 +
src/synth/fluid_synth.c | 16 +++---
src/synth/fluid_synth.h | 2 +-
src/utils/fluid_sys.c | 9 +++-
src/utils/fluid_sys.h | 8 +--
src/utils/fluidsynth_priv.h | 2 +-
13 files changed, 132 insertions(+), 34 deletions(-)
create mode 100644 src/glib_shim.c
create mode 100644 src/glib_shim.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b12afa..dd3a0c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -522,8 +522,8 @@ if ( CMAKE_VERSION VERSION_GREATER_EQUAL 3.15 AND VCPKG_TOOLCHAIN )
endif ()
# Mandatory libraries: glib and gthread
-find_package ( GLib2 ${GLIB2_MINUMUM_VERSION} REQUIRED )
-list( APPEND PC_REQUIRES_PRIV "glib-2.0" "gthread-2.0")
+# find_package ( GLib2 ${GLIB2_MINUMUM_VERSION} REQUIRED )
+# list( APPEND PC_REQUIRES_PRIV "glib-2.0" "gthread-2.0")
if ( GLib2_VERSION AND GLib2_VERSION VERSION_LESS "2.26.0" )
message ( WARNING "Your version of glib is very old. This may cause problems with fluidsynth's sample cache on Windows. Consider updating to glib 2.26 or newer!" )
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 114fa16..53e8c6a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -108,6 +108,7 @@ endif ( OBOE_SUPPORT )
set ( config_SOURCES ${FluidSynth_BINARY_DIR}/config.h )
set ( libfluidsynth_SOURCES
+ glib_shim.c
utils/fluid_conv.c
utils/fluid_conv.h
utils/fluid_hash.c
@@ -353,7 +354,7 @@ if ( TARGET OpenMP::OpenMP_C AND HAVE_OPENMP )
target_link_libraries ( libfluidsynth-OBJ PUBLIC OpenMP::OpenMP_C )
endif()
-target_link_libraries ( libfluidsynth-OBJ PUBLIC GLib2::glib-2 GLib2::gthread-2 )
+# target_link_libraries ( libfluidsynth-OBJ PUBLIC GLib2::glib-2 GLib2::gthread-2 )
if ( TARGET SndFile::sndfile AND LIBSNDFILE_SUPPORT )
target_link_libraries ( libfluidsynth-OBJ PUBLIC SndFile::sndfile )
diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c
index 444b263..74780e1 100644
--- a/src/bindings/fluid_cmd.c
+++ b/src/bindings/fluid_cmd.c
@@ -433,6 +433,8 @@ static const fluid_cmd_t fluid_commands[] =
int
fluid_command(fluid_cmd_handler_t *handler, const char *cmd, fluid_ostream_t out)
{
+ return 0;
+#if 0
int result, num_tokens = 0;
char **tokens = NULL;
@@ -451,6 +453,7 @@ fluid_command(fluid_cmd_handler_t *handler, const char *cmd, fluid_ostream_t out
fluid_strfreev(tokens);
return result;
+#endif
}
/**
diff --git a/src/glib_shim.c b/src/glib_shim.c
new file mode 100644
index 0000000..40b8b56
--- /dev/null
+++ b/src/glib_shim.c
@@ -0,0 +1,12 @@
+#include "glib_shim.h"
+
+int g_atomic_int_dec_and_test(int* _pi) {
+ *_pi -= 1;
+ return (_pi == 0);
+}
+
+int g_atomic_int_add(int* _pi, int _add) {
+ int tmp = *_pi;
+ *_pi += _add;
+ return tmp;
+}
diff --git a/src/glib_shim.h b/src/glib_shim.h
new file mode 100644
index 0000000..f90f0eb
--- /dev/null
+++ b/src/glib_shim.h
@@ -0,0 +1,90 @@
+#ifndef GLIB_SHIM_H
+#define GLIB_SHIM_H
+
+#define GLIB_MAJOR_VERSION 3
+#define GLIB_MINOR_VERSION 0
+#define GLIB_MICRO_VERISON 0
+
+#define GLIB_CHECK_VERSION(major,minor,micro) \
+ (GLIB_MAJOR_VERSION > (major) || \
+ (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
+ (GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
+ GLIB_MICRO_VERSION >= (micro)))
+
+typedef int GMutex;
+typedef int GRecMutex;
+typedef int GThread;
+typedef int GCond;
+typedef int GStatBuf;
+typedef int GTimeVal;
+typedef void* gpointer;
+typedef int GError;
+
+#ifdef WORDS_BIGENDIAN
+#define G_BIG_ENDIAN WORDS_BIGENDIAN
+#define G_BYTE_ORDER WORDS_BIGENDIAN
+#else
+#define G_BYTE_ORDER 0
+#define G_BIG_ENDIAN 1
+#endif
+
+#define GINT32_FROM_LE(x) ((x))
+#define GINT16_FROM_LE(x) ((x))
+
+#define G_LIKELY
+#define G_UNLIKELY
+
+#ifndef TRUE
+#define TRUE 1
+#define FALSE 0
+#endif
+
+#define g_mutex_init(x)
+#define g_mutex_clear(x)
+#define g_mutex_lock(x)
+#define g_mutex_unlock(x)
+
+#define g_rec_mutex_init(x)
+#define g_rec_mutex_clear(x)
+#define g_rec_mutex_lock(x)
+#define g_rec_mutex_unlock(x)
+
+#define g_new(type, len) ( NULL )
+#define g_free(obj)
+
+#define g_atomic_int_inc(_pi) ( *_pi += 1 )
+#define g_atomic_int_get(_pi) ( *_pi )
+#define g_atomic_int_set(_pi, _val) ( *_pi = _val )
+int g_atomic_int_dec_and_test(int* _pi);
+#define g_atomic_int_compare_and_exchange(_pi, _old, _new) ( 1 )
+int g_atomic_int_add(int* _pi, int _add);
+#define g_atomic_pointer_get(_pp) ( _pp )
+#define g_atomic_pointer_set(_pp, val) ( _pp = val )
+#define g_atomic_pointer_compare_and_exchange(_pp, _expected, _desired) (1)
+
+#define g_cond_init(x)
+#define g_cond_signal(x)
+#define g_cond_broadcast(x)
+#define g_cond_clear(x)
+#define g_cond_wait(x, y)
+
+#define g_stat(a, b) ( 0 )
+
+#define g_assert(a)
+
+#define G_FILE_TEST_IS_REGULAR 0
+#define G_FILE_TEST_EXISTS 1
+#define g_file_test(a, b) ( FALSE )
+
+#define g_usleep(x)
+
+#define g_thread_try_new(a, b, c, d) ( NULL )
+#define g_clear_error(e) ( *err = 0 )
+#define g_thread_unref(t)
+#define g_thread_join(t)
+
+#define g_shim_alloca(size) _alloca((size))
+#define g_newa(struct_type, n_structs) \
+ ((struct_type *)g_shim_alloca(sizeof(struct_type) * (size_t)(n_structs)))
+
+#endif
diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c
index c1e2fb2..9255313 100644
--- a/src/rvoice/fluid_rvoice_mixer.c
+++ b/src/rvoice/fluid_rvoice_mixer.c
@@ -478,7 +478,6 @@ fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t *buffers,
else
{
// here goes the vectorizable loop
- #pragma omp simd aligned(dsp_buf,buf:FLUID_DEFAULT_ALIGNMENT)
for(dsp_i = 0; dsp_i < FLUID_BUFSIZE; dsp_i++)
{
// We cannot simply increment current_amp by amp_incr during every iteration, as this would create a dependency and prevent vectorization.
@@ -489,7 +488,6 @@ fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t *buffers,
if(target_amp > 0)
{
/* Note, that this loop could be unrolled by FLUID_BUFSIZE elements */
- #pragma omp simd aligned(dsp_buf,buf:FLUID_DEFAULT_ALIGNMENT)
for(dsp_i = FLUID_BUFSIZE; dsp_i < sample_count; dsp_i++)
{
// Index by blocks (not by samples) to let the compiler know that we always start accessing
@@ -1413,8 +1411,6 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
for(i = 0; i < minbuf; i++)
{
- #pragma omp simd aligned(base_dst,base_src:FLUID_DEFAULT_ALIGNMENT)
-
for(j = 0; j < scount; j++)
{
int dsp_i = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j;
@@ -1427,8 +1423,6 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
for(i = 0; i < minbuf; i++)
{
- #pragma omp simd aligned(base_dst,base_src:FLUID_DEFAULT_ALIGNMENT)
-
for(j = 0; j < scount; j++)
{
int dsp_i = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j;
@@ -1448,8 +1442,6 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
for(i = 0; i < minbuf; i++)
{
- #pragma omp simd aligned(base_dst,base_src:FLUID_DEFAULT_ALIGNMENT)
-
for(j = 0; j < scount; j++)
{
int dsp_i = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j;
@@ -1462,8 +1454,6 @@ fluid_mixer_buffers_mix(fluid_mixer_buffers_t *dst, fluid_mixer_buffers_t *src,
for(i = 0; i < minbuf; i++)
{
- #pragma omp simd aligned(base_dst,base_src:FLUID_DEFAULT_ALIGNMENT)
-
for(j = 0; j < scount; j++)
{
int dsp_i = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j;
diff --git a/src/sfloader/fluid_defsfont.c b/src/sfloader/fluid_defsfont.c
index 9721a09..e9daff3 100644
--- a/src/sfloader/fluid_defsfont.c
+++ b/src/sfloader/fluid_defsfont.c
@@ -395,8 +395,6 @@ int fluid_defsfont_load_all_sampledata(fluid_defsfont_t *defsfont, SFData *sfdat
}
}
- #pragma omp parallel
- #pragma omp single
for(list = defsfont->sample; list; list = fluid_list_next(list))
{
sample = fluid_list_get(list);
@@ -405,11 +403,9 @@ int fluid_defsfont_load_all_sampledata(fluid_defsfont_t *defsfont, SFData *sfdat
{
/* SF3 samples get loaded individually, as most (or all) of them are in Ogg Vorbis format
* anyway */
- #pragma omp task firstprivate(sample,sfdata,defsfont) shared(sample_parsing_result, invalid_loops_were_sanitized) default(none)
{
if(fluid_defsfont_load_sampledata(defsfont, sfdata, sample) == FLUID_FAILED)
{
- #pragma omp critical
{
FLUID_LOG(FLUID_ERR, "Failed to load sample '%s'", sample->name);
sample_parsing_result = FLUID_FAILED;
@@ -431,7 +427,6 @@ int fluid_defsfont_load_all_sampledata(fluid_defsfont_t *defsfont, SFData *sfdat
}
else
{
- #pragma omp task firstprivate(sample, defsfont) shared(invalid_loops_were_sanitized) default(none)
{
int modified;
/* Data pointers of SF2 samples point to large sample data block loaded above */
diff --git a/src/sfloader/fluid_samplecache.c b/src/sfloader/fluid_samplecache.c
index 64e9e9e..4c504c0 100644
--- a/src/sfloader/fluid_samplecache.c
+++ b/src/sfloader/fluid_samplecache.c
@@ -282,6 +282,7 @@ static fluid_samplecache_entry_t *get_samplecache_entry(SFData *sf,
static int fluid_get_file_modification_time(char *filename, time_t *modification_time)
{
+#if 0
fluid_stat_buf_t buf;
if(fluid_stat(filename, &buf))
@@ -290,6 +291,7 @@ static int fluid_get_file_modification_time(char *filename, time_t *modification
}
*modification_time = buf.st_mtime;
+#endif
return FLUID_OK;
}
diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c
index 76c4a0f..95d52ea 100644
--- a/src/synth/fluid_synth.c
+++ b/src/synth/fluid_synth.c
@@ -631,8 +631,9 @@ new_fluid_synth(fluid_settings_t *settings)
double sample_rate_min, sample_rate_max;
/* initialize all the conversion tables and other stuff */
- if(fluid_atomic_int_compare_and_exchange(&fluid_synth_initialized, 0, 1))
+ if(fluid_synth_initialized == 0)
{
+ fluid_synth_initialized = 1;
fluid_synth_init();
}
@@ -808,7 +809,7 @@ new_fluid_synth(fluid_settings_t *settings)
fluid_atomic_int_set(&synth->ticks_since_start, 0);
synth->tuning = NULL;
- fluid_private_init(synth->tuning_iter);
+ synth->tuning_iter = 0;
/* Initialize multi-core variables if multiple cores enabled */
if(synth->cores > 1)
@@ -1194,7 +1195,7 @@ delete_fluid_synth(fluid_synth_t *synth)
FLUID_FREE(synth->tuning);
}
- fluid_private_free(synth->tuning_iter);
+ synth->tuning_iter = 0;
#ifdef LADSPA
/* Release the LADSPA effects unit */
@@ -7395,7 +7396,7 @@ fluid_synth_tuning_iteration_start(fluid_synth_t *synth)
{
fluid_return_if_fail(synth != NULL);
fluid_synth_api_enter(synth);
- fluid_private_set(synth->tuning_iter, FLUID_INT_TO_POINTER(0));
+ synth->tuning_iter = 0;
fluid_synth_api_exit(synth);
}
@@ -7418,7 +7419,7 @@ fluid_synth_tuning_iteration_next(fluid_synth_t *synth, int *bank, int *prog)
fluid_synth_api_enter(synth);
/* Current tuning iteration stored as: bank << 8 | program */
- pval = fluid_private_get(synth->tuning_iter);
+ pval = &synth->tuning_iter;
p = FLUID_POINTER_TO_INT(pval);
b = (p >> 8) & 0xFF;
p &= 0xFF;
@@ -7447,12 +7448,11 @@ fluid_synth_tuning_iteration_next(fluid_synth_t *synth, int *bank, int *prog)
if(p < 127)
{
- fluid_private_set(synth->tuning_iter,
- FLUID_INT_TO_POINTER(b << 8 | (p + 1)));
+ synth->tuning_iter = (b << 8 | (p + 1));
}
else
{
- fluid_private_set(synth->tuning_iter, FLUID_INT_TO_POINTER((b + 1) << 8));
+ synth->tuning_iter = ((b + 1) << 8);
}
FLUID_API_RETURN(1);
diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h
index cb838e9..6e04566 100644
--- a/src/synth/fluid_synth.h
+++ b/src/synth/fluid_synth.h
@@ -152,7 +152,7 @@ struct _fluid_synth_t
fluid_atomic_float_t cpu_load; /**< CPU load in percent (CPU time required / audio synthesized time * 100) */
fluid_tuning_t ***tuning; /**< 128 banks of 128 programs for the tunings */
- fluid_private_t tuning_iter; /**< Tuning iterators per each thread */
+ int tuning_iter; /**< Tuning iterators per each thread */
fluid_sample_timer_t *sample_timers; /**< List of timers triggered before a block is processed */
unsigned int min_note_length_ticks; /**< If note-offs are triggered just after a note-on, they will be delayed */
diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c
index d5ebd16..63a6c52 100644
--- a/src/utils/fluid_sys.c
+++ b/src/utils/fluid_sys.c
@@ -33,7 +33,7 @@
#if HAVE_PTHREAD_H && !defined(_WIN32)
// Do not include pthread on windows. It includes winsock.h, which collides with ws2tcpip.h from fluid_sys.h
// It isn't need on Windows anyway.
-#include <pthread.h>
+//#include <pthread.h>
#endif
/* WIN32 HACK - Flag used to differentiate between a file descriptor and a socket.
@@ -411,6 +411,8 @@ unsigned int fluid_curtime(void)
double
fluid_utime(void)
{
+ return 0.0;
+#if 0
double utime;
#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 28
@@ -445,6 +447,7 @@ fluid_utime(void)
#endif
return utime;
+#endif
}
@@ -477,6 +480,7 @@ fluid_thread_self_set_prio(int prio_level)
void
fluid_thread_self_set_prio(int prio_level)
{
+#if 0
struct sched_param priority;
if(prio_level > 0)
@@ -501,6 +505,7 @@ fluid_thread_self_set_prio(int prio_level)
#endif
FLUID_LOG(FLUID_WARN, "Failed to set thread to high priority");
}
+#endif
}
#ifdef FPE_CHECK
@@ -1041,7 +1046,7 @@ new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int pri
fluid_thread_info_t *info = NULL;
GError *err = NULL;
- g_return_val_if_fail(func != NULL, NULL);
+ fluid_return_val_if_fail(func != NULL, NULL);
#if OLD_GLIB_THREAD_API
diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h
index cefff4a..a8067ff 100644
--- a/src/utils/fluid_sys.h
+++ b/src/utils/fluid_sys.h
@@ -168,7 +168,7 @@ typedef gintptr intptr_t;
#include <gmodule.h>
#endif
-#include <glib/gstdio.h>
+#include "glib_shim.h"
/**
* Macro used for safely accessing a message from a GError and using a default
@@ -176,7 +176,7 @@ typedef gintptr intptr_t;
* @param err Pointer to a GError to access the message field of.
* @return Message string
*/
-#define fluid_gerror_message(err) ((err) ? err->message : "No error details")
+#define fluid_gerror_message(err) ("No error details")
#if defined(_WIN32) || defined(__CYGWIN__)
char* fluid_get_windows_error(void);
@@ -329,13 +329,13 @@ delete_fluid_cond(fluid_cond_t *cond)
}
/* Thread private data */
-
+#if 0
typedef GPrivate fluid_private_t;
#define fluid_private_init(_priv) memset (&_priv, 0, sizeof (_priv))
#define fluid_private_free(_priv)
#define fluid_private_get(_priv) g_private_get(&(_priv))
#define fluid_private_set(_priv, _data) g_private_set(&(_priv), _data)
-
+#endif
#else
/* glib prior to 2.32 */
diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h
index fbcbc6f..8bd400a 100644
--- a/src/utils/fluidsynth_priv.h
+++ b/src/utils/fluidsynth_priv.h
@@ -31,7 +31,7 @@
#include "config.h"
-#include <glib.h>
+#include "glib_shim.h"
#if HAVE_STDLIB_H
#include <stdlib.h> // malloc, free
--
2.40.0