Hello,
do anybody know, how to loop a sound file without the use of high fps?
This is my code:
// --------------------------------- //
// Project: sound test
// Start: Sunday, October 11, 2009
// IDE Version: 7.115
// SETCURRENTDIR("Media") // seperate media and binaries?
LIMITFPS 60
LOCAL water AS TSound
water.file$ = "./water.wav"
TSound_LoadSound(water)
loop = 0
WHILE TRUE
// Problem is here I think, a higher FPS causes a higher check rate
IF TSound_IsPlaying(water) = FALSE
INC loop, 1
TSound_Play(water, 0, 2)
ENDIF
PRINT "Time: " + GETTIMERALL(), 10, 0
PRINT "Playing: " + water.file$ + " Loop: " + loop, 10, 10
SHOWSCREEN
WEND
TYPE TSound
id
file$ = ""
channel%
ENDTYPE
FUNCTION TSound_LoadSound: s AS TSound
s.id = GENSOUND()
LOADSOUND s.file$, s.id, 1
ENDFUNCTION
FUNCTION TSound_Play: s AS TSound, pan#, volume#
s.channel = PLAYSOUND(s.id, pan#, volume#)
ENDFUNCTION
FUNCTION TSound_IsPlaying: s AS TSound
RETURN SOUNDPLAYING(s.channel)
ENDFUNCTION
Something like this, perhaps?
PLAYMUSIC "Music.mp3", TRUE
PRINT "Music!", 100, 100
SHOWSCREEN
MOUSEWAIT
STOPMUSIC // GLBasic does this automatically when ending
Thanks, but playmusic isn't the right thing for me. I can only play one file once. But I would like to play more sound files in a loop.
Im getting this directly out of the help files.
If this isnt working the way it is recorded in help file,
then theres a bug and we should report it.
PLAYMUSIC
PLAYMUSIC file$, bLoop%
The parameter bLoop% indicates, whether the music should be looped (TRUE) or not (FALSE).
When you need to change the sound, just do this:
LOCAL SoundFileName2$="Sound2.mp3"
LOCAL ContinuousLoop=TRUE
STOPMUSIC
PLAYMUSIC SoundFileName2$, ContinuousLoop
Hope that help you.
And hey one other thing youll find very handy..
There is alot of sample files loaded into glbasic directory.
Those files are invaluable, i have been using GLBasic almost ten years now (the name has changed actually), and believe it or not, i still use those help files for reference.
Hemlos, what he ment was/is playing several sounds at the same time. And there looping isn't supported. It was requested before already.
I see if I can make that x-platform. Another option would be to start a new thread for each sound and do the loop within the thread's main loop.
Threads would be okay - afaik. I'm using threads in my JAVA applications.
How do threads work in GLBasic?
Are there no problems on any plattforms with that?
Is there a way to syncronize objects/type instances?
What about deadlocks?
It's all solved. http://www.glbasic.com/forum/index.php?topic=3642.0 (http://www.glbasic.com/forum/index.php?topic=3642.0)
Very cool :) Thanks mate - I'll give a try...