vb.net 重复使用 beep(freq,duration)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19030666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:14:32  来源:igfitidea点击:

Using beep(freq,duration) Repeatedly

vb.netbeep

提问by Blake Stoddard

I have asked a question already that relates to the same project that I am working on. What I am trying to do, is create a piano, and have it to where the piano will play the correct note by either pressing the assigned key, or clicking the buttons.

我已经问过一个与我正在从事的同一个项目相关的问题。我想要做的是创建一架钢琴,并通过按下指定的键或单击按钮将其置于钢琴将演奏正确音符的位置。

Thus far, it works, but with limitations and I have not yet found a way around those. Through this site, I found the beep(freq, duration)command, which I have been using. That command has a limitation to where it can only do one note at a time, so if I run through all the notes, it will lag behind until it has played every note at the set duration.

到目前为止,它有效,但有局限性,我还没有找到解决这些问题的方法。通过这个站点,我找到了beep(freq, duration)我一直在使用的命令。该命令有一个限制,它一次只能做一个音符,所以如果我遍历所有的音符,它会滞后,直到它在设定的持续时间内播放了每个音符。

What I am looking to do, is to play the note as long as the button is being pressed, or the key is being pushed down, but also have the ability to play more than one note at a time. I know of the hardware limitations of most keyboard, but I would at least like to be able to press 3 keys at once, and have all three notes generate and play at the SAME time, not back to back after it has been through its set duration.

我想要做的是,只要按下按钮或按下琴键,就可以演奏音符,但也可以一次演奏多个音符。我知道大多数键盘的硬件限制,但我至少希望能够一次按下 3 个键,并且同时生成和播放所有三个音符,而不是在完成设置后背靠背期间。

The code I have been using:

我一直在使用的代码:

Beep(GlobalVariables.frqD, intDuration)

Beep(GlobalVariables.frqD, intDuration)

with Beep declared as:

Beep 声明为:

Private Declare Function Beep Lib "kernel32" (ByVal soundFrequency As Int32, ByVal soundDuration As Int32) As Int32

Private Declare Function Beep Lib "kernel32" (ByVal soundFrequency As Int32, ByVal soundDuration As Int32) As Int32

回答by NathanTempelman

Playing as long as the key is pressed should be easy.

只要按下键就可以轻松演奏。

while(keypressed)
{
    beep(freq,millisecond);
}

the frequency of the really short beeps should make it sound like a single note(temporal frequency, not auditory frequency, aha).

真正短的哔哔声的频率应该使它听起来像一个音符(时间频率,而不是听觉频率,啊哈)。

The thing about the beep method though, is last I checked it used the speaker on the motherboard, not your actual speakers. I could be wrong, but it seems as though you can't get more than one tone at a time. Try something like this, or just google yourself a proper audio playing library. That should be possible to create chords with.

不过,关于哔声的方法是最后一次我检查它使用的是主板上的扬声器,而不是您的实际扬声器。我可能是错的,但似乎一次只能听到一种音调。尝试像这样,还是只是谷歌自己一个正确的音频播放库。应该可以用它来创建和弦。