Loadsound sync?
Blitz3D Forums/Blitz3D Programming/Loadsound sync?
| ||
Hi all, I've got a little issue I'd like to share, I have a demo that's time synced to a soundtrack. The problem is that the first time you run the program it seems to have a 1 second delay in playing the soundfile - so everything is off (timewise). Running the demo again it seems the sound file is cached or something because it functions as expected. My question is, how do I know a soundfile is really loaded and ready to play? My code obviously doesn't work: s=LoadSound("intro.wav") done=False Repeat If s<>0 Then done=True Until done=True PlaySound S Can anyone help? -R |
| ||
Program execution will halt at LoadSound until the sound is fully loaded. |
| ||
GFK, thanks for the reply - The problem must be with playsound then, because at times running the demo the audio is delayed 1 second, other times the audio is on que. I use millisecs() for my timing. ie. I have an event that occurs at 1.5 secs, another at say 5 secs and another at 9.5 secs. When the audio is late it looks terrible, everything happens early. I do a playsound and jump directly into the main loop. gamefps=30 framePeriod = 1000 / gameFPS frameTime = MilliSecs () - framePeriod Repeat Repeat Delay 1 frameElapsed = MilliSecs () - frameTime Until frameElapsed >0 frameTime = frameTime + framePeriod etc. etc. could it be that this frame limiting code is sometimes early? I really appreciate anyones help - I have no idea? -R |
| ||
Try compiling an EXE and run that, see if you get the same problem. In Blitz3D I often get a "stutter" in program speed about 2-3s after I run a program, I don't know if Blitz is doing some internal memory housekeeping or what, but I don't get that problem with EXEs. Could be related....? |
| ||
You could try pausing the channel (s, in your code above) immediately after loading it. Then delay for a second or two before unpausing the channel and starting your loop. This might give the computer enough time to finish up whatever's slowing it down. |
| ||
Gfk - same problem with EXEs :( Wolron - I'll try this, I did try putting a few second delay after it loaded, and the called playsound. I'll try your suggestion. Thank you both! -R |