我正在学习使用SharpDevelop的C#和Winforms并试图做一个非常简单的合成器。我只想在按下按钮时播放正弦波,并在正弦波释放时停止正弦波。以下是相关代码:
public class SharpSynth : Form
{
Timer myTimer = new Timer();
public SharpSynth()
{
myTimer.Interval = 500;
myTimer.Start();
Button SineButton = new Button();
SineButton.MouseDown += new EventHandler(ButtonDown);
SineButton.MouseUp += new EventHandler(ButtonUp);
Controls.Add(SineButton);
}
private void ButtonDown(object sender, System.EventArgs e)
{
myTimer.Tick += new EventHandler(WriteSine);
}
private void ButtonUp(object sender, System.EventArgs e)
{
myTimer.Tick -= EventHandler(WriteSine);
}
private void WriteSine()
{}
}
我已经看到使用MemoryStream和SoundPlayer写入流的波形文件,但似乎这些需要波形标题,其中一个是样本数量,另一个是文件大小。我需要能够写出任意长度的原始音频。或者每个标记的每个块是否都有自己的波形标题?我真的只是想知道在WriteSine函数中放入什么来使其工作。我见过NAudio推荐,但我想首先学习纯.NET库。
编辑:我在这里有一些相关的问题和研究
Creating sine or square wave in C#
Best way to use the System.Media.Soundplayer class
我只是不确定如何使用它们。