不定系统扬声器蜂鸣声
现在,我知道我可以使用 Console.Beep
播放设定持续时间的蜂鸣声,但我正在寻找的是一种无限期地播放特定频率声音的方法,例如开始和停止功能。有什么想法吗?
Now, I know that I can play a beep of a set duration with Console.Beep
, but what I'm looking for is a way to indefinitely play a sound of a certain frequency, like a start and stop function. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想发出控制台命名空间中提供的蜂鸣声以外的蜂鸣声,则必须直接与扬声器交谈。使用 Kernel32.dll 来执行此操作,如下所示:
首先确保包含互操作:
然后为 Beep 添加 extern 方法,并从其他方法中使用它,这个方法将使扬声器以您想要的频率发出蜂鸣声。给它。
If you want to make a beep other than the one offered in the Console namespace you have to talk directly to the speaker. Use the Kernel32.dll to do this like so:
First make sure to include interop:
Then add the extern method for Beep, and use it from your other methods, this one will beep the speaker for as long as you want at the frequency you give it.
您也许可以使用MIDI。
您还可以使用 PlaySound API 循环播放 WAV 文件指定 SND_LOOP 和 SND_ASYNC 的调用。
在现代 PC 上无限期地播放相同声音的概念有点变化无常,除非您处于可以编写和控制无限循环或只是以特定频率“打开”扬声器的硬件级别。更高级别的 API 和编程语言不会允许这样做,因为在该级别上,操作系统迫使您与其他应用程序良好地合作。
编辑
还应该注意的是,Beep 调用的持续时间以毫秒为单位,并且它确实采用 Int32 值。 Int32.MaxValue 毫秒是很长的时间。可能比任何人都更能忍受听到嘟嘟声。
You may be able to use MIDI.
You may also be able to loop a WAV file using the PlaySound API call with SND_LOOP and SND_ASYNC specified.
The concept of playing the same sound indefinitely on a modern PC is somewhat fickle unless you are at the the hardware level where you can write and control an infinite loop or just "turn on" the speaker at a certain frequency. The higher level API's and programming languages aren't going to allow this as, at that level, the OS is forcing you to play nice with other applications.
Edit
It should also be noted that the duration of the Beep call is in milliseconds and it does take an Int32 value. Int32.MaxValue milliseconds is looooong time. Probably more than anyone could stand listening to the beep.
与这些问题一样,第一反应应该是:
你真正想要实现什么目标。您真的想要无限持续时间的蜂鸣声,还是想要播放更长的声音?
As always in these questions, the first response should be:
What are you really trying to accomplish. Do you really want a beep of indefinite duration, or do you want to play sounds for longer periods?