日本恐怖片鸡皮疙瘩:谁能看懂下列画波形的算法(VB)

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/07 11:04:44
Public Sub DrawWaves()
' Graph the waveform
Dim x As Long ' current X position
Dim leftYOffset As Long ' Y offset for left channel graph
Dim rightYOffset As Long ' Y offset for right channel graph
Dim curLeftY As Long ' current left channel Y value
Dim curRightY As Long ' current right channel Y value
Dim lastX As Long ' last X position
Dim lastLeftY As Long ' last left channel Y value
Dim lastRightY As Long ' last right channel Y value
Dim maxAmplitude As Long ' the maximum amplitude for a wavegraph on the form
Dim leftVol As Double ' buffer for retrieving the left volume level
Dim rightVol As Double ' buffer for retrieving the right volume level
Dim scaleFactor As Double ' samples per pixel on the wave graph
Dim xStep As Double ' pixels per sample on the wave graph
Dim curSample As Long ' current sample number

' clear the screen
Me.Cls

' if no file is loaded, don't try to draw graph
If (Module1.fFileLoaded = False) Then
Exit Sub
End If

' calculate drawing parameters
scaleFactor = (Module1.drawTo - Module1.drawFrom) / Me.Width
If (scaleFactor < 1) Then
xStep = 1 / scaleFactor
Else
xStep = 1
End If

' Draw the graph
If (Module1.format.nChannels = 2) Then
maxAmplitude = Me.Height / 4
leftYOffset = maxAmplitude
rightYOffset = maxAmplitude * 3

For x = 0 To Me.Width Step xStep
curSample = scaleFactor * x + Module1.drawFrom
If (Module1.format.wBitsPerSample = 16) Then
GetStereo16Sample curSample, leftVol, rightVol
Else
GetStereo8Sample curSample, leftVol, rightVol
End If
curRightY = CLng(rightVol * maxAmplitude)
curLeftY = CLng(leftVol * maxAmplitude)
Line (lastX, leftYOffset + lastLeftY)-(x, curLeftY + leftYOffset)
Line (lastX, rightYOffset + lastRightY)-(x, curRightY + rightYOffset)
lastLeftY = curLeftY
lastRightY = curRightY
lastX = x
Next
Else
maxAmplitude = Me.Height / 2
leftYOffset = maxAmplitude

For x = 0 To Me.Width Step xStep
curSample = scaleFactor * x + Module1.drawFrom
If (Module1.format.wBitsPerSample = 16) Then
GetMono16Sample curSample, leftVol
Else
GetMono8Sample curSample, leftVol
End If
curLeftY = CLng(leftVol * maxAmplitude)
Line (lastX, leftYOffset + lastLeftY)-(x, curLeftY + leftYOffset)
lastLeftY = curLeftY
lastX = x
Next
End If

End Sub
看懂的请解释一下,以下几个答案为废话,不解释有什么用处

基本上能看懂
单引号后面的是解释说明 你可以拿个金山词霸对照着看,会有帮助的。
还有不明白的请补充。

给分吧