Results 1 to 10 of 10

Thread: Calculating progress speed using byte count of data

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Calculating progress speed using byte count of data

    I hope I can explain this well enough but here is my problem.

    I am using two pictureboxes to show the progress of a sound as it is being played. Picture2 is the background that holds an image in it. It does not move. Picture1 is sitting on top of Picture2 (not in Picture2 like a Child) and it is to move from left to right until it's left border has moved all the way to the right border of Picture2 thus exposing the image underneath it.

    I know how many bytes of data are in the sound file and as the sound is being played I can capture the number of bytes that have been played using a Timer event.

    I need to take the number of bytes already played and using that calculate how much movement should be applied to Picture1 so it moves right a certain amount of distance and it will have moved all the way to the right when the return value of bytes played is equal to the number of bytes in the sound file.


    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.

  2. #2
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Calculating progress speed using byte count of data

    I am assuming the following:
    Picture1.Left = Picture2.Left when the song begins
    lngBytesPlayed is total number of bytes you have "captured"
    lngTotalBytes is the total size of the sound file

    Code:
       Picture1.Left = Picture2.Left + ((lngBytesPlayed * Picture2.Width) / lngTotalBytes)
    Please note, however, there may not be a one for one correlation consumption of bytes of the sound file and the actual pace of music. In other words, the first 10 seconds of a song file may take up more or less memory than the middle 10 seconds, which would cause the background image to be revealed at an uneven pace. A better method would be to use calculate and use time elapsed and total song length instead of lngBytesPlayed and lngTotalBytes, respectively.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Calculating progress speed using byte count of data

    Yes, I agree with you about using time elapsed and total length to get an even pace but maybe it doesn't really matter. I would think that the return bytes used varies and this would influence how much Picture1 moves either a very small amount or a bigger anount of distance. Let's say the first 10 seconds takes up half the total size in bytes and the next 30 seconds take up the last half of the total size. This would result in Picture1 moving faster in the first 10 seconds then it slows down in the next 30 seconds. Yes, it's an uneven pace as you state but maybe that wont matter as long as Picture1 reaches the end at the same time the song ends.

    However I would have preferred to use the time elapsed instead so as to get an even pace. I can capture the time elapsed in millisecond however I do not know how to get the total time duration of the sound file prior to playing the sound. I am using waveIn and waveOut and I have not been able to find a MM method or API the get the total length in time of the sound file without having to play it first. I get the total number of bytes because that is the size of the sound file minus the header size.
    Last edited by jmsrickland; May 23rd, 2013 at 02:32 PM.


    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.

  4. #4

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Calculating progress speed using byte count of data

    I already know total bytes without playing it. You didn't read my post correctly. It's the total length in time I can't get without playing it first.


    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.

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Calculating progress speed using byte count of data

    Well, what you can do is use this sample to get file extended info and then calculate how long it's going to play using code below (it's extended sample from that link):
    Code:
    Private Sub Command1_Click()
    Dim rInfo As WAVInfo
    Dim targetWav As String
    Dim totalBytes As Long
    Dim wavLength As Long
    
        targetWav = "C:\Temp\REMINDER.WAV"
        
        totalBytes = FileLen(targetWav)
        
        If GetWaveInfo(targetWav, rInfo) Then
            Debug.Print rInfo.AverageBytesPerSecond
            wavLength = totalBytes / rInfo.AverageBytesPerSecond
            Debug.Print "File playtime in seconds: " & wavLength
        End If
    
    End Sub

  7. #7

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Calculating progress speed using byte count of data

    Quote Originally Posted by RhinoBull View Post
    Well, what you can do is use this sample to get file extended info and then calculate how long it's going to play using code below (it's extended sample from that link):
    Code:
    Private Sub Command1_Click()
    Dim rInfo As WAVInfo
    Dim targetWav As String
    Dim totalBytes As Long
    Dim wavLength As Long
    
        targetWav = "C:\Temp\REMINDER.WAV"
        
        totalBytes = FileLen(targetWav)
        
        If GetWaveInfo(targetWav, rInfo) Then
            Debug.Print rInfo.AverageBytesPerSecond
            wavLength = totalBytes / rInfo.AverageBytesPerSecond
            Debug.Print "File playtime in seconds: " & wavLength
        End If
    
    End Sub
    Absolutely!. That's exactly what I have been looking for. Thanks RB, very appreciative.


    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
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Calculating progress speed using byte count of data

    Quote Originally Posted by RhinoBull View Post
    Also, if interested read this article.
    Look really neat but as usual when I download from VBA there's always something not quit right. When I go to run it I get error:

    Code in vbalWaveRender.cls

    Object variable or With block variable not set

    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
      '
      '
      '


    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.

  10. #10

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