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.

Code Snippets / [DBP] Play Multiple Sound / Music

Author
Message
luskos
16
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 15th May 2010 02:30 Edited at: 20th May 2010 02:40
This is how i do it, it may be very useful for someone.I find it very usefull.I think that this can be writen even better, but it suits me, and i think in 99.0% of time there will be safe to use as is, without producing errors or making troubles.I`m not sure if there is snippet with something like this, so enjoy if there isn`t.

Used plugins : Matrix1 Plugin

Music Snippet - Last test and changes in this snippet shows no problems with it.


Sound Snippet - Issue: Doesen`t free up Virtual Memmory!


Thanks myself for not being lazy!

EDIT: I made an update to the code.Past state of it didn`t unload the virtual memmory and sometimes there is music stuck in the array with state of playing but it does not.So there is new function included force_free, it check the sound counter.Perhaps nobody need 20+musics/sounds at the same time so it means there is need of clear on stucked sounds/musics.Unfortunately it`ll stop all sounds playing at this time.I`ll update when figure out how to prevent this.

Also i remove "backdrop on" command and added cls instead, i write it by habit, it realesed arround 150-180k virtual memory.

EDIT2: I made sound version of the snippet.It`s a bit diferent, there is no sound stuck in the array anymore.There is just virtual memory issue, it doesen`t free when new file is deleted.I`ll work on this.It maybe caused by find free comand

EDIT3: Update of music version, it`s exact copy of sound one, using UDT array and so on,but it doesn`t have the virtual memory issue in it.Force free function is removed.Test shows that is 100% bug free, for now...

EDIT4: I forget to mention something.When you use the code above you need to call your sounds like this:

or like this, because eventualy you need volume option for your game:

and you need to call the function play_music like this:



Enjoy!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th May 2010 10:38
I'll use this in my next project and give credit if it stays in! Seems to work fine so far so I'm hoping the old stuck "music playing" issue has been resolved. Nice neat and simple code well tested by the sound of it.

luskos
16
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 17th May 2010 11:21 Edited at: 17th May 2010 11:28
I need to make an intensive test on it to find out.Last night i couldn`t do it because my girlfriend was sleeping and the insane mouseclicks could of wake her, now i can do it

I`ll be glad if you mention me somewhere in your game but it`s not neceserry.I`m curious to see it, and the code in action

EDIT: I just test it and it looks fine.I think ~150-200 clicks per minute should do the job, but not.I stick "bug free" certificate on it until someone show me how he bug it

Where there is a will, there is a way.
I often edit my posts, that`s who i am

Login to post a reply

Server time is: 2024-04-18 23:37:17
Your offset time is: 2024-04-18 23:37:17