如何在c#中将midi转换为wav / mp3?

时间:2022-10-17 19:44:37

I started a small project which includes working with MIDI files. I've been wondering, is there any C# or VB.Net code that peforms that cast between MIDI and WAV files?

我开始了一个小项目,包括使用MIDI文件。我一直在想,是否有任何C#或VB.Net代码可以实现MIDI和WAV文件之间的转换?

3 个解决方案

#1


You could try to somehow interface with Timidity, which is Open Source:

你可以尝试以某种方式与Timidity接口,这是开源的:

TiMidity++ is a software synthesizer. It can play MIDI files by converting them into PCM waveform data; give it a MIDI data along with digital instrument data files, then it synthesizes them in real-time, and plays. It can not only play sounds, but also can save the generated waveforms into hard disks as various audio file formats.

TiMidity ++是一个软件合成器。它可以通过将MIDI文件转换为PCM波形数据来播放MIDI文件;给它一个MIDI数据和数字乐器数据文件,然后实时合成它们并播放。它不仅可以播放声音,还可以将生成的波形作为各种音频文件格式保存到硬盘中。

FluidSynth is a more recently updated Open Source project in a similar vein:

FluidSynth是一个类似的最近更新的开源项目:

FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications.

FluidSynth是基于SoundFont 2规范的实时软件合成器。

You can download some free SoundFonts (the actual PCM data used by these synthesizers to "render" the MIDI files) from the sites on this list.

您可以从此列表中的站点下载一些免费的SoundFonts(这些合成器使用的实际PCM数据来“渲染”MIDI文件)。

#2


MIDI files contain only note and controller information, not sounds. In order to get sounds from a MIDI file, you have to pass the file through a music synthesizer or sampler, which will convert the note and controller information into actual sounds.

MIDI文件仅包含音符和控制器信息,而不包含声音。为了从MIDI文件中获取声音,您必须通过音乐合成器或采样器传递文件,音乐合成器或采样器会将音符和控制器信息转换为实际声音。

In practice this means that any given MIDI file doesn't have a specific sound to it. The sound that results from converting a MIDI file to audio will vary depending on the quality of the synthesizer or sample library, and the sounds that are selected to perform the conversion.

实际上,这意味着任何给定的MIDI文件都没有特定的声音。将MIDI文件转换为音频所产生的声音将根据合成器或样本库的质量以及为执行转换而选择的声音而有所不同。

Many sound cards have the capability of producing sound from MIDI files. They can do this because many MIDI files follow a standard called the General MIDI specification. The General MIDI Specification provides a standardized way to map specific instrument assignments. If your MIDI file conforms to this standard, you can play it through a General MIDI sound generator and expect a snare drum to sound like a snare drum, and not like a trumpet.

许多声卡都能够从MIDI文件中产生声音。他们可以这样做,因为许多MIDI文件遵循称为通用MIDI规范的标准。通用MIDI规范提供了映射特定仪器分配的标准化方法。如果您的MIDI文件符合此标准,您可以通过通用MIDI声音发生器播放它,并期望小鼓听起来像军鼓,而不是像小号。

If you have a sophisticated music production package like Cakewalk, you can load a MIDI file into it, and it will use its on-board sound libraries to render a sound file for you, and this can actually be done faster than real-time (i.e. it doesn't have to play the sound through the sound card and capture the output).

如果你有一个像Cakewalk这样复杂的音乐制作软件包,你可以加载一个MIDI文件,它会使用它的板载声音库为你渲染一个声音文件,这实际上可以比实时更快地完成(即它不必通过声卡播放声音并捕获输出)。

I guess what I'm trying to say is there's a lot of moving parts to this. There isn't a single piece of code or a class module that will do this for you.

我想我想说的是这里有很多活动部分。没有一段代码或类模块可以为您执行此操作。

#3


There are a number of programs you can purchase that will do this (google "convert midi to WAV"), but I've never come across publically-available .Net code that does this (I think some of these programs are written in .Net, but the source code is not available).

你可以购买许多程序来执行此操作(google“将midi转换为WAV”),但我从来没有遇到过这样做的公共可用的.Net代码(我认为其中一些程序是用这些程序编写的)。网,但源代码不可用)。

I have an online friend who is working on a commercial MIDI-to-WAV converter, but it isn't in .Net and it won't be open source. As Robert Harvey mentioned, this is not a simple task at all, as it basically involves writing your own software synthesizer (a task after my own heart).

我有一个在线朋友正在研究商用MIDI-to-WAV转换器,但它不在.Net中,它不会是开源的。正如罗伯特哈维所提到的,这根本不是一项简单的任务,因为它基本上涉及编写自己的软件合成器(我心中的任务)。

#1


You could try to somehow interface with Timidity, which is Open Source:

你可以尝试以某种方式与Timidity接口,这是开源的:

TiMidity++ is a software synthesizer. It can play MIDI files by converting them into PCM waveform data; give it a MIDI data along with digital instrument data files, then it synthesizes them in real-time, and plays. It can not only play sounds, but also can save the generated waveforms into hard disks as various audio file formats.

TiMidity ++是一个软件合成器。它可以通过将MIDI文件转换为PCM波形数据来播放MIDI文件;给它一个MIDI数据和数字乐器数据文件,然后实时合成它们并播放。它不仅可以播放声音,还可以将生成的波形作为各种音频文件格式保存到硬盘中。

FluidSynth is a more recently updated Open Source project in a similar vein:

FluidSynth是一个类似的最近更新的开源项目:

FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications.

FluidSynth是基于SoundFont 2规范的实时软件合成器。

You can download some free SoundFonts (the actual PCM data used by these synthesizers to "render" the MIDI files) from the sites on this list.

您可以从此列表中的站点下载一些免费的SoundFonts(这些合成器使用的实际PCM数据来“渲染”MIDI文件)。

#2


MIDI files contain only note and controller information, not sounds. In order to get sounds from a MIDI file, you have to pass the file through a music synthesizer or sampler, which will convert the note and controller information into actual sounds.

MIDI文件仅包含音符和控制器信息,而不包含声音。为了从MIDI文件中获取声音,您必须通过音乐合成器或采样器传递文件,音乐合成器或采样器会将音符和控制器信息转换为实际声音。

In practice this means that any given MIDI file doesn't have a specific sound to it. The sound that results from converting a MIDI file to audio will vary depending on the quality of the synthesizer or sample library, and the sounds that are selected to perform the conversion.

实际上,这意味着任何给定的MIDI文件都没有特定的声音。将MIDI文件转换为音频所产生的声音将根据合成器或样本库的质量以及为执行转换而选择的声音而有所不同。

Many sound cards have the capability of producing sound from MIDI files. They can do this because many MIDI files follow a standard called the General MIDI specification. The General MIDI Specification provides a standardized way to map specific instrument assignments. If your MIDI file conforms to this standard, you can play it through a General MIDI sound generator and expect a snare drum to sound like a snare drum, and not like a trumpet.

许多声卡都能够从MIDI文件中产生声音。他们可以这样做,因为许多MIDI文件遵循称为通用MIDI规范的标准。通用MIDI规范提供了映射特定仪器分配的标准化方法。如果您的MIDI文件符合此标准,您可以通过通用MIDI声音发生器播放它,并期望小鼓听起来像军鼓,而不是像小号。

If you have a sophisticated music production package like Cakewalk, you can load a MIDI file into it, and it will use its on-board sound libraries to render a sound file for you, and this can actually be done faster than real-time (i.e. it doesn't have to play the sound through the sound card and capture the output).

如果你有一个像Cakewalk这样复杂的音乐制作软件包,你可以加载一个MIDI文件,它会使用它的板载声音库为你渲染一个声音文件,这实际上可以比实时更快地完成(即它不必通过声卡播放声音并捕获输出)。

I guess what I'm trying to say is there's a lot of moving parts to this. There isn't a single piece of code or a class module that will do this for you.

我想我想说的是这里有很多活动部分。没有一段代码或类模块可以为您执行此操作。

#3


There are a number of programs you can purchase that will do this (google "convert midi to WAV"), but I've never come across publically-available .Net code that does this (I think some of these programs are written in .Net, but the source code is not available).

你可以购买许多程序来执行此操作(google“将midi转换为WAV”),但我从来没有遇到过这样做的公共可用的.Net代码(我认为其中一些程序是用这些程序编写的)。网,但源代码不可用)。

I have an online friend who is working on a commercial MIDI-to-WAV converter, but it isn't in .Net and it won't be open source. As Robert Harvey mentioned, this is not a simple task at all, as it basically involves writing your own software synthesizer (a task after my own heart).

我有一个在线朋友正在研究商用MIDI-to-WAV转换器,但它不在.Net中,它不会是开源的。正如罗伯特哈维所提到的,这根本不是一项简单的任务,因为它基本上涉及编写自己的软件合成器(我心中的任务)。