Is this how loopsound should work?

Blitz3D Forums/Blitz3D Programming/Is this how loopsound should work?

Matty(Posted 2005) [#1]
I've noticed this for a long time but it hasn't been too much of a problem before, and I didn't test it fully to see how it works before now.

soundhandle=loadsound("some sound.wav")
loopsound soundhandle
soundchn=playsound(soundhandle)
delay 10000 ;simply to allow it to play for a while and loop
stopchannel soundchn
freesound soundhandle

soundhandle=loadsound("some sound.wav")
loopsound soundhandle
soundchn=playsound(soundhandle)
waitkey
end



On my machine if I do this the looped sound, despite being freed earlier will continue from where it left off. Quite annoying when you want to load a new level and have the music start from the beginning again. Is this the way it is meant to work and therefore should I use the playmusic() command - which also seems to play some songs continually and others just once!


Topknot(Posted 2005) [#2]
Hey Matty,

not sure if this helps but here's how you could have either Looping Music sound files play when you want or not, nothing major big, just loading the two sound files, pausing them at the start, then when you hit a key it resumes the play looping of the sound, but as you'll see it resumes right where it left off, and not starting over:



But what I would recommend for more control is this little piece of code that allows you more control over playing sounds either by themself or mixed together. You could have music playing in the background while other sounds like Menu Clicks and such could be heard.



To use the Functions load in your sound files ahead of time:
Global Sound1 = LoadSound("soundfile1.wav")
Global Sound2 = LoadSound("soundfile2.wav")


To Play a sound and/or loop:
PlaySample (Sound1,-1)

PlaySample (Sound2,1)


-1 Means only play the once once until asked to play again or Simultaneous Off
1 Mean Play the sound as many times as asked for, like if your shooting a gun over and over and the sound overlay eachother.

Well not sure if this helps and but my 3 cents worth.

Topknot ;)


Matty(Posted 2005) [#3]
Thanks Topknot but what I am asking is really whether the way loopsound works is the way the command is meant to work.

If I load a level, load a sound, set it up as a looped sound, I can play it fine. Then when I finish the level I use freesound to free the sound which was loaded. All good so far. Then on the next level if I decide to load the sound again as soon as I start playing it, it begins to play from where it finished at the point at which the previous level ended.

Given I have freed the sound resource from memory, why if I load it again into memory does it play from where it left off instead of from the start.

I realise I could just use a simple 'playsound' without using the 'loopsound' command and simply detect if the channel is playing or not and then replay the sound again but I just want to find out why loopsound 'remembers' where a piece of music was upto despite the sound being freed from memory and then loaded again.


Topknot(Posted 2005) [#4]
Well leave it to me to go to the Moon and Back with an answer lol, but changed the original tester code and I can't get the problem you mentioned, even with freeing the sound recource.



Hitting 1 shuts it down, and 2 reloads and loops and it plays from the beginning instead of in the middle or such.

So maybe I'm still missing your Loopsound issues completely, but in trying to emulate it I can't see how.

Topknot ;)


Matty(Posted 2005) [#5]
I must apologise very much. I must have been hearing things. There is no problem with the loopsound command. My mistake.

Ignore my previous posts.

Sorry about that.