From e291f3d257360667e12754154acac9ba3fe3316a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:29:38 +0200 Subject: decoder/fluidsynth: remove throttle (requires libfluidsynth 1.1) The libfluidsynth API is now sane, and does not require real-time decoding. --- src/decoder/fluidsynth_decoder_plugin.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index 085f84f14..9e2511d3e 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2012 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -28,7 +28,6 @@ #include "config.h" #include "decoder_api.h" -#include "timer.h" #include "conf.h" #include @@ -102,7 +101,6 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) fluid_player_t *player; char *path_dup; int ret; - struct timer *timer; enum decoder_command cmd; soundfont_path = @@ -170,13 +168,6 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) return; } - /* set up a timer for synchronization; fluidsynth always - decodes in real time, which forces us to synchronize */ - /* XXX is there any way to switch off real-time decoding? */ - - timer = timer_new(&audio_format); - timer_start(timer); - /* initialization complete - announce the audio format to the MPD core */ @@ -186,11 +177,6 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) int16_t buffer[2048]; const unsigned max_frames = G_N_ELEMENTS(buffer) / 2; - /* synchronize with the fluid player */ - - timer_add(timer, sizeof(buffer)); - timer_sync(timer); - /* read samples from fluidsynth and send them to the MPD core */ @@ -209,8 +195,6 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) /* clean up */ - timer_free(timer); - fluid_player_stop(player); fluid_player_join(player); -- cgit v1.2.3 From c8ec85d649e46df87d1b526fde2d8234428925c0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:35:56 +0200 Subject: decoder/fluidsynth: check if file is really a MIDI Use fluid_is_midifile() to verify the file format. --- src/decoder/fluidsynth_decoder_plugin.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index 9e2511d3e..8cb524c98 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -208,10 +208,7 @@ fluidsynth_scan_file(const char *file, G_GNUC_UNUSED const struct tag_handler *handler, G_GNUC_UNUSED void *handler_ctx) { - /* to be implemented */ - (void)file; - - return true; + return fluid_is_midifile(file); } static const char *const fluidsynth_suffixes[] = { -- cgit v1.2.3 From c31d11bfe07a6c37d53061dd0ef732d602f98154 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:38:58 +0200 Subject: decoder/fluidsynth: don't duplicate path The libfluidsynth now accepts const strings. --- src/decoder/fluidsynth_decoder_plugin.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index 8cb524c98..b55c1db5e 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -99,7 +99,6 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) fluid_settings_t *settings; fluid_synth_t *synth; fluid_player_t *player; - char *path_dup; int ret; enum decoder_command cmd; @@ -144,11 +143,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) return; } - /* temporarily duplicate the path_fs string, because - fluidsynth wants a writable string */ - path_dup = g_strdup(path_fs); - ret = fluid_player_add(player, path_dup); - g_free(path_dup); + ret = fluid_player_add(player, path_fs); if (ret != 0) { g_warning("fluid_player_add() failed"); delete_fluid_player(player); -- cgit v1.2.3 From b1bbd70f0f956e9829158ee80a42f1bafde67347 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:47:10 +0200 Subject: decoder/fluidsynth: stop playback at end of file Use libfluidsynth's new function fluid_player_get_status(). --- src/decoder/fluidsynth_decoder_plugin.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index b55c1db5e..a8c148c89 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -168,7 +168,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) decoder_initialized(decoder, &audio_format, false, -1); - do { + while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) { int16_t buffer[2048]; const unsigned max_frames = G_N_ELEMENTS(buffer) / 2; @@ -178,15 +178,14 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) ret = fluid_synth_write_s16(synth, max_frames, buffer, 0, 2, buffer, 1, 2); - /* XXX how do we see whether the player is done? We - can't access the private attribute - player->status */ if (ret != 0) break; cmd = decoder_data(decoder, NULL, buffer, sizeof(buffer), 0); - } while (cmd == DECODE_COMMAND_NONE); + if (cmd != DECODE_COMMAND_NONE) + break; + } /* clean up */ -- cgit v1.2.3 From 9c83464b95a6e8145fee0a03bd151f4bc7a6cac7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:29:59 +0200 Subject: configure.ac: auto-detect libfluidsynth Now that the libfluidsynth API was sanitized, we can enable the plugin automatically if libfluidsynth is installed. --- src/decoder/fluidsynth_decoder_plugin.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index a8c148c89..1fef209bc 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -17,15 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/* - * WARNING! This plugin suffers from major shortcomings in the - * libfluidsynth API, which render it practically unusable. For a - * discussion, see the post on the fluidsynth mailing list: - * - * http://www.mail-archive.com/fluid-dev@nongnu.org/msg01099.html - * - */ - #include "config.h" #include "decoder_api.h" #include "conf.h" -- cgit v1.2.3 From 02325d2edec3c8ac733f4565595d27127cb5c9c1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:51:45 +0200 Subject: decoder/fluidsynth: add "soundfont" setting Replaces the old global "soundfont" which never worked. --- src/decoder/fluidsynth_decoder_plugin.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index 1fef209bc..ed0efdd99 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -28,6 +28,8 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "fluidsynth" +static const char *soundfont_path; + /** * Convert a fluidsynth log level to a GLib log level. */ @@ -65,8 +67,12 @@ fluidsynth_mpd_log_function(int level, char *message, G_GNUC_UNUSED void *data) } static bool -fluidsynth_init(G_GNUC_UNUSED const struct config_param *param) +fluidsynth_init(const struct config_param *param) { + soundfont_path = + config_get_block_string(param, "soundfont", + "/usr/share/sounds/sf2/FluidR3_GM.sf2"); + fluid_set_log_function(LAST_LOG_LEVEL, fluidsynth_mpd_log_function, NULL); @@ -86,17 +92,12 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) char setting_verbose[] = "synth.verbose"; char setting_yes[] = "yes"; */ - const char *soundfont_path; fluid_settings_t *settings; fluid_synth_t *synth; fluid_player_t *player; int ret; enum decoder_command cmd; - soundfont_path = - config_get_string("soundfont", - "/usr/share/sounds/sf2/FluidR3_GM.sf2"); - /* set up fluid settings */ settings = new_fluid_settings(); -- cgit v1.2.3 From 4a993cd79ec4149c3b52b383a8f751be26c2bac5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 00:57:32 +0200 Subject: decoder/fluidsynth: add "sample_rate" setting --- src/decoder/fluidsynth_decoder_plugin.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c index ed0efdd99..894b2d353 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/fluidsynth_decoder_plugin.c @@ -19,6 +19,7 @@ #include "config.h" #include "decoder_api.h" +#include "audio_check.h" #include "conf.h" #include @@ -28,6 +29,7 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "fluidsynth" +static unsigned sample_rate; static const char *soundfont_path; /** @@ -69,6 +71,15 @@ fluidsynth_mpd_log_function(int level, char *message, G_GNUC_UNUSED void *data) static bool fluidsynth_init(const struct config_param *param) { + GError *error = NULL; + + sample_rate = config_get_block_unsigned(param, "sample_rate", 48000); + if (!audio_check_sample_rate(sample_rate, &error)) { + g_warning("%s\n", error->message); + g_error_free(error); + return false; + } + soundfont_path = config_get_block_string(param, "soundfont", "/usr/share/sounds/sf2/FluidR3_GM.sf2"); @@ -82,11 +93,6 @@ fluidsynth_init(const struct config_param *param) static void fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) { - static const struct audio_format audio_format = { - .sample_rate = 48000, - .format = SAMPLE_FORMAT_S16, - .channels = 2, - }; char setting_sample_rate[] = "synth.sample-rate"; /* char setting_verbose[] = "synth.verbose"; @@ -104,7 +110,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) if (settings == NULL) return; - fluid_settings_setnum(settings, setting_sample_rate, 48000); + fluid_settings_setnum(settings, setting_sample_rate, sample_rate); /* fluid_settings_setstr(settings, setting_verbose, setting_yes); @@ -158,6 +164,8 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) /* initialization complete - announce the audio format to the MPD core */ + struct audio_format audio_format; + audio_format_init(&audio_format, sample_rate, SAMPLE_FORMAT_S16, 2); decoder_initialized(decoder, &audio_format, false, -1); while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) { -- cgit v1.2.3