📄 funcgen.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "FunctionGenerator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Dim tmFunGen As Timer
Dim sample_rate As Long
Dim samp_buf(512) As Double
Const nsamples = 512
Dim ampl As Double
Public Property Get SamplingRate() As Variant
Sampling_Rate = sample_rate
End Property
Public Property Let SamplingRate(vNewValue As Variant)
sample_rate = vNewValue
End Property
Public Property Get Samples() As Variant
Samples = samp_buf
End Property
Public Property Get NumSamples() As Variant
NumSamples = nsamples
End Property
'Public Property Let NumSamples(ByVal vNewValue As Variant)
'nsamples = vNewValue
'End Property
Public Function GenSine(Frequency As Long)
For cnt = 1 To nsamples
samp_buf(cnt) = samp_buf(cnt) + (ampl * Sin(2 * 3.141592658 * Frequency * (cnt / sample_rate)))
Next cnt
End Function
Public Sub Clear()
For cnt = 1 To nsamples
samp_buf(cnt) = 0
Next cnt
End Sub
Public Property Get amplitude() As Variant
Attribute amplitude.VB_Description = "Sets Amplitude of the wave"
amplitude = ampl
End Property
Public Property Let amplitude(ByVal vNewValue As Variant)
ampl = vNewValue
End Property
Public Function GenCos(Frequency As Long)
For cnt = 1 To nsamples
samp_buf(cnt) = samp_buf(cnt) + (ampl * Cos(2 * 3.141592658 * Frequency * (cnt / sample_rate)))
Next cnt
End Function
Public Sub GenImpulse(position As Integer)
samp_buf(position) = samp_buf(position) + ampl
End Sub
Public Sub GenSquare(Frequency As Long)
On Error Resume Next
polarity = 0
ontime = 512 / (2 * Frequency)
For cnt = 0 To (512 / ontime)
For cnt2 = 0 To ontime
If (polarity = 0) Then
samp_buf((cnt * ontime) + cnt2) = ampl
Else
samp_buf((cnt * ontime) + cnt2) = -ampl
End If
Next cnt2
If polarity = 0 Then
polarity = 1
Else
polarity = 0
End If
Next cnt
End Sub
Public Sub ApplyHamming()
For cnt = 1 To 512
samp_buf(cnt) = samp_buf(cnt) * (0.54 - (0.46 * Cos(2 * 3.14159265 * cnt / 512)))
Next cnt
End Sub
Public Sub ApplyHanning()
For cnt = 1 To 512
samp_buf(cnt) = samp_buf(cnt) * (0.5 - (0.5 * Cos(2 * 3.14159265 * cnt / 512)))
Next cnt
End Sub
Public Sub ApplyBlackman()
For cnt = 1 To 512
samp_buf(cnt) = samp_buf(cnt) * (0.42 - (0.5 * Cos(2 * 3.14159265 * cnt / 512)) + (0.08 * Cos(4 * 3.14159265 * cnt / 512)))
Next cnt
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -