summaryrefslogtreecommitdiff
path: root/libs/fluidsynth/src
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-04-19 15:25:47 +0200
committerRobin Gareus <robin@gareus.org>2019-04-19 15:44:14 +0200
commit1f982b532d17fea9126f2e62e84874e9c5598da5 (patch)
tree8f4758bed1aa7400c465a3cf1a999684bcd59a6f /libs/fluidsynth/src
parentbcd33a23814d9b86b09ebe930cc201f395b486fb (diff)
Update Fluidsynth to v2.0.5
Diffstat (limited to 'libs/fluidsynth/src')
-rw-r--r--libs/fluidsynth/src/fluid_defsfont.c15
-rw-r--r--libs/fluidsynth/src/fluid_midi.c16
-rw-r--r--libs/fluidsynth/src/fluid_sffile.c8
-rw-r--r--libs/fluidsynth/src/fluid_sfont.c22
-rw-r--r--libs/fluidsynth/src/fluid_synth.c18
-rw-r--r--libs/fluidsynth/src/fluid_synth.h7
-rw-r--r--libs/fluidsynth/src/fluid_sys.c45
-rw-r--r--libs/fluidsynth/src/fluid_sys.h4
-rw-r--r--libs/fluidsynth/src/fluidsynth_priv.h2
9 files changed, 84 insertions, 53 deletions
diff --git a/libs/fluidsynth/src/fluid_defsfont.c b/libs/fluidsynth/src/fluid_defsfont.c
index ae8a9fb2da..8c0fd5ed98 100644
--- a/libs/fluidsynth/src/fluid_defsfont.c
+++ b/libs/fluidsynth/src/fluid_defsfont.c
@@ -246,7 +246,18 @@ int delete_fluid_defsfont(fluid_defsfont_t *defsfont)
for(list = defsfont->sample; list; list = fluid_list_next(list))
{
- delete_fluid_sample((fluid_sample_t *) fluid_list_get(list));
+ sample = (fluid_sample_t *) fluid_list_get(list);
+
+ /* If the sample data pointer is different to the sampledata chunk of
+ * the soundfont, then the sample has been loaded individually (SF3)
+ * and needs to be unloaded explicitly. This is safe even if using
+ * dynamic sample loading, as the sample_unload mechanism sets
+ * sample->data to NULL after unload. */
+ if ((sample->data != NULL) && (sample->data != defsfont->sampledata))
+ {
+ fluid_samplecache_unload(sample->data);
+ }
+ delete_fluid_sample(sample);
}
if(defsfont->sample)
@@ -425,7 +436,7 @@ int fluid_defsfont_load(fluid_defsfont_t *defsfont, const fluid_file_callbacks_t
if(sfdata == NULL)
{
- FLUID_LOG(FLUID_ERR, "Couldn't load soundfont file");
+ /* error message already printed */
return FLUID_FAILED;
}
diff --git a/libs/fluidsynth/src/fluid_midi.c b/libs/fluidsynth/src/fluid_midi.c
index 73551a6d8c..5b2efe0b9b 100644
--- a/libs/fluidsynth/src/fluid_midi.c
+++ b/libs/fluidsynth/src/fluid_midi.c
@@ -99,13 +99,7 @@ int fluid_is_midifile(const char *filename)
do
{
- if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR))
- {
- return retcode;
- }
-
- // file seems to exist and is a regular file or a symlink to such
- if((fp = FLUID_FOPEN(filename, "rb")) == NULL)
+ if((fp = fluid_file_open(filename, NULL)) == NULL)
{
return retcode;
}
@@ -1677,7 +1671,7 @@ new_fluid_player(fluid_synth_t *synth)
player->currentfile = NULL;
player->division = 0;
player->send_program_change = 1;
- player->miditempo = 480000;
+ player->miditempo = 500000;
player->deltatime = 4.0;
player->cur_msec = 0;
player->cur_ticks = 0;
@@ -1761,7 +1755,7 @@ fluid_player_reset(fluid_player_t *player)
player->ntracks = 0;
player->division = 0;
player->send_program_change = 1;
- player->miditempo = 480000;
+ player->miditempo = 500000;
player->deltatime = 4.0;
return 0;
}
@@ -1892,14 +1886,14 @@ fluid_player_load(fluid_player_t *player, fluid_playlist_item *item)
buffer = fluid_file_read_full(fp, &buffer_length);
+ FLUID_FCLOSE(fp);
+
if(buffer == NULL)
{
- FLUID_FCLOSE(fp);
return FLUID_FAILED;
}
buffer_owned = 1;
- FLUID_FCLOSE(fp);
}
else
{
diff --git a/libs/fluidsynth/src/fluid_sffile.c b/libs/fluidsynth/src/fluid_sffile.c
index b5a641b63d..5fa34297aa 100644
--- a/libs/fluidsynth/src/fluid_sffile.c
+++ b/libs/fluidsynth/src/fluid_sffile.c
@@ -340,13 +340,7 @@ int fluid_is_soundfont(const char *filename)
do
{
- if(!fluid_file_test(filename, G_FILE_TEST_IS_REGULAR))
- {
- return retcode;
- }
-
- // file seems to exist and is a regular file or a symlink to such
- if((fp = FLUID_FOPEN(filename, "rb")) == NULL)
+ if((fp = fluid_file_open(filename, NULL)) == NULL)
{
return retcode;
}
diff --git a/libs/fluidsynth/src/fluid_sfont.c b/libs/fluidsynth/src/fluid_sfont.c
index d0ce264d0c..04dd001768 100644
--- a/libs/fluidsynth/src/fluid_sfont.c
+++ b/libs/fluidsynth/src/fluid_sfont.c
@@ -24,26 +24,14 @@
void *default_fopen(const char *path)
{
- FILE* handle;
+ const char* msg;
+ FILE* handle = fluid_file_open(path, &msg);
- if(!fluid_file_test(path, G_FILE_TEST_EXISTS))
+ if(handle == NULL)
{
- FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Unable to load non-existent file. ('%s')", path);
- return NULL;
- }
-
- if(!fluid_file_test(path, G_FILE_TEST_IS_REGULAR))
- {
- FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Refusing to load non-regular file! ('%s')", path);
- return NULL;
+ FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Failed to open '%s': %s", path, msg);
}
-
- if((handle = FLUID_FOPEN(path, "rb")) == NULL)
- {
- FLUID_LOG(FLUID_ERR, "fluid_sfloader_load(): Specified file does not exists or insufficient permissions to open it! ('%s')", path);
- return NULL;
- }
-
+
return handle;
}
diff --git a/libs/fluidsynth/src/fluid_synth.c b/libs/fluidsynth/src/fluid_synth.c
index e267720733..83d427fcac 100644
--- a/libs/fluidsynth/src/fluid_synth.c
+++ b/libs/fluidsynth/src/fluid_synth.c
@@ -1235,7 +1235,7 @@ fluid_synth_noteoff_LOCAL(fluid_synth_t *synth, int chan, int key)
{
/* channel is poly and legato CC is Off) */
/* removes the note from the monophonic list */
- if(key == fluid_channel_last_note(channel))
+ if(channel->n_notes && key == fluid_channel_last_note(channel))
{
fluid_channel_clear_monolist(channel);
}
@@ -3639,12 +3639,19 @@ int
fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[],
int nout, float *out[])
{
+ return fluid_synth_process_LOCAL(synth, len, nfx, fx, nout, out, fluid_synth_render_blocks);
+}
+
+int
+fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[],
+ int nout, float *out[], int (*block_render_func)(fluid_synth_t *, int))
+{
fluid_real_t *left_in, *fx_left_in;
fluid_real_t *right_in, *fx_right_in;
int nfxchan, nfxunits, naudchan;
double time = fluid_utime();
- int i, f, num, count;
+ int i, f, num, count, buffered_blocks;
float cpu_load;
@@ -3668,9 +3675,10 @@ fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[],
count = 0;
num = synth->cur;
- if(synth->cur < FLUID_BUFSIZE)
+ buffered_blocks = (synth->cur + FLUID_BUFSIZE - 1) / FLUID_BUFSIZE;
+ if(synth->cur < buffered_blocks * FLUID_BUFSIZE)
{
- int available = FLUID_BUFSIZE - synth->cur;
+ int available = (buffered_blocks * FLUID_BUFSIZE) - synth->cur;
num = (available > len) ? len : available;
if(nout != 0)
@@ -3712,7 +3720,7 @@ fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[],
while(count < len)
{
int blocksleft = (len - count + FLUID_BUFSIZE - 1) / FLUID_BUFSIZE;
- int blockcount = fluid_synth_render_blocks(synth, blocksleft);
+ int blockcount = block_render_func(synth, blocksleft);
num = (blockcount * FLUID_BUFSIZE > len - count) ? len - count : blockcount * FLUID_BUFSIZE;
diff --git a/libs/fluidsynth/src/fluid_synth.h b/libs/fluidsynth/src/fluid_synth.h
index 9615cb1b53..2b35f1fcb0 100644
--- a/libs/fluidsynth/src/fluid_synth.h
+++ b/libs/fluidsynth/src/fluid_synth.h
@@ -209,6 +209,13 @@ void delete_fluid_sample_timer(fluid_synth_t *synth, fluid_sample_timer_t *timer
void fluid_synth_process_event_queue(fluid_synth_t *synth);
+int fluid_synth_set_gen2(fluid_synth_t *synth, int chan,
+ int param, float value,
+ int absolute, int normalized);
+
+int
+fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[],
+ int nout, float *out[], int (*block_render_func)(fluid_synth_t *, int));
/*
* misc
*/
diff --git a/libs/fluidsynth/src/fluid_sys.c b/libs/fluidsynth/src/fluid_sys.c
index bcb86bac21..22694f21c5 100644
--- a/libs/fluidsynth/src/fluid_sys.c
+++ b/libs/fluidsynth/src/fluid_sys.c
@@ -934,7 +934,7 @@ fluid_thread_t *
new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int prio_level, int detach)
{
GThread *thread;
- fluid_thread_info_t *info;
+ fluid_thread_info_t *info = NULL;
GError *err = NULL;
g_return_val_if_fail(func != NULL, NULL);
@@ -971,25 +971,21 @@ new_fluid_thread(const char *name, fluid_thread_func_t func, void *data, int pri
#endif
}
-#if NEW_GLIB_THREAD_API
else
{
+#if NEW_GLIB_THREAD_API
thread = g_thread_try_new(name, (GThreadFunc)func, data, &err);
- }
-
#else
- else
- {
thread = g_thread_create((GThreadFunc)func, data, detach == FALSE, &err);
- }
-
#endif
+ }
if(!thread)
{
FLUID_LOG(FLUID_ERR, "Failed to create the thread: %s",
fluid_gerror_message(err));
g_clear_error(&err);
+ FLUID_FREE(info);
return NULL;
}
@@ -1603,3 +1599,36 @@ void delete_fluid_server_socket(fluid_server_socket_t *server_socket)
}
#endif // NETWORK_SUPPORT
+
+FILE* fluid_file_open(const char* path, const char** errMsg)
+{
+ static const char ErrExist[] = "File does not exist.";
+ static const char ErrRegular[] = "File is not regular, refusing to open it.";
+ static const char ErrNull[] = "File does not exists or insufficient permissions to open it.";
+
+ FILE* handle = NULL;
+
+ if(!g_file_test(path, G_FILE_TEST_EXISTS))
+ {
+ if(errMsg != NULL)
+ {
+ *errMsg = ErrExist;
+ }
+ }
+ else if(!g_file_test(path, G_FILE_TEST_IS_REGULAR))
+ {
+ if(errMsg != NULL)
+ {
+ *errMsg = ErrRegular;
+ }
+ }
+ else if((handle = FLUID_FOPEN(path, "rb")) == NULL)
+ {
+ if(errMsg != NULL)
+ {
+ *errMsg = ErrNull;
+ }
+ }
+
+ return handle;
+}
diff --git a/libs/fluidsynth/src/fluid_sys.h b/libs/fluidsynth/src/fluid_sys.h
index e3a6967411..5d82b686dd 100644
--- a/libs/fluidsynth/src/fluid_sys.h
+++ b/libs/fluidsynth/src/fluid_sys.h
@@ -19,7 +19,7 @@
*/
-/**
+/*
* @file fluid_sys.h
*
* This header contains a bunch of (mostly) system and machine
@@ -486,7 +486,7 @@ fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock);
typedef GStatBuf fluid_stat_buf_t;
#endif
-#define fluid_file_test g_file_test
+FILE* fluid_file_open(const char* filename, const char** errMsg);
/* Profiling */
#if WITH_PROFILING
diff --git a/libs/fluidsynth/src/fluidsynth_priv.h b/libs/fluidsynth/src/fluidsynth_priv.h
index 7a3ce6d6d1..c8a59908cc 100644
--- a/libs/fluidsynth/src/fluidsynth_priv.h
+++ b/libs/fluidsynth/src/fluidsynth_priv.h
@@ -18,7 +18,7 @@
* 02110-1301, USA
*/
-/**
+/*
* @file fluidsynth_priv.h
*
* lightweight part of fluid_sys.h, containing forward declarations of fluidsynth's private types and private macros