CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 8587|回复: 0

[分享] mpd 调用 fluidsynth 播放 MIDI

[复制链接]
发表于 2015-4-3 17:46:35 | 显示全部楼层 |阅读模式
本帖最后由 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的平衡性比这个好的没几个;

)然后,应用以下patch
  1. diff --git a/src/decoder/plugins/FluidsynthDecoderPlugin.cxx b/src/decoder/plugins/FluidsynthDecoderPlugin.cxx
  2. index 2b4967b..bb64b12 100644
  3. --- a/src/decoder/plugins/FluidsynthDecoderPlugin.cxx
  4. +++ b/src/decoder/plugins/FluidsynthDecoderPlugin.cxx
  5. @@ -32,6 +32,8 @@
  6. static constexpr Domain fluidsynth_domain("fluidsynth");

  7. static unsigned sample_rate;
  8. +static unsigned polyphony;
  9. +static const char *gain;
  10. static const char *soundfont_path;

  11. /**
  12. @@ -85,6 +87,8 @@ fluidsynth_init(const ConfigBlock &block)

  13.         soundfont_path = block.GetBlockValue("soundfont",
  14.                                              "/usr/share/sounds/sf2/FluidR3_GM.sf2");
  15. +       gain = block.GetBlockValue("gain", "0.2");
  16. +       polyphony = block.GetBlockValue("polyphony", 64);

  17.         fluid_set_log_function(LAST_LOG_LEVEL,
  18.                                fluidsynth_mpd_log_function, nullptr);
  19. @@ -113,6 +117,9 @@ fluidsynth_file_decode(Decoder &decoder, Path path_fs)

  20.         fluid_settings_setnum(settings, setting_sample_rate, sample_rate);

  21. +       fluid_settings_setnum(settings, "synth.gain", atof(gain));
  22. +       fluid_settings_setint(settings, "synth.polyphony", polyphony);
  23. +
  24.         /*
  25.         fluid_settings_setstr(settings, setting_verbose, setting_yes);
  26.         */
复制代码
此 patch 会让 mpd 的配置文件对 fluidsynth 插件增加两个参数:gain(增益)和polyphony(复音数)。
通常只需要把复音数锁定在64以下,就没有卡的问题了,然而和命令行单独调用fluidsynth不一样,mpd还是会导致 CPU 单核心100%,另外试了下cpu-cores参数,居然没有效果

)编辑/etc/mpd.conf,增加以下代码
  1. decoder {
  2.     plugin "fluidsynth"
  3.     soundfont "/usr/share/soundfonts/FluidR3_GM2-2.sf2"
  4.     gain "1.0"
  5.     polyphony "48"
  6. }
复制代码
)编译安装mpd-git,过程中可能会报缺少其他库,比如 boost

)把MIDI扔进mpd的媒体目录下,mpc update 一下,客户端就能播放了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-4-20 02:26 , Processed in 0.020722 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部