Results 1 to 9 of 9

Thread: Graphical waveform representation?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Graphical waveform representation?

    I want to 'draw' a waveform from a file on a picturebox control.
    I don't know exactly how to approach the problem and I want to ask here some questions.

    In the first version of the program, I want to use only 8-bit, 1 channel audio files because they're the most easy ones.

    I know to draw a point in the picturebox control I must use picture1.pset and I know that raw audio data starts usually in the byte #45. After that I don't know anything else. So I would like to know what to do next.

    I'm reading some source codes also.

    EDIT: the file is a *.wav
    Last edited by Jose_VB; Jul 16th, 2015 at 02:50 PM.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Graphical waveform representation?

    Is this what you want
    Attached Images Attached Images  


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Graphical waveform representation?

    Quote Originally Posted by jmsrickland View Post
    Is this what you want
    Yes, that is what I want.

  4. #4
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Graphical waveform representation?


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Graphical waveform representation?

    Quote Originally Posted by VBClassicRocks View Post
    Thank you, I've read it.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Graphical waveform representation?

    I've been reading the link that VBClassicRocks posted and I've a more clear idea.
    In the code I'm writting, I use only 8bit-mono files because I think they're the easiest one.

    After reading the channels, bits per sample, etc... the program starts reading the sound information in the byte #45. So the first byte of 'sound information' is the byte #45.

    If the byte value is above 127 it corresponds to positive Y.
    If the byte value is below 127 it corresponds to negative Y.


    I use Picture1.Line to draw the values in the Picture1 control.
    I've stopped here because I don't know how to follow.

    I tried:
    Code:
    Dim MinView As Long      'Byte where the program starts to read
    Dim MaxView As Long     'Byte where the program ends to read
    
    Dim MyByte1 As Byte     'Actual byte the program reads
    Dim MyByte2 As Byte     'Following byte that the program uses to perform the caculations when drawing the line
    
    Dim ValueY1 As Long      'Value in the Y axis calculated from the value of the read byte
    Dim ValueY2 As Long
    
    Open CommonDialog.FileName For Binary Access Read As #1    'The program opens the file
          Dim I As Long
          For I = MinView To MaxView      
               Get #1, I, MyByte1
               Get #1, I + 1, MyByte2
               CalculateYValue MyByte1, MyByte2
               Picture1.Line (I, Picture1.ScaleHeight - ValueY1) - (I + 1, Picture1.ScaleHeight - ValueY2)
          Next I
    
    
    Private Sub CalculateYValue (FirstByte As Byte, SecondByte As Byte)          
    ' Calculate the position in the graph (Y axis) of the current byte read, depending the size of the picture1 control
         
         ValueY1 = (FirstByte * Picture1.ScaleHeight) / 255
         ValueY2 = (SecondByte * Picture1.ScaleHeight) / 255
    End Sub
    Is that ok?

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Graphical waveform representation?

    Not sure this is going to do you any good but it does display waveform however I noticed it takes a long time to load certain wave files. It's similar to the one VBClassicRocks posted except it plays the wave file and shows the waveform as it plays instead of displaying it all at one time
    Attached Files Attached Files


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Graphical waveform representation?

    @VBClassicRocks

    The exe works fine but the source code is all screwed up. I get Object variable or With block not set on below and there are many other places where that error occurs (too many to post)

    I realize you just posted a link to the source code at vbAc.. so maybe you have no knowledge of the code


    Code:
    Private Sub setScroll()
    Dim lMax As Long
    
       m_bSetting = True
    
       If (m_lZoom <= 1) Then
          m_lSampleStep = 1
          m_lPixelStep = Abs(m_lZoom)
          m_lSamplePerPixelStep = 1
          lMax = m_cWAVRead.AudioLength
      '
      '
      '
    Code:
    Private Sub setScroll()
    Dim lMax As Long
    
       m_bSetting = True
    
       If (m_lZoom <= 1) Then
          m_lSampleStep = 1
          m_lPixelStep = Abs(m_lZoom)
          m_lSamplePerPixelStep = 1
    '      lMax = m_cWAVRead.AudioLength
       Else
          m_lSamplePerPixelStep = m_lZoom
          m_lSampleStep = m_lSamplePerPixelStep \ 32
          If (m_lSampleStep < 1) Then
             m_lSampleStep = 1
          End If
          m_lPixelStep = 1
          Debug.Print m_lSamplePerPixelStep, (m_cWAVRead.AudioLength \ m_lSamplePerPixelStep), UserControl.ScaleWidth
          lMax = (m_cWAVRead.AudioLength \ m_lSamplePerPixelStep) - UserControl.ScaleWidth
       End If
    
       If lMax <= 0 Then
          m_cScroll.Value(efsHorizontal) = 0
          m_cScroll.Visible(efsHorizontal) = False
       Else
          m_cScroll.SmallChange(efsHorizontal) = UserControl.ScaleWidth \ 32
          m_cScroll.LargeChange(efsHorizontal) = UserControl.ScaleWidth
          m_cScroll.Max(efsHorizontal) = lMax
          m_cScroll.Visible(efsHorizontal) = True
       End If
     
      '
      '


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Graphical waveform representation?

    Quote Originally Posted by jmsrickland View Post
    Not sure this is going to do you any good but it does display waveform however I noticed it takes a long time to load certain wave files. It's similar to the one VBClassicRocks posted except it plays the wave file and shows the waveform as it plays instead of displaying it all at one time
    Yes, I'm testing the code and it's very helpful. Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width