Page 1 of 1

Music and loop mode

Posted: Sat Sep 22, 2007 1:06 pm
by Buckethead
After many tests I couldn't make a perfect loop on a sample, I've this "Memory Access Violation" error message.

music = PlaySound("sound.wav")
SetSound music,1,100,0

1 should repeat the sample, but it result in a crash.
SetSound
Manipulates a playing channel realtime. You can, for example, fade sounds in/out, or fake over-flying.
Usage:
SetSound channel, mode [, volume] [, pan] [, pitch]

channel can be retrieved from PlaySound()
mode works only for loaded sounds. 1 = repeat, 0 = play once
I've seen this on the finnish forum, but this solution doesn't make perfect loops. (Btw there was SetSound in the code)

Code: Select all

...
 If SoundPlaying(music)=OFF Then 
        music=PlaySound("frenchtouch-01.wav")
    EndIf
...
I've also tried LoadSound etc

Re: Music and loop mode

Posted: Sat Sep 22, 2007 1:19 pm
by Harakka
This should work:

Code: Select all

musicfile = LoadSound("music.mp3")
musicchannel = PlaySound musicfile

Repeat
  If Not SoundPlaying(musicchannel) then musicchannel = playsound musicfile
  DrawScreen
Forever

Re: Music and loop mode

Posted: Sat Sep 22, 2007 1:42 pm
by Buckethead
Thanks.

First I got a "code 42" with PlaySound. I'd to modify it a bit.
It load the sample in memory so it's faster, it's not perfect but inside a routine that is not huge it's ok. (16 ms you can't hear, ~60 FPS)

Code: Select all

...

musicfile = LoadSound("sound.wav")
musicchannel = PlaySound(musicfile)

...

Repeat

...

If Not SoundPlaying(musicchannel) Then musicchannel = PlaySound(musicfile)
DrawScreen 1 , 1

Forever 

Re: Music and loop mode

Posted: Sat Sep 22, 2007 8:32 pm
by Valtzu
Hi!
CoolBasic's sound system is maybe little complicated, but you should do that like this:

Code: Select all

snd = LoadSound("Media\blaster.wav")
SetSound snd, 1

snd_play = PlaySound(snd)

// Do something
Now the sound should be looped forever.

Re: Music and loop mode

Posted: Sun Sep 23, 2007 11:51 am
by Buckethead
Great! 8-)