[分享] mpd 调用 fluidsynth 播放 MIDI
本帖最后由 kappa8086 于 2015-4-3 17:54 编辑现在像我一样早年从 MIDI 时代走过来并有搜集大量 MIDI 音乐的估计不多了吧?
mpd 对 fluidsynth 是有内置插件支持的,但主要问题有几个
1 archlinux 下的 mpd 默认没启用这个功能,需要重新编译(其他发行版的暂不清楚)
2 fluidsynth CPU 占用太大,复杂一点的 MIDI 音乐 A20 根本撑不住
3 音量太小
因此从 mpd-git 重编译了一份
AUR 链接:
https://aur.archlinux.org/packages/mp/mpd-git/PKGBUILD
GIT:
git clone git://git.musicpd.org/master/mpd.git
)首先安装 fluidsynth。mpd 在configure阶段检测到fluidsynth就会自动开启 enable_fluidsynth 选项;
)安装soundfont-fluid。用过很多soundfont音色库,但GM的平衡性比这个好的没几个;
)然后,应用以下patchdiff --git a/src/decoder/plugins/FluidsynthDecoderPlugin.cxx b/src/decoder/plugins/FluidsynthDecoderPlugin.cxx
index 2b4967b..bb64b12 100644
--- a/src/decoder/plugins/FluidsynthDecoderPlugin.cxx
+++ b/src/decoder/plugins/FluidsynthDecoderPlugin.cxx
@@ -32,6 +32,8 @@
static constexpr Domain fluidsynth_domain("fluidsynth");
static unsigned sample_rate;
+static unsigned polyphony;
+static const char *gain;
static const char *soundfont_path;
/**
@@ -85,6 +87,8 @@ fluidsynth_init(const ConfigBlock &block)
soundfont_path = block.GetBlockValue("soundfont",
"/usr/share/sounds/sf2/FluidR3_GM.sf2");
+ gain = block.GetBlockValue("gain", "0.2");
+ polyphony = block.GetBlockValue("polyphony", 64);
fluid_set_log_function(LAST_LOG_LEVEL,
fluidsynth_mpd_log_function, nullptr);
@@ -113,6 +117,9 @@ fluidsynth_file_decode(Decoder &decoder, Path path_fs)
fluid_settings_setnum(settings, setting_sample_rate, sample_rate);
+ fluid_settings_setnum(settings, "synth.gain", atof(gain));
+ fluid_settings_setint(settings, "synth.polyphony", polyphony);
+
/*
fluid_settings_setstr(settings, setting_verbose, setting_yes);
*/
此 patch 会让 mpd 的配置文件对 fluidsynth 插件增加两个参数:gain(增益)和polyphony(复音数)。
通常只需要把复音数锁定在64以下,就没有卡的问题了,然而和命令行单独调用fluidsynth不一样,mpd还是会导致 CPU 单核心100%,另外试了下cpu-cores参数,居然没有效果
)编辑/etc/mpd.conf,增加以下代码decoder {
plugin "fluidsynth"
soundfont "/usr/share/soundfonts/FluidR3_GM2-2.sf2"
gain "1.0"
polyphony "48"
}
)编译安装mpd-git,过程中可能会报缺少其他库,比如 boost
)把MIDI扔进mpd的媒体目录下,mpc update 一下,客户端就能播放了
页:
[1]