# DirectMusic：微软音乐 API 的开源重新实现

> 以可移植的 C11 库重新实现 DirectMusic，即 Microsoft 随早期 DirectX 提供的自适应配乐 API；它载入游戏的段落（segment）、风格（style）和 DLS 音色文件，并将音乐渲染为 PCM。README 只列出 Gothic 与 Gothic II（含 Night of the Raven）的配乐经过测试，且只是“大致”正确；项目自称尚不完整、仍在大力开发中。乐器经 DLS 转 SoundFont 后由内置的 TinySoundFont 合成器发声。

- 类型：案例
- 目标：游戏
- 类别：独立重建案例
- 关联：独立重建项目
- 来源复核于：2026-10-19
- 收录于：2026-11-09
- 原始资源：<https://github.com/GothicKit/dmusic>
- 一手来源：<https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/README.md>
- 目录页面：<https://awesomerea.org/zh/resources/dmusic-directmusic-reimplementation-case/>
- 记录 JSON：<https://awesomerea.org/resources/dmusic-directmusic-reimplementation-case/record.json>
- 英文版：[English](https://awesomerea.org/resources/dmusic-directmusic-reimplementation-case/index.md)

## 使用条件与局限

- 该 C11 库提供自己的 DmLoader、DmSegment 和 DmPerformance API。“结尾加前奏”装饰及部分曲线和消息类型尚未实现。
- 使用者需通过解析回调提供自己游戏数据中的 .sgt 段落、.sty 风格和 .dls 音色集；仓库不附带这些文件。
- 构建需要 C11 编译器和 CMake 3.10+。支持 Linux、macOS 和 Windows。play-segment 示例需要 <unistd.h> 和 <sys/stat.h>。
- README 报告 Gothic 与 Gothic II 配乐运行“大致”正确。CI 为 Linux、Android、macOS 和 Windows 构建库；未列出测试套件或与 Microsoft 运行时输出的比较。
- LICENSE.md 对项目代码采用 MIT 许可证（现代变体）。TinySoundFont、miniaudio 和 Gothic II 主题曲渲染有各自权利；游戏音乐保留原有权利。

## 一手来源

1. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/README.md>
2. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/include/dmusic.h>
3. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/CMakeLists.txt>
4. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/src/util/Tsf.c>
5. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/src/Performance.c>
6. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/src/_Internal.h>
7. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/examples/play-segment.c>
8. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/.github/workflows/build.yml>
9. <https://github.com/GothicKit/dmusic/blob/b73b270b94714b8ec8d9d0b2a9f3a5c445da52d1/LICENSE.md>
10. <https://dm.gothickit.dev/>

## 同分区更多条目：游戏

- [Dishonored：重建兼容 Windows XP 的商店接口 DLL](https://awesomerea.org/zh/resources/dishonored-xp-stub-case/index.md) · 案例
- [DLSSNR-AMD：为 RDNA4 重新实现 DLSS 5 神经渲染](https://awesomerea.org/zh/resources/dlssnr-amd-neural-rendering-case/index.md) · 案例
- [dndserver：重建 Dark and Darker 服务端](https://awesomerea.org/zh/resources/dndserver-case/index.md) · 案例
- [Dodge It：《Dodge It》Fairchild Channel F 注释反汇编](https://awesomerea.org/zh/resources/dodge-it-videocart-16-case/index.md) · 案例
- [逆向工程需要更大的模型吗？东方 Project 重建中的通用模型与专用模型](https://awesomerea.org/zh/resources/rea-bigger-model-essay-case/index.md) · 案例
- [Dogfish：重建 Conquest of Skyrim 的战略系统](https://awesomerea.org/zh/resources/dogfish-conquest-of-skyrim-case/index.md) · 案例

## 关于此条目

说明已依据一手来源复核。
原创说明采用 MIT 许可；外部项目、论文与素材保留各自的权利和许可。
