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.
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.
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.
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
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.
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.
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.
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?
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.