Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Trouble with looping music.

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 18th Aug 2010 09:38
Hi all,

I've been trying different methods to make my music loop from threads that I've found but I still can't loop my music.

I'm using version 1.074, my file is a .wav which lasts around 3 minutes and I want a certain music to loop when I'm in the menu. I tried the following methods:







The first two plays the music once then never again. The third wrecks the game (which I'm not surprised).

But yeah, I can't get my song to loop.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Aug 2010 12:26
Try something like this...


You need one loop for your main program loop, and a separate loop for your main menu. You only need to use loop music once in that whole section, which is why it's not within the do/loop nest.

Just remember that sometimes, (I.E. most times) the standard DBP audio commands will introduce a slight delay in looping your audio. I'd highly recommend Torrey's enhanced audio plugin, which is free and will loop music perfectly.

My signature is NOT a moderator plaything! Stop changing it!
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 18th Aug 2010 12:53 Edited at: 18th Aug 2010 12:55
Or put this in your menu loop.

The problem with the music playing command is that if you do not actually stop the music from playing after the check, it ignores the next play music command. The level thing is just so I can change tunes per level easily, or you can add a random in to play random tracks. Just make sure the level=1 is out the main loop if you want to alter the sound value and add a new value in after stop music level.

http://s6.bitefight.org/c.php?uid=103081
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2010 12:57
I think you're right. There seems to be a problem with the play music command. The following snippet works fine for me - but only if I comment out the initial play music command. I've attached the music file I used.

The sound starts after about 2 seconds, then loops for about 2 seconds, then stops.

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 18th Aug 2010 13:30
You can also use the play sound command with no problems, just limits the type of music file you can use. The music issue has been in DB since forever lol. I worked out that stopping the music manually before replaying fixes it. Must be some flag that isn't reset when the music ends I guess.

http://s6.bitefight.org/c.php?uid=103081
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2010 13:48
Yes. It's about time it was fixed.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2010 13:58
Actually, there's still a problem with the sync command. See this Bug Report:

loop music doesn't work without sync

The following variation of my earlier snippet illustrates the problem:



The reason my earlier snippet worked was that the system was syncing behind the scenes - with sync on the program takes control and sync is needed. I think it ought to be classed as a bug. It's daft that sounds and music should be treated differently.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 18th Aug 2010 15:26
Just want to post a quick reply.

So far I tried Van B's method and DVader and both didn't work for me =/

I waited a while after the song ended in case it does take some time before it loops, but to no avail.

Could it be my version?

Oh and where may I get that enhanced plugin by Torrey's? Is it here in the website I assume?

I'm going to try using Green Gandalf's method soon.

Also could it be because my file is a .wav? Should it be a .midi?
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Aug 2010 15:35
I use LOOP SOUND instead of LOOP MUSIC, and it works fine. It even plays my .ogg files. I don't know if it supports .mp3 files, but I didn't try yet. I think LOOP MUSIC worked too, but if I remember correctly, it didn't loop seamless (always a silence when re-looping).

Cheers

Slayer rules!!! Yeaaah, man!
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 18th Aug 2010 16:18
Ok I'm an idiot. No wonder it didn't work the first time for me. The music file I got had nothing playing after the music ended for around 1 minute or so.

I.E. the actual music ended around 3 minutes but the music file kept going until around 4 minutes.

I used my initial code and it works now:



I placed that in a function outside the main do loop.

Ugh, sorry for wasting everyone's time =(

But while I'm here, do Sound and Music occupy the same "space"? Like, is Sound 1 and Music 1 taking up the same audio slot?
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 18th Aug 2010 17:59 Edited at: 18th Aug 2010 18:01
Nope. If your file is a .wav you can use loop sound anyway. Music files are really for .mid, .mp3 and .ogg.

http://s6.bitefight.org/c.php?uid=103081
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 18th Aug 2010 19:44
It's time to advertise myself

Here is something for DB_Newbie to play with (all others are invited )and you can open task manager to see what is happening when you load massive amount of sounds even if they are "deleted" by dbpro, they just don't free virtual memory!I think this is not happening just because of the way i write the sound snippet.So i think the best way of using sounds is to load them all once and use them until the user exit your game.You are gonna see why is pointless to use delete sound comand, just execute sound snippet and hit the mouse 100-200 times.

Anyway the music one works just fine, you are free to use it if you want.I use it for my sounds too, just convert them from wav or whatever to mp3's.

Here is the link :
http://forum.thegamecreators.com/?m=forum_view&t=170129&b=6

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 18th Aug 2010 21:47 Edited at: 18th Aug 2010 23:37
I always load up all my music in one go. Never worry about their memory use in game(not normally a lot). Hence the stop music command and not delete music above, and level so I can play from the the music selection. Will have a look at your link, but memory leaks are not new here
Edit - Surprised you said my code didn't work, it works fine here. Here is a full program to try using the suggestion. I include media and an exe also.

All you need to do to add more tunes is to add the extra to the variable soundnum, and put the names in the data array. If nothing else it's a nostalgia trip for some No points for guessing what sort of game I am working on presently!

http://s6.bitefight.org/c.php?uid=103081

Login to post a reply

Server time is: 2026-07-24 23:41:06
Your offset time is: 2026-07-24 23:41:06