Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sound help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nored




PostPosted: 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.

Turing:

var key : array char of boolean
var x:int:=0

process music
    Music.PlayFile ("zap5.wav")
end music

loop
    Input.KeyDown (key)
    drawfilloval (x, 50, 5, 5, black)
    x+=1
    if key (' ') then
        fork music
    end if
    delay (50)
end loop



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.
Sponsor
Sponsor
Sponsor
sponsor
Euphoracle




PostPosted: 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.
Nored




PostPosted: 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?
Euphoracle




PostPosted: 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.
Nored




PostPosted: 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?
revangrey




PostPosted: Sun Jan 18, 2009 9:54 pm   Post subject: Re: Sound help

Turing:
process backmusic
loop
    Music.PlayFile ("jingle-bells.mp3")
end loop
end backmusic
fork backmusic


dunno if that helps...probably not much
Nored




PostPosted: Sun Jan 18, 2009 10:44 pm   Post subject: Re: Sound help

revangrey @ Sun Jan 18, 2009 9:54 pm wrote:
Turing:
process backmusic
loop
    Music.PlayFile ("jingle-bells.mp3")
end loop
end backmusic
fork backmusic


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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: