| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 684 人关注过本帖
标题:这是个wav文件波形示例,但显示总有些不正常,多了一些条码样的线条,谁能帮我 ...
取消只看楼主 加入收藏
ymm0792
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-12-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
这是个wav文件波形示例,但显示总有些不正常,多了一些条码样的线条,谁能帮我看看什么改,谢谢了
Option Explicit
Dim DAT() As Byte         '样本数据

Private Sub 绘制_Click()
On Error GoTo 100
Dim filename As String
Dim tagType As String * 4 '标记字符
Dim dataSum As Long       '样本数据个数
Dim Channels As Integer   '声道数
Dim SampleBit As Integer  '量化位数
Dim Temp1 As Long

CommonDialog1.filename = "*.wav"
CommonDialog1.DefaultExt = ".wav"
CommonDialog1.ShowOpen
filename = CommonDialog1.filename
Open filename For Binary As #1

Get #1, , tagType
If tagType <> "RIFF" Then GoTo 100 '如果不是RIFF退出
Get #1, 9, tagType
If tagType <> "WAVE" Then GoTo 100 '如果不是WAVE退出
Get #1, , tagType
If tagType <> "fmt " Then GoTo 100 '如果不是fmt 退出

Get #1, , dataSum         '格式块长度
Get #1, 23, Channels      '声道数
Get #1, 35, SampleBit     '量化位数
Get #1, 21 + dataSum, tagType
If tagType = "fact" Then  '如果是附加块
  Get #1, , Temp1         '废弃
  Get #1, , Temp1         '废弃
  Get #1, , tagType       '废弃
  Get #1, , dataSum       '数据块长度
ElseIf tagType = "data" Then
  Get #1, , dataSum       '数据块长度
Else
  GoTo 100
End If

ReDim DAT(dataSum)
Get #1, , DAT
Close #1

Select Case Channels         '绘制波形
  Case 1                     '单声道
    Select Case SampleBit
      Case 8:  DrawWaves8_1 Picture1   '如果是8位
      Case 16: DrawWaves16_1 Picture1 '如果是16位
    End Select
  Case 2                     '立体声
    Select Case SampleBit
      Case 8:  DrawWaves8_2 Picture1   '如果是8位
      Case 16: DrawWaves16_2 Picture1 '如果是16位
    End Select
End Select
Exit Sub

100
Close #1
End Sub

Private Sub DrawWaves8_1(WavBox As PictureBox)
Dim i As Long
Dim exten As Long  '波幅
Dim lastX As Long  '水平坐标
Dim curY1 As Long  '垂直坐标
Dim curY2 As Long  '垂直坐标

WavBox.WavBox.ScaleWidth = UBound(DAT) '窗体宽度=样本个数
exten = WavBox.ScaleHeight / 2  '波幅=窗体高度的二分之一
WavBox.Cls

For i = 0 To WavBox.ScaleWidth
  curY1 = (DAT(i) - 128) / 128 * exten '垂直坐标=样本数据*最大波幅
  WavBox.Line (lastX, exten + curY2)-(i, exten + curY1)
  curY2 = curY1: lastX = i
Next
End Sub

Private Sub DrawWaves8_2(WavBox As PictureBox)
Dim i As Long
Dim exten As Long    '波幅
Dim lastX As Long    '水平坐标
Dim curLY1 As Long   '左声道垂直坐标
Dim curLY2 As Long   '左声道垂直坐标
Dim curRY1 As Long   '右声道垂直坐标
Dim curRY2 As Long   '右声道垂直坐标
Dim LYOffset As Long '左声道垂直偏移量
Dim RYOffset As Long '右声道垂直偏移量

WavBox.ScaleWidth = UBound(DAT) / 2 '窗体宽度=单声道样本个数
exten = WavBox.ScaleHeight / 4      '最大波幅为窗体高度的四分之一
LYOffset = exten
RYOffset = exten * 3
WavBox.Cls

For i = 0 To WavBox.ScaleWidth
  curLY1 = (DAT(i * 2) - 128) / 128 * exten
  curRY1 = (DAT(i * 2 + 1) - 128) / 128 * exten
  WavBox.Line (lastX, LYOffset + curLY2)-(i, LYOffset + curLY1) '画左声道波形
  WavBox.Line (lastX, RYOffset + curRY2)-(i, RYOffset + curRY1) '画右声道波形
  curLY2 = curLY1: curRY2 = curRY1: lastX = i
Next
End Sub

Private Sub DrawWaves16_1(WavBox As PictureBox)
Dim i As Long, d As String
Dim exten As Long  '波幅
Dim lastX As Long  '水平坐标
Dim curY1 As Long  '垂直坐标
Dim curY2 As Long  '垂直坐标

WavBox.ScaleWidth = UBound(DAT) / 2 '窗体宽度=样本个数
exten = WavBox.ScaleHeight / 2      '波幅=窗体高度的二分之一
WavBox.Cls

For i = 0 To WavBox.ScaleWidth
  d = "&H" & Hex(DAT(i * 2 + 1)) & Hex(DAT(i * 2))
  curY1 = Val(d) / 32768 * exten
  WavBox.Line (lastX, exten + curY2)-(i, exten + curY1)
  curY2 = curY1: lastX = i
Next
End Sub

Private Sub DrawWaves16_2(WavBox As PictureBox)
Dim i As Long, j As Long, dL As String, dR As String
Dim exten As Long    '最大波幅
Dim lastX As Long    '水平坐标
Dim curLY1 As Long   '左声道垂直坐标
Dim curLY2 As Long   '左声道垂直坐标
Dim curRY1 As Long   '右声道垂直坐标
Dim curRY2 As Long   '右声道垂直坐标
Dim LYOffset As Long '左声道垂直偏移量
Dim RYOffset As Long '右声道垂直偏移量

WavBox.ScaleWidth = UBound(DAT) / 4 '窗体宽度=立体声样本个数/4
exten = WavBox.ScaleHeight / 4      '最大波幅为窗体高度的四分之一
LYOffset = exten
RYOffset = exten * 3
WavBox.Cls

For i = 0 To WavBox.ScaleWidth
  j = i * 4
  dL = "&H" & Hex(DAT(j + 1)) & Hex(DAT(j))
  dR = "&H" & Hex(DAT(j + 3)) & Hex(DAT(j + 2))
  curLY1 = Val(dL) / 32768 * exten
  curRY1 = Val(dR) / 32768 * exten
  WavBox.Line (lastX, LYOffset + curLY2)-(i, LYOffset + curLY1) '画左声道波形
  WavBox.Line (lastX, RYOffset + curRY2)-(i, RYOffset + curRY1) '画右声道波形
  curLY2 = curLY1: curRY2 = curRY1: lastX = i
Next
End Sub
搜索更多相关主题的帖子: 条码 样本 
2014-12-22 20:37
快速回复:这是个wav文件波形示例,但显示总有些不正常,多了一些条码样的线条,谁能 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017497 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved