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 Discussion / Loop Music Command makes game freeze

Author
Message
Hop a long
21
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 14th Aug 2005 03:00
I'm trying to put some background music into my game. But each time the music loops the game hangs up for a moment then continues. Anybody know a way around this?
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 14th Aug 2005 05:24 Edited at: 14th Aug 2005 09:13
Hop a long,

Loop Sound might be a way around this. However, I am not sure how DBC handles the loading of large .wav files. However, I have used short beat loops with the sound loop command, and there were no pauses in between plays. Therefore, if your file is short, this may be what your looking for. Good luck.


+NanoBrain+
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 14th Aug 2005 09:04
To clarify, are you using an audio file or a midi file?


I'm going to eat you!
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Aug 2005 15:54
heres a good way to do it..




or, if you want it to go onto the next track




"Well if she dies it'll teach her not to do it again..." - Me
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Aug 2005 21:13 Edited at: 14th Aug 2005 21:14
The problem Hop a long is experiencing is one I have experienced too and to be honest, I haven't got a clue why it happens or how to stop it.

I'll be watching this thread to see if someone comes up with an answer that works.

Basically, if you load a wav or an MP3 and use Loop Music, at the end of the music, sometimes, DB itself can freeze for a moment while the music restarts.

Alternatively, there's a gap before the loop starts again - despite the fact the it's smooth and continuous when looped in say Sound
Forge.

The length of the sound file used doesn't appear to be a factor - it can happen with small as well as large files.

It's bugged me for a long time this one...

TDK_Man
Zotoaster
20
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Aug 2005 01:05
well check out what i did, it worked fine for me

start off before the loop:

sync on

load music "music.mp3",1
play music 1

do

if rnd(100)=1
if music playing(1)=0 then play music 1
endif

sync
loop

"Well if she dies it'll teach her not to do it again..." - Me
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Aug 2005 03:48 Edited at: 15th Aug 2005 03:50
I don't understand what the

if rnd(100)=1
Endif

is for - it's totally unrelated to the problem.

Or are you saying, "that's the point - it may well be, but it fixes the problem"?

All it's doing is comparing a random number to 1 and if it matches checks to see if the music is playing and if not plays it. If anything, you would think that this would add to any gap before the loop starts again.

Actually, it's the Loop Music command I have problems with - not Play Music.

I've attached a short mp3 which I wrote which is meant to be looped continuously. In WinAmp, it sounds like it should - a continuous loop.

If you convert it to a wav file, it also does the same in Sound Forge.

However if you use:

Load Music "Options.mp3",1
Loop Music 1

in DB, there's a small gap at the end before it starts playing again which completely ruins the effect I was after!

Maybe it's my machine, so let me know if it does the same for you.

By the way, I tried your code (pasted below) and it played the music once and then stopped!



TDK_Man

Attachments

Login to view attachments
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 15th Aug 2005 04:09
Try using:


Hop a long
21
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 15th Aug 2005 06:40 Edited at: 15th Aug 2005 06:43
I got home late and didn't get to try any of the suggestions. Please don't think the problem is solved. If you have an idea, post it!

In answer to BearCDP : It's a midi.
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 15th Aug 2005 13:44
TDK :: Zotoaster was told to put that in there by somebody else, so that it didn't keep checking 10s of thousands of times a second.

However, with the sync it's irrelevant, and if I were him I'd use the Kernel32.dll Sleep API function, it's much better <.<

I used to find that the game would freeze for a second before playing again - I feel that DarkBASIC is either 'seeking' back to the beginning of the track, emptying the sound buffer and loading it back in again, or it's loading the whole track back in (less likely, though).

Please, could you post the lengths of the 'music's you are using, and your system specs, Hop a long and TDK? That should either prove or disprove my theory/hypothesis/random guess. Post yours if you don't experience the problem either.

(I don't experience the problem on my P4 3.2GHz + 1GB DDR RAM PC, although my laptop (P3 750MHz 128MB SDRAM) doesn't freeze but the music does 'pause' between loops.)

[Insert extremely witty comment here] :: Add me to MSN if you like, but don't expect any big favours [unless you like VB6]. ... IDK!!
Hop a long
21
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 16th Aug 2005 02:06
If it's a question of speed then I guess I won't get it to work. I thought it was an error in my coding. I just remembered and tried the Cave Runner Demo that came with DBC and it hung up too.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 16th Aug 2005 08:22
I haven't used the midi commands in a while, and I can't find the CaveRunner demo (which would also lag the music on my pc). But I recall using this would make it work:

play music 1
do
`yatta
if music playing(1)=0 then play music 1
loop


I'm going to eat you!
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 16th Aug 2005 09:54
@ P Schnell:

so you want to stop the music when the music is not playing?
Weird...

Immunity and Annihalation makes Immunihalation...
Hop a long
21
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 16th Aug 2005 23:55
Thank you BearCDP I'll give that a try.

The Caverun.dba file is at the end of Help\Fasttrack\Create your much better second program
Hop a long
21
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 18th Aug 2005 01:57
Ok BearCDP this worked for me:

Do

If Music Playing(1) = 0
Stop Music 1
Play Music 1
EndIf

Loop


Without the Stop Music, the music played once, the program ran slow and seemed like it was trying to make up it's mind about something.

Thanks to everybody who took time to offer a suggestion!

Login to post a reply

Server time is: 2025-05-22 14:10:23
Your offset time is: 2025-05-22 14:10:23