Music and loop mode

Post your coding questions such as 'how to' here.
Post Reply
Buckethead
Newcomer
Posts: 16
Joined: Thu Sep 20, 2007 9:53 am

Music and loop mode

Post 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
Harakka
Advanced Member
Posts: 430
Joined: Mon Aug 27, 2007 9:08 pm
Location: Salo
Contact:

Re: Music and loop mode

Post 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
Peli piirtokomennoilla - voittaja, Virtuaalilemmikkipeli - voittaja,
Sukellusvenepeli - voittaja, Paras tileset - voittaja
Vaihtuva päähenkilö - voittaja, Autopeli - voittaja sekä
Hiirellä ohjattava peli - voittaja B)
Buckethead
Newcomer
Posts: 16
Joined: Thu Sep 20, 2007 9:53 am

Re: Music and loop mode

Post 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 
Valtzu
Active Member
Posts: 115
Joined: Sun Aug 26, 2007 2:40 pm
Location: Sauvo
Contact:

Re: Music and loop mode

Post 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.
Buckethead
Newcomer
Posts: 16
Joined: Thu Sep 20, 2007 9:53 am

Re: Music and loop mode

Post by Buckethead »

Great! 8-)
Post Reply