⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form2.frm

📁 vb精彩编程希望大家有用
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form2 
   Caption         =   "波形窗口"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form2"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Visible         =   0   'False
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Sub DrawWaves()
' 绘制波形
   Dim x As Long               ' X位置
   Dim leftYOffset As Long     ' Y  左声道Y方向偏移
   Dim rightYOffset As Long    ' Y  右声道Y方向偏移
   Dim curLeftY As Long        ' 左声道Y方向值
   Dim curRightY As Long       ' 右声道Y方向值
   Dim lastX As Long           ' 最后X位置
   Dim lastLeftY As Long       ' 最后左声道Y值
   Dim lastRightY As Long      ' 最后右声道Y值
   Dim maxAmplitude As Long    ' 图象在窗体中的最大宽度
   Dim leftVol As Double       ' 左音量
   Dim rightVol As Double      ' 右音量
   Dim scaleFactor As Double   ' 在图像上的采样率
   Dim xStep As Double         ' 在图像上每采样占的点数
   Dim curSample As Long       ' 当前采样值
   ' 清屏
   Me.Cls
   ' 如果没有文件,退出
   If (Module1.fFileLoaded = False) Then
       Exit Sub
   End If
   ' 计算绘图的参数
   scaleFactor = (Module1.drawTo - Module1.drawFrom) / Me.Width
   If (scaleFactor < 1) Then
       xStep = 1 / scaleFactor
   Else
       xStep = 1
   End If
   ' 绘制波形图
   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
Private Sub Form_Paint()
   DrawWaves
End Sub
Private Sub Form_Resize()
   DrawWaves
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -