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.

AppGameKit Classic Chat / A good method to play sounds exactly

Author
Message
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 8th Oct 2017 18:29
Hello all together,
i will be happy if someone helps. What is a good method to play sounds exactly, in equal intervals. Values up to 0.1 seconds are ok for me. At this moment i work with timer() to control the intervals. Is timer() or getmilliseconds() the better way? Or is it equal?
To control the sounds, i use the following lines:

timea# = timer()
if mb1 = 1 and getspritecollision
flag = 1
timeb#=timer()
endif

if flag = 1 and soundplaying = 0 and timea#>timeb#+0.2
playsound (1,70)
soundplaying=1
endif
if flag = 1 and soundplaying = 1 and timea#>timeb#+0.4
playsound (2,70)
soundplaying=2
endif

And so on. Is this a good method or is there an easier or better way? Thank you for your help.
ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 8th Oct 2017 18:49 Edited at: 8th Oct 2017 19:00
Using Timer() is fine, they both should be equal. However, Timer() uses floating pointer numbers which will loose accuracy the longer the program is running. But it shouldn't be a problem under normal usage.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 9th Oct 2017 09:56
You can reset the timer at regular intervals to maintain accuracy.
Supertino
7
Years of Service
User Offline
Joined: 22nd Jun 2017
Location: Behind you!
Posted: 9th Oct 2017 10:07
Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 9th Oct 2017 16:35 Edited at: 9th Oct 2017 16:53
If all you want is to repeat the same sequence of sounds every n milliseconds, then by far the best solution is using some audio-software to create that pattern and save it as a single sound file. Then you'll trigger this sound file (and stop it) whenever you like. This is by far the best solution.

If you still want to try it "the hard and imperfect way" you could use

do
if timer*1000>"n"
"perform this operation"
reset timer
loop

This should do the operation close to every "n" milliseconds if I am not mistaken.
iMac Book Pro, MacOS 10.12.4, Xcode 9.0 (9A235);
iPhone 6, iOS 9.35; iPhone 5s, iOS 9.35; iPad (3rd gen), iOS 9.35;

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2015;
sprcoll
12
Years of Service
User Offline
Joined: 26th Aug 2012
Location:
Posted: 9th Oct 2017 18:36
Thank you for your answers. All post´s have give me some ideas to test. At the moment if i use intervalls with 0.2 it sounds good enough.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 9th Oct 2017 20:56
Since you're only concerned about tenths of seconds(.1), and not milliseconds(.001) I wouldn't think you would have a problem.

Are you noticing something wrong?




Login to post a reply

Server time is: 2024-09-30 09:24:20
Your offset time is: 2024-09-30 09:24:20