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.

Newcomers DBPro Corner / play sound

Author
Message
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 14th May 2010 01:53
I`m almost at end of finishing my clone game and i begin to mess with the sounds, so there is few of them as "death sound", "reload sound" and etc, that need to be played a lot in the game and i realised that play sound comand play the sound once only.The loop sound comand play it forever.

I also need sometimes to play 1 sound twice at the same time.

What is the best way to do it?How you did it?

Where there is a will, there is a way.
I often edit my posts, that`s who i am
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 14th May 2010 08:20
not really sure what u mean , but sounds for wepons ect the sound will play each time u tell it to ,if u want to play it for some time for each condition (burst fire for example)you could use a timed play command ( ie make a countdown for as long as u want the sound to play and at intervals just longenough for the sound to play through , so say sound is 1 second long and u want 3 seconds of it to loop at a given point ,then make timer start at the game point and count for 3 seconds calling the sound once every second) maybe this is what u need?
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 14th May 2010 17:09
With "play sound" comand this is not exactly true, it plays 1 time only.When my condition is met in the game anything between if-endif statements is done, but not the sound part, it plays only 1 time.

If i use countdown timer then i can play the sound every time the timer expires, but i can`t play it again while is playing because the timer would not be expired yet.

If we say i kill enemy, there is sound to be played for enemy`s death.Then if i kill 2nd enemy before the 1st enemy`s sound is done playing, there`ll be no sound played for 2nd.

I could think about some workaround, but i need to know how others do it.There`s also maybe some plugin which can make my life easy.Who knows...

Where there is a will, there is a way.
I often edit my posts, that`s who i am
zootan
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 14th May 2010 18:31
what u want to happen should happen ok, i noticed when using timer sound if u say 'play sound if timer(100) is less than 20' the sound is repeated nonstop untill the timer reaches 0 . i didnt want this to happen,it sounds horrible so i needed just one time, u can do either way with timer depending when u call it. BTW i used "load 3dsound" comand if that makes any difrence to you, then position sound at firing enemy and play sound based on the same timer i used for the actual wepon fire. the one time loaded sound should work just fine whenever u use it, if not then something is wrong,check the sound files are working and loud enough ect could be something like that, i think sounds are quiet when played in db compaired to same file in media player . have a play with just sound files and sound commands in a test program , thats the best way to troubleshoot.
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 14th May 2010 21:55 Edited at: 14th May 2010 22:01
Hiya, just came by to peek in this forum.

I noticed the same thing with playsound. What you need is to be able to detect if a sound is currently playing. If it is , then clone that sound and then play the clone sound. That will allow it to not cut off the original sound.

I snipped this from my current program I'm working on.

I use this custom function, GetNewSoundID(), to find an available sound ID for the loaded sound:



Then when I want something like shooting laser gun sounds, I call this custom function that I created to make sure each sound is played on it's own sound channel:

(note: i used the variable sndchannel to act like different sound channels. It will actually hold a new sound ID for the cloned sound. Here I loop though from 1000-1032 for open cloned sound ID's. You can change this range to whatever you want. Just try to remember to not hard code sound ID's to loaded sounds so they won't conflict with the sound ID range the PlaySoundID uses. I don't like hard coding ID's and only use custom functions like GetNewSoundID to find ID's.)




I load sounds like this:

global_sound_laser1=GetNewSoundID()
Load Sound "myawsomelasersound.wav",global_sound_laser1

and then call the custom PlaySoundID function to play the sound repeatedly like for each time one hits the fire gun button for example:

PlaySoundID(global_sound_laser1)

Hope that helps...

ExoDev.Com |XBOX360 CONTROLLER LIBRARY|USE DARK GDK WITH LATEST DIRECTX| C2Q2.66, 8G RAM, GeFORCE 9800 X2, VISTA 64Bit
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 15th May 2010 01:18 Edited at: 15th May 2010 02:24
This is the code i needed, it`s not fully functional as i wanted but is an approach to the right direction.It can play music, then detect if the sounds is played to the end and stop it.

The problem was that i never stoped the sound from playing and dbpro just tried to do it from the point where the sound ends.

I think that because even there is no sound produced the play music comand shows that it`s playing when conditions are met.



@Todd Riggins

Thank you for sharing this Todd.I have to ask you when you load a lot of sounds is there any performance punches?You didn`t mentioned what happens when the sounds/musics are done playing?I doubt that dbpro realease them automaticly so there can be expected speed drops or not?

EDIT: I manage to do it myself, how stupid to ask for help when i knew the answer...

There is the code:



When statements for playing are met, begin search for free music id, i used matrix1`s plugin for this.Then there is a check made against an array for storing the music id, then again with matrix1 sort comand the array is sorted, then all sounds stored in the array are played.

Next step is to unload the music with delete_music function.It checks the id`s stored in our array then if the sound is playing or not.If not this means it`s have been played allready, because in the same time of making it we begin playing it, "music playing() = 0" means only that.Next we delete the sound to clear it from memory and then clear it`s place/id in the array.

This goes immediately to Code Snippets
Thanks to all and thanks to myself for not being lazy!

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 15th May 2010 05:46 Edited at: 15th May 2010 05:48
Quote: "I have to ask you when you load a lot of sounds is there any performance punches?"


I didn't see any big performance hits with playing up to 32 sounds at once ( of coarse, I may have a fast enough computer to not notice ).

Quote: "You didn`t mentioned what happens when the sounds/musics are done playing?I doubt that dbpro realease them automaticly so there can be expected speed drops or not?"


Yes, in my custom Function PlaySoundID as seen above, on each call, it loops through 1000 to 1032 sound id range. First, it checks to see if the sound at the sound ID number exists or not ( DBPro Command: Sound Exist() ). If it does exist, then it checks to see if that specific sound is playing or not ( DBPro Command: Sound Playing() ).

If the sound is still playing, then skip and check the next sound ID to see if it exists and playing.

If the sound doesn't exist at a specific sound ID, then clone it ( DBPro Command: Clone Sound() ) and play the clone sound with that sound ID.

If the sound exists and is NOT playing, then delete the sound ( DBPro Command: Delete Sound() )at this sound ID( Your right, DBPro will not release them automatically until your DBPro program is closed. So this function does it manually to manage the amount of existing sounds being used ). After deleting the sound at this point, clone the original sound and play it.

---------

Looks like you found your solution though, good job

ExoDev.Com |XBOX360 CONTROLLER LIBRARY|USE DARK GDK WITH LATEST DIRECTX| C2Q2.66, 8G RAM, GeFORCE 9800 X2, VISTA 64Bit
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 15th May 2010 13:03
Yeah i`m pretty amazed from myself lately

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Spectre 117
14
Years of Service
User Offline
Joined: 18th Apr 2010
Location: *Insert cheesy location here*
Posted: 16th May 2010 04:55 Edited at: 16th May 2010 05:15
Ok so I don't mean to hijack someone else thread, but it looks like luskos got the answer he needed. I am also having some problems with playing sound, so I figured there was no point in starting a new thread.
I want to play my laser sound wav for as long as my laser is being displayed. Unfortunately, all my program is doing right now is restarting the sound every loop if the space key is held down. What I want to happen is for the sound(and laser graphic in theroy) to start once the space key is pressed and then not restart until the 2.49 seconds has passed. I will post my code for everyone to look at. Any advice would be greatly appreciated.


also any advice on making my plain grow to reach a specific length would also be helpful.
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 16th May 2010 22:31
Try this:

Spectre 117
14
Years of Service
User Offline
Joined: 18th Apr 2010
Location: *Insert cheesy location here*
Posted: 17th May 2010 01:50
Deego,
Umm... I am kinda new to basic so I don't understand all the key words and commands. So could you kinda explain what this command does or is suppose to do, because really doing what I want.
Spectre 117
14
Years of Service
User Offline
Joined: 18th Apr 2010
Location: *Insert cheesy location here*
Posted: 17th May 2010 02:19 Edited at: 17th May 2010 04:55
Ok I have a question thats not exactly about playing but might help me get the effect that I am looking for. Is there some kind of skip command DBpro. What I am thinking is something along the lines of making a variable for my laser routine. Then checking that variable in my loop. If the variable=1 then skip command, If variable=0 then the command can be run when the spacekey is pressed again. If anyone can help me out I wouldd really appreciate it.

edit: never mind I figured it out
harmyboy
16
Years of Service
User Offline
Joined: 20th Jul 2008
Location:
Posted: 17th May 2010 21:24
cant you just do

?
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 17th May 2010 22:41
About Deego`s line it means if sound playing(1)=0 then play sound 1

If sound playing state of specified sound is 0 it means it`s not playing and then play it.At the end of playing the sound if this line is in a loop it`ll play the sound again.Tomorow i can answer to your last post because i`m very tired and can`t think much else i would scratch some sample snippet.In theory there is no such command, but actually this is the meaning of coding so you can pick certain comands put them in order, make a condition and watch what happens.

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-11-27 09:25:50
Your offset time is: 2024-11-27 09:25:50