简体   繁体   English

C#中的声和弦?

[英]Sound chords in C#?

I've tried using Console.Beep() at low millisecond rates two play two frequencies 'at once', but the pause between beeps ruins it. 我已经尝试以低毫秒速率使用Console.Beep()两个“同时”播放两个频率,但是蜂鸣声之间的暂停会使它失效。 I have tried researching it but I've found nothing, and don't know where to start, aside from DirectSound, which I'm looking in to. 我已经尝试过研究但是我什么也没找到,除了我正在寻找的DirectSound之外,我不知道从哪里开始。 All I need is to make a program that plays two or more frequencies simultaneously out of one speaker, in C#. 我所需要的只是制作一个程序,用一个扬声器同时播放两个或多个频率,在C#中。

Thanks. 谢谢。

I suggest you look at DirectSound, which has nice .NET bindings. 我建议你看看DirectSound,它有很好的.NET绑定。 You can use two (or more) Buffer objects and invoke their Play methods to play them simultaneously. 您可以使用两个(或更多) Buffer对象并调用其Play方法来同时播放它们。

This tutorial shows how to implement a simple drum machine in C# by synthesising sounds on the fly. 本教程介绍如何通过动态合成声音在C#中实现简单的鼓机。 Hope it helps. 希望能帮助到你。

Try looking at using MIDI. 尝试使用MIDI。 This example should get you started. 这个例子可以帮助你入门。 It uses a MIDI library that several people recommend highly. 它使用了一些人们高度推荐的MIDI库。

Console.Beep() is synchronous and does not return until the sound is finished. Console.Beep()是同步的,直到声音结束才返回。

Try Simple DirectMedia Layer ( SDL.net ). 试试Simple DirectMedia Layer( SDL.net )。

Here's some very simple sample code that will let you play a WAV or MIDI file. 这里有一些非常简单的示例代码,可以让您播放WAV或MIDI文件。 This way you can write your code once then just maintain the wav or mid file if you want to make changes to the sound effect. 这样,您可以编写代码一次,然后只需要维护wav或mid文件,如果您想更改声音效果。

Play Any Sound File - C# ( Uses DirectX 9.0 for Managed Code ) 播放任何声音文件 - C# (使用DirectX 9.0作为托管代码)

If you know the frequencies beforehand you can synthesize them into a wave file (audacity or another similar program) and then play the wave file with the SoundPlayer class. 如果您事先知道频率,可以将它们合成为波形文件(大胆或其他类似程序),然后使用SoundPlayer类播放波形文件。

string path = /*path goes here*/;
player = new SoundPlayer(path);
player.Play();

If you need to synthesize them at runtime you would have to write the file by hand. 如果需要在运行时合成它们,则必须手动编写文件。 Here's a SO question that you can reference to build the wave files. 这是一个可以参考构建wave文件的SO问题。

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

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