简体   繁体   English

如何从头开始创建声音C#

[英]How to create a sound from scratch C#

I am trying to build a virtual piano in C#, and want a way to create a scale of musical notes from scratch. 我正在尝试用C#构建一个虚拟钢琴,想要一种从头开始创建音符音阶的方法。

I know that I can simply find or create a bunch of .wav files, 1 for each note, but this will create too much space on the User's Hard disk and not be very intuative for myself in the future. 我知道我可以简单地找到或创建一堆.wav文件,每个音符1个,但是这会在用户的硬盘上创建太多空间,并且对我自己来说不是很直观。

So is there a way to create a proper sound - eg B flat, in C# without using a .wav file, all in code thorugh c#, and if not, is there a way to do this in a different language - C++. 那么有没有办法在不使用.wav文件的情况下在C#中创建一个合适的声音 - 例如B flat,所有代码都是#,如果没有,有没有办法用不同的语言 - C ++。

Thanks, I have tried to make it as clear as possible. 谢谢,我尽力让它变得清晰。

I think this looks like it should get you started: 我认为这看起来应该让你开始:

http://blogs.msdn.com/b/dawate/archive/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c.aspx http://blogs.msdn.com/b/dawate/archive/2009/06/24/intro-to-audio-programming-part-3-synthesizing-simple-wave-audio-using-c.aspx

EDIT : I should add that generating sounds without .wav samples and emulating a piano are at odds with each other. 编辑:我应该补充说,生成没有.wav样本和模拟钢琴的声音是相互矛盾的。

If you want to get a 'real' piano sound, it's best to work with samples (hold them in memory if you don't want to keep them in the filesystem). 如果你想获得一个“真正的”钢琴音色,最好使用样本(如果你不想将它们保存在文件系统中,请将它们保存在内存中)。 If you just want a simple way of emitting accurate notes (which sound nothing like a real piano) then doing it programmatically is the way to go! 如果你只是想要一种简单的方法来发出准确的音符(听起来就像真正的钢琴一样),那么以编程方式进行操作就是要走的路!

If you want to emulate a piano specifically you only have two options, one of which is to use samples and the other is physical modelling . 如果你想特别模仿钢琴,你只有两个选项,一个是使用样本,另一个是物理建模 Physical modelling requires some pretty advanced knowledge of DSP (filtering, convolution, etc.) and a piano would be a challenging instrument to tackle but it has been done by the likes of Pianoteq 物理建模需要一些非常先进的DSP知识(滤波,卷积等),钢琴将成为一个具有挑战性的工具,但它已经由Pianoteq等人完成。

On the subject of samples, to create a piano that is anywhere near a convincing analogue you would ideally require more than one sample per note for different velocities with crossfades between them but you can probably get away with using a sample over a limited range of notes to reduce the total number of samples. 关于样本的主题,要创建一个接近令人信服的模拟的钢琴,理想情况下,每个音符需要不同的样本以获得不同的速度,并且它们之间有交叉淡化,但是你可以在有限的音符范围内使用样本。减少样本总数。

You might want to take a look at MIDI. 你可能想看看MIDI。

There's a windows API you could wrap in C++, then expose a managed interface you can consume in C#. 你可以用C ++包装一个Windows API ,然后公开你可以在C#中使用的托管界面。

Maybe using a MIDI library could help? 也许使用MIDI库可以帮助? I'm not into the matter, but if you don't want to use audio files it's the only thing that comes to my mind. 我不是这个问题,但如果你不想使用音频文件,那么我就会想到这一点。 There's a question about it here . 有一个关于它的问题在这里

在这里你可以找到一篇文章,其中包括如何从零开始创建至少一个八度音符音符的钢琴声音的源(它是可扩展的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM