Results 1 to 10 of 10

Thread: A very tricky problem for me to figure out

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    A very tricky problem for me to figure out

    I am piss-poor at math which makes certain things difficult for me to figure out.

    Here's what I am up against.

    I am trying to move a vertical bar horizontally across a picturebox at a precise as possible amount of time.

    In this picturebox is a display of a sine wave from a sound file (a .wav). The duration of time varies from one sound file to another. I need this bar to start moving left to right at a given pace so that it will reach the right edge of the picturebox as close as possible when the sound stops. I can calculate the duration of the sound from the sound file header records but I cannot get the correct amount of speed to move the vertical bar so it will be at the right edge of the picturebox when the sound stops.

    I have this code line that works somewhat but really starts to get out of sync as the sound plays on.....many times it way too slow and other times it's way too fast.

    Speed of vertical bar = (picturebox width /10) / (sound data size in bytes \ average number of bytes per second)

    In the sound file header record is a field that gives me the total number of bytes there are in the actual sound data and another field that gives me the average number of bytes per second that are sent to the player device. I believe that (sound data size in bytes \ average number of bytes per second) gives me the duration in seconds of the sound.

    Some of the problems I have is I do not know what scale mode I should use for the picturebox, what timing interval I need to use for the timer control, whether I should divide picturebox width by 10 or 100 or what. I'm not even sure if the equation I posted is the best way to go or not.


    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
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: A very tricky problem for me to figure out

    Off the top of my head I would think you would use and interval of about 100 ms for your timer then you just need to determine the length in seconds of the audio stream and the size of the picture box in use.

    EachStep=Picturebox.width / (LengthInSeconds*10)

    I would probably just use the default Twips for the scale mode though Pixel should work ok as well.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: A very tricky problem for me to figure out

    DM

    Just about the same as the method I was using. Using the test wave file the movement was way too fast; the bar reached the right edge but the sound continued on for a least three more movements of the bar which means the bar actually went beyond the right edge.

    Maybe the problem is in getting the correct duration. Maybe using sound data size in bytes \ average number of bytes per second is not the correct way to get the duration but it looks like it is.


    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
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: A very tricky problem for me to figure out

    Keep in mind that the width property of the picture box is the outside measurement. What are you using for the display bar? That is probably what you should use. You may also want to try the scalewidth property of the picture box or perhaps subtract from the width to account for the boarders of the picture box, I forget off the top of my head but seems like the borders are 30 twips each or is it 60 twips?
    You could try something like
    Code:
    EachStep=(Picturebox.width-120) / (LengthInSeconds*10)
    and see how it goes then adjust that number as needed.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: A very tricky problem for me to figure out

    Something doesn't make sense.

    The picturebox has a scalemode of pixels. It's width and scalewidth are the same which is 122 according to the property box but the code returns 308529 as it's widths??????????????????
    The Form is also pixels

    Dim L as Long
    L = Picture1.Width

    L = 308529


    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

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: A very tricky problem for me to figure out

    I know it can be done with better precision as I have several wave players and they all show a progress bar as the sound plays and they all stop at the right edge when the sound stops.

    I also know the formula is corrct. I timed the sound to 38 seconds and when I get the results of sound data size in bytes \ average number of bytes per second I also get 38.


    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.

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: A very tricky problem for me to figure out

    Personally I would use twips but if you are wanting to deal with pixels then I think you will need to use scalewidth

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: A very tricky problem for me to figure out

    You could try using mcisendstring commands to get the length and position of the playing file. Attached is a sample that I stripped out of something I did a while back.
    Attached Files Attached Files

  9. #9
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: A very tricky problem for me to figure out

    That's about what I was thinking going with MCISendString API for better control. with the PlaySound you have to estimate and use timers. MarkT since you made a nice little project, do you know how to stream audio with MCISendString? Do you know how to read file to array and then maybe read (play) audio file from array, or memory?

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: A very tricky problem for me to figure out

    @MarkT

    Perfect. Exactly what I have been struggling to get. Thank you so much!

    Can the API play sound from memory (like a byte array)

    BTW: Can you record with this API
    Last edited by jmsrickland; May 17th, 2013 at 10:55 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.

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