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 / random sounds

Author
Message
Chief Armstrong
21
Years of Service
User Offline
Joined: 28th Oct 2002
Location:
Posted: 28th Oct 2002 23:21
how do you do random sounds? say i had 5 sounds in my file and i just wanted to randomly play any of the 5 sounds when the prog was run? thanx in advance.
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 28th Oct 2002 23:50
Put this in your main loop. As soon as a sound has finished playing, a random new one should start. Put 'randomize timer()' in at the beginning somewhere to make it actually random.



You can butcher this to get a sound to play when the mouse is clicked, etc.
Chief Armstrong
21
Years of Service
User Offline
Joined: 28th Oct 2002
Location:
Posted: 28th Oct 2002 23:57
thanx, i'll give it a try. i'm trying to make a screensaver and i want a different tune to play each time it's run.

The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 29th Oct 2002 00:27
Then you'll want to put a single



command before your main loop but after you've loaded the sounds.

Actually, a better way would be to only load one sound at the start.



This saves unnecessary file loading, but will only play one of the five sounds as long as the screensaver is running.
Chief Armstrong
21
Years of Service
User Offline
Joined: 28th Oct 2002
Location:
Posted: 29th Oct 2002 00:36
after a sound stops, will it automatically select the next random sound or do i need to have code for that

Chief Armstrong
21
Years of Service
User Offline
Joined: 28th Oct 2002
Location:
Posted: 29th Oct 2002 00:53
nevermind, got what you were saying. my brain wasn't in gear.

TheNVS
21
Years of Service
User Offline
Joined: 25th Oct 2002
Location: United States
Posted: 30th Oct 2002 01:32
hey, i think i could help. since you want a different sound to run each time the program has been runned, you could save some data to a file when the sound has been played and not play it the next time. here is a little preview on what it might look like(this is just a draft). i hope you understand what i am trying to say. this seems a little challenge for me so i would like to try to figrue it out. i am working on how to play one sound after the previous one has finished. btw, if you like the code, you could use, it is not under copyright .



TheNVS
21
Years of Service
User Offline
Joined: 25th Oct 2002
Location: United States
Posted: 30th Oct 2002 01:40
oh yeah, i forgot to tell you to put

after you have run the program. also for the last part of script, <if upkey=1>, replace that with <if upkey()=1>. so that you could save an array.

Login to post a reply

Server time is: 2024-03-29 08:48:59
Your offset time is: 2024-03-29 08:48:59