Sound repeats 30 times a second

Blitz3D Forums/Blitz3D Beginners Area/Sound repeats 30 times a second

JT(Posted 2008) [#1]
I'm just trying to create a program that plays certain sounds at certain times. For example I might want a "start" sound and then 2 minutes later a "stop" sound. But the sound repeats many times a second. How do I get it to just play once? I'm a complete newb BTW so don't get too technical. Thx


; Timer
;_______________

Graphics3D 640,480
SetBuffer BackBuffer()

; Create camera
cam=CreateCamera()
PositionEntity cam, 0,0,0


; Creating a light
light=CreateLight(3)

;Loading the sounds

rndtwo = LoadSound("rndtwo.wav")


;Create timer.
timer = MilliSecs()




; This following code makes our program run

While Not KeyDown( 1 )

;Just trying to make certain sounds play at certain times dictated by a timer
If MilliSecs() < timer + 1000 Then
PlaySound rndtwo
EndIf


UpdateWorld

RenderWorld


Flip

Wend

End


Ace Killjoy(Posted 2008) [#2]
I've had the same problem in the past.
The good people here told me to put this code in:
If Not ChannelPlaying(soundchn)
soundchn=PlaySound(sound)
End if


I your case, I think it would be more like:
;Just trying to make certain sounds play at certain times dictated by a timer
If MilliSecs() < timer + 1000 Then 
If Not ChannelPlaying(soundchn)
soundchn=PlaySound(rndtwo)
EndIf
EndIf


I think the reason your sound keeps repeating is because of this part:
If MilliSecs() < timer + 1000 Then

There's not anything wrong with that, it is just telling Blitz to play the sound as soon as MilliSecs() is less than timer+1000, which Blitz will play over and over as long as it remains true.


JT(Posted 2008) [#3]
That totally worked. Thank you so much!


Ace Killjoy(Posted 2008) [#4]
Just glad I could help.


blade007(Posted 2008) [#5]
by the way...
you need to update your timer
If MilliSecs() < timer + 1000 Then 
PlaySound(rndtwo)
timer = millisecs()
EndIf