GLBasic forum

Main forum => GLBasic - en => Topic started by: Foo on 2009-Oct-12

Title: How do I loop sounds uninterruptible without using high fps?
Post by: Foo on 2009-Oct-12
Hello,

do anybody know, how to loop a sound file without the use of high fps?

This is my code:

Code (glbasic) Select

// --------------------------------- //
// 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


Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Hemlos on 2009-Oct-12
Something like this, perhaps?

Code (glbasic) Select
PLAYMUSIC "Music.mp3", TRUE
PRINT "Music!", 100, 100
SHOWSCREEN
MOUSEWAIT
STOPMUSIC // GLBasic does this automatically when ending
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Foo on 2009-Oct-12
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.
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Hemlos on 2009-Oct-12
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.

Code (glbasic) Select
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:

Code (glbasic) Select
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.
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: MikeHart on 2009-Oct-12
Hemlos, what he ment was/is playing several sounds at the same time. And there looping isn't supported. It was requested before already.
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Kitty Hello on 2009-Oct-12
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.
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Foo on 2009-Oct-13
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?
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Kitty Hello on 2009-Oct-13
It's all solved. http://www.glbasic.com/forum/index.php?topic=3642.0 (http://www.glbasic.com/forum/index.php?topic=3642.0)
Title: Re: How do I loop sounds uninterruptible without using high fps?
Post by: Foo on 2009-Oct-13
Very cool :) Thanks mate - I'll give a try...