Computer Science Canada Sound help |
Author: | Nored [ Sun Jan 18, 2009 12:45 pm ] | ||
Post subject: | Sound help | ||
I'm trying to incorporate music into my program. However, whenever I play the music file it slows down my program a LOT.
This is basically the code pertaining to the sound part of my program. When I run it in Turing, the oval will draw approximately every 50 milliseconds. However, when I hit the spacebar, it slows down. Basically what I'm trying to do is only play the sound when a certain key is pressed and to stop playing once released. If anyone could give me some advice, it would be greatly appreciated. Thanks. |
Author: | Euphoracle [ Sun Jan 18, 2009 1:40 pm ] |
Post subject: | RE:Sound help |
Consider using Time.DelaySinceLast. delay always causes a static delay to occur (it will always delay for 50ms). If your code takes longer than instantly to execute (which is likely) it will add that time to the delay, and it will appear as if it is slowing down. Time.DelaySinceLast only delays to a maximum of 50ms, taking into account when it was last called and the amount of time it has taken to reach the statement again. |
Author: | Nored [ Sun Jan 18, 2009 2:57 pm ] |
Post subject: | Re: Sound help |
Thanks for the quick reply, but I don't want to slow my program down-I want to keep the sound in sync with the rest of the program without delaying it (ie. to keep things running smoothly). It's for a game I'm making, and the sound is supposed to be linked to firing the laser-however, rather than just playing, it slows the program down. Time.DelaySinceLast would attempt to make everything uniform, but if the loop takes longer than 50 milliseconds to run then wouldn't it make no difference? |
Author: | Euphoracle [ Sun Jan 18, 2009 6:38 pm ] |
Post subject: | RE:Sound help |
If the sound is taking more than 50ms to load, there might be a problem with your sound device, or something is messing with the wav codec, which is highly unlikely. |
Author: | Nored [ Sun Jan 18, 2009 8:40 pm ] |
Post subject: | Re: Sound help |
Well, it runs the same regardless of what computer I use. I changed it to Music.PlayFileReturn and it's faster but it still lags a bit. Any suggestions? |
Author: | revangrey [ Sun Jan 18, 2009 9:54 pm ] | ||
Post subject: | Re: Sound help | ||
dunno if that helps...probably not much |
Author: | Nored [ Sun Jan 18, 2009 10:44 pm ] | ||
Post subject: | Re: Sound help | ||
revangrey @ Sun Jan 18, 2009 9:54 pm wrote:
dunno if that helps...probably not much I saw an example like this in the tutorial. It'd be great for background music, but it continues playing unless I put the fork inside my loop. I've also tried Music.PlayFileLoop on the if and using Music.PlayFileStop on every elsif and else, and that seems to yield the same results as Music.PlayFileReturn. Although both are significantly faster than Music.PlayFile, they still slow the program down a bit. I suppose it's not too noticeable, but having it run synced with my program would be better. |