![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
milliseconds to minutes:seconds:ms |
Steve Terry
Member #1,989
March 2002
![]() |
I'm using fmod and there is a function FSOUND_Stream_GetTime(stream) which returns the number of milliseconds since the beginning of the track. The only problem is that it's not 60milliseconds to a second and so forth. Instead it's just a single number from 0 to infinity. How do I break this single number into minutes, seconds, and milliseconds in the 60:60:60 format. Sorry if this is a bit offtopic. ___________________________________ |
Derezo
Member #1,666
April 2001
![]() |
I thought it was 1000ms -> 1s? I'm not sure how to break down the ms to 60, exactly.. but, I usually break it down to 100 instead. Just divide by 10.
Ok, was simpler than I thought.. so I edited my post to include code "He who controls the stuffing controls the Universe" |
Steve Terry
Member #1,989
March 2002
![]() |
yeah the problem I'm getting it's coming out like 00:00:78 instead of 00:01:18, etc. ___________________________________ |
Matthew Leverton
Supreme Loser
January 1999
![]() |
How about this? int t = FSOUND_Stream_GetTime(stream); int minutes, seconds, ms; minutes = t / (60 * 1000); t -= minutes * (60 * 1000); seconds = t / 1000; ms = t - (seconds * 1000); printf("%02d:%02d:%d", minutes, seconds, ms); Untested, and not optimized, but something along those lines should work. Edit: If you want ms to be 0 to 59, just scale it. ms = ms * 60 / 1000; |
Korval
Member #1,538
September 2001
![]() |
Quote: The only problem is that it's not 60milliseconds to a second That's because there aren't 60 milliseconds to a second. Nor should there be. The prefix "milli" is used to denote 1/1000ths, not 1/60ths. To get seconds, divide the milliseconds by 1000. What Matthew wrote should get you what you need. If, for some odd reason, you really want 1/60ths of a second, you should be able to convert the code that computes the variable "ms" into something that gives you 1/60ths of a second. |
Rash
Member #2,374
May 2002
![]() |
Sometimes the term jiffy is used to denote 1/60th of a second. |
Steve Terry
Member #1,989
March 2002
![]() |
alrighty that worked.. what's wrong with the 00:00:00 format instead of 00:00:0000, personally I like it all 1/60. ___________________________________ |
Matthew Leverton
Supreme Loser
January 1999
![]() |
You are losing precision, but it really doesn't matter. Whatever looks best visually is what should be used. I personally would make the ms display as 00-99 (or not at all). |
Bruce Perry
Member #270
April 2000
|
The ms display won't be 0-99. If it's 0-99, they're centiseconds. Personally I've never seen seconds subdivided into 60; it's usually 100 or 1000. Sometimes it's 24. I'd recommend minutes:seconds.centiseconds or minutes:seconds.milliseconds (note the use of . not : int ms = (LONG_LONG)al_duh_get_position(dp)*1000>>16; /* :P */ int secs, mins/*, hours*/; secs = ms / 1000; ms %= 1000; mins = secs / 60; secs %= 60; /* hours = mins / 60; mins %= 60; */ /* By all means replace this with text_printf(). * %02d will print a trailing zero for <10. * %2d will print a trailing space for <10. * %d would not print a trailing space. */ printf("%2d:%02d.%03d", mins, secs, ms); /* printf("%2d:%02d:%02d.%03d", hours, mins, secs, ms); */ If you'd like to use centiseconds, replace 1000 with 100 and ms with cs everywhere, and change %03d to %02d. (Using FMOD's function, divide by 10, obviously.) -- |
Paul Pridham
Member #250
April 2000
![]() |
I use this for my game's countdown clock: hours=(countdown/(UPDATE_RATE*60*60))%24; mins=(countdown/(UPDATE_RATE*60))%60; secs=(countdown/(UPDATE_RATE))%60; msecs=countdown%UPDATE_RATE; This works in 1/100ths of a second (UPDATE_RATE=100, countdown is in 1/100ths), but just change UPDATE_RATE and countdown to whatever you need. ---- |
Steve Terry
Member #1,989
March 2002
![]() |
hey enthen does DUMB support FFT output, I heard you a long time ago talking about finding the algorithm and whatnot, but have you actually implimented it yet? Oh and I think I will take the mm:ss.ms where ms = 1/100s method.. it looks nicer. ___________________________________ |
Thomas Fjellstrom
Member #476
June 2000
![]() |
why 100? milliseconds are 1/1000th... my little wav player thats builting to an editor for a file called a pak file (kinda like a dat file, but has the nesesary api to add and write them, and adding more formats are a breeze.) I use 1/1000ths and it looks fine... -- |
Steve Terry
Member #1,989
March 2002
![]() |
hmm interesting replies.. I never thought that displaying a timer would be so complex.. maybe I should specify a config file for my media player that allows the user to set the time format. [edit] ___________________________________ |
Thomas Fjellstrom
Member #476
June 2000
![]() |
if anything allegro's pakkfile reading will be slower. Winamp takes just as long to read the id3 tags.. you just have to do it a bit at a time... say every MSG_IDLE do a couple files -- |
Steve Terry
Member #1,989
March 2002
![]() |
ahhh brilliant.. that should work.. though I can't really impliment that at the moment because of HW.. but brilliant non-theless I would of never thought of that.. it would update just like winamp does as well... possibly I could do it for only those in the view of the playlist. It's very doable as well, not much to change... ___________________________________ |
Thomas Fjellstrom
Member #476
June 2000
![]() |
w00t. Someone said I'm brilliant! hehe. It feels nice to feel needed... Now if only my game would get to a point people could play it... -- |
Bruce Perry
Member #270
April 2000
|
Ack! PLEASE stop referring to 100ths of seconds as milliseconds! They're not milliseconds, they're centiseconds! No, DUMB does not do any FFT or similar algorithms yet. I implemented it in ML, which has a tendency to be one of the slowest languages around (although apparently it "can now run as fast as C"... DUMB's .mod support is on its way though. DUMB CVS also does length calculation. It won't take much more work to allow you to stop a module from looping (it'll use a system that's already in place for the length calculation). So progress is being made I'm dumb!, I really didn't mean to turn this thread into a DUMB plug thread as well -- |
Paul Pridham
Member #250
April 2000
![]() |
If you wrote your FFT in ML (PolyML was it?), you should consider porting it over to O'Caml, which is generally faster than g++. It's also very nifty. ---- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
hehe... pushing other 'intelectual' languages are you paul? I'm dumb!. -- |
Steve Terry
Member #1,989
March 2002
![]() |
TF... I used the MSG_IDLE technique... worked beautifully.. better than I expected.. simply awsome, you don't even knotice much of a drag down and it updates em fast. The only way I can see it working is to scroll all teh way to the bottom, select a file, close the dialog, and reload it... in about 6 seconds it hits the bottom, this also lets me do more complex things with the filenames in case an ID3 tag doesn't exist too, like the filename parsing you did... without any performance hit whatsoever... god I love it. Happy happy happy.....:P;D:P [edit] ___________________________________ |
Bruce Perry
Member #270
April 2000
|
Yep, it was Poly/ML. Cool, I'll try O'Caml then (it should be installed on here, though it might be an out-of-date version). However, unless the compiler can really work miracles, I doubt it'll do better than gcc on an algorithm that can work in place in a procedural implementation Why do you mention g++ in particular? It's my understanding that compiled C++ code used to be slower than compiled C code (assuming the source file is understandable as both), but not any more... For reference, here's the thread in which I implemented FFT. (I wonder if I should clone Steve Terry now By the way, XMMS is much faster than Winamp at reading the ID3 tags. Hooray for Linux's file system! -- |
Steve Terry
Member #1,989
March 2002
![]() |
Hmm I wonder what fmod wrote their FFT functions in.. it's quite fast too. I bet I still have some source on my HD from earlier versions before they just sent out the dlls and libs only. Yes and XMMS is cool, it has some nice visuals too. Oh and sadly this topic is getting off topic unless we start talking about programming again...... I think I'll shut up. ___________________________________ |
Paul Pridham
Member #250
April 2000
![]() |
Thomas: If I was an intellectual, I'd reply "yes" to that. Ben: I mentioned g++ because of this: http://www.bagley.org/~doug/shootout/ ... O'Caml did very well. Anyway, definitely look at O'Caml. It's doubly cool because O'Caml is also a scripting language as well as a compiler, as well as giving you the productivity increases that you already know about from using ML. ---- |
Steve Terry
Member #1,989
March 2002
![]() |
clone me?? um.. ok.. but I think there is enough of just one of me around... but I bet two of us would code a lot faster... what about writing a DUMB wrapper for my GUI ___________________________________ |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Steve: Cool. I just thought that would be the best way, short of rewriting everything to use threads Paul: It just seems you like those languages that are mostly used by scientists (who don't code much) -- |
|
1
2
|