this is the wait function
Code:void wait ( int seconds ) { clock_t endwait; endwait = clock () + seconds * CLK_TCK ; while (clock() < endwait) {} }
this is the wait function
Code:void wait ( int seconds ) { clock_t endwait; endwait = clock () + seconds * CLK_TCK ; while (clock() < endwait) {} }
If you change it to the above. A question though, is CLK_TCK 1000?Code:void wait ( double seconds ) { clock_t endwait; endwait = clock () + seconds * CLK_TCK; while (clock() < endwait); }
now you can say - wait( 0.5 ), and it'll work ... hopefully
EDIT ::
Also, here's a REALLY simple timing class I made before - http://cboard.cprogramming.com/showp...4&postcount=10
To use it, do something like this
EDIT:: NP RaigneCode:TimeIt TimeForBeep; for ( limits ) { TimeForBeep.StartTimer(); // your beep stuff here TimeForBeep.EndTimer(); wait( 1 - TimeForBeep.GetTime() ); cout<< "Whatever"; TimeForBeep.Clear(); // Not really needed I suppose }
Last edited by twomers; 09-04-2006 at 11:04 AM.
If I understand correctly you need to make your program wait the exact length of each Beep so that it is relatively right, but if you want you could use multi-threading to doit as well, that is if you want to make somehting like a audio mixer or something, and thanks for fixing my mistake in my first post twomers ( geeze i cant type today)
Last edited by Raigne; 09-04-2006 at 11:04 AM.
i cant remember what the CLK_TCK is but i think it is 1000
says there is an error with
Code:endwait = clock () + seconds * CLK_TCK;
What's the error, peckitt99?Originally Posted by peckitt99
Also, look at my edit on my previous post.
it says
[warning] assignment
sorry bout all the questions im actually new to this n gotta learn it since im doing computing forensics in uni, lol
It's warning you cause the types are different. ints doubles and clock_t's
You have a few options, revert to an int, but instead of having seconds, use miliseconds, so 500 would be half a second ect.
Or cast the result. I think the above is a better option.Code:void wait ( int miliseconds ) { clock_t endwait; endwait = clock () + miliseconds while (clock() < endwait); }
ah right ok thanx,
ill give it all ago n see if i can get it to work.
thanks for all your help
for some reason it dont like wait(0.5). says there is a warning with the passing.
Are you using the milisecond version? If so, say - wait( 500 ); 0.5 is full seconds, remember.
With the portability thing though I am sure I saw that your code was using (or you were going to use) system ("CLS") making it un-portable so therefore it is a lot easier to use Sleep ();
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Windows Console Option. Still using windows, but after that, use option 5
yeah i have changed it to 500 but it still cant play both at the same time it is always waits for one to finish before doing something again.
Course it does! Those functions aren't asynchronous! Sorry, I thought I'd expressed as much in an earlier post. I don't know any asynch functions to play sound.
Did you mean CLOCKS_PER_SEC?Code:CLK_TCK
The time in seconds is the value returned by the clock function, divided by CLOCKS_PER_SEC. CLK_TCK is equivalent, but considered obsolete.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.