在windows-VB.Net中生成音频
我需要在窗口中产生方波声音。我正在使用以下代码:在windows-VB.Net中生成音频,vb.net,audio,beep,Vb.net,Audio,Beep,我需要在窗口中产生方波声音。我正在使用以下代码: System.console.beep(500,500) 但效果不太好:播放声音需要一点时间。 我有一个2.7GHz的CPU,所以我不认为我的电脑慢 有人知道在windows中播放频率的库或其他代码吗?导入: Imports System.IO Imports System.Media 电话: 分: 我想这就是你要找的。不幸的是,不,我想在没有System.console.beep()的情况下继续播放声音频率。我有一个问题,这段代码:Soun
System.console.beep(500,500)
但效果不太好:播放声音需要一点时间。
我有一个2.7GHz的CPU,所以我不认为我的电脑慢
有人知道在windows中播放频率的库或其他代码吗?导入:
Imports System.IO
Imports System.Media
电话:
分:
我想这就是你要找的。不幸的是,不,我想在没有System.console.beep()的情况下继续播放声音频率。我有一个问题,这段代码:SoundPlayer没有定义。你导入了System.Media吗?哦,是的,我忘了导入System.Media,现在它可以工作了。非常感谢你!
FrequencyBeep(500, 500, 10000)
Public Shared Sub FrequencyBeep(ByVal Amplitude As Integer, ByVal Frequency As Integer, ByVal Duration As Integer)
Dim A As Double = ((Amplitude * (System.Math.Pow(2, 15))) / 1000) - 1
Dim DeltaFT As Double = 2 * Math.PI * Frequency / 44100.0
Dim Samples As Integer = 441 * Duration / 10
Dim Bytes As Integer = Samples * 4
Dim Hdr As Integer() = {1179011410, 36 + Bytes, 1163280727, 544501094, 16, 131073, 44100, 176400, 1048580, 1635017060, Bytes}
Using MS As MemoryStream = New MemoryStream(44 + Bytes)
Using BW As BinaryWriter = New BinaryWriter(MS)
For I As Integer = 0 To Hdr.Length - 1
BW.Write(Hdr(I))
Next
For T As Integer = 0 To Samples - 1
Dim Sample As Short = System.Convert.ToInt16(A * Math.Sin(DeltaFT * T))
BW.Write(Sample)
BW.Write(Sample)
Next
BW.Flush()
MS.Seek(0, SeekOrigin.Begin)
Using SP As SoundPlayer = New SoundPlayer(MS)
SP.PlaySync()
End Using
End Using
End Using
End Sub