在 windows - VB.Net 中生成声音频率
Generate sound frequency in windows - VB.Net
我需要在 windows 中生成方波声音。我正在使用此代码:
System.console.beep(500,500)
但效果不是很好:播放声音需要一点时间。
我有一个 2.7 GHZ CPU,所以我不认为我的电脑很慢。
有人知道在 windows 中播放频率的库或其他代码吗?
进口:
Imports System.IO
Imports 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
我需要在 windows 中生成方波声音。我正在使用此代码:
System.console.beep(500,500)
但效果不是很好:播放声音需要一点时间。 我有一个 2.7 GHZ CPU,所以我不认为我的电脑很慢。
有人知道在 windows 中播放频率的库或其他代码吗?
进口:
Imports System.IO
Imports 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