Does this look okay? : Time: 1:15.50 of 4:13.73, Bitrate: 133.3 How about? : <snip from=ogg123.c> info.u_time = ov_time_total (&vf, -1); /* Seconds with double precision */ gettimeofday (&start_time, NULL); t_min = (long) info.u_time / (long) 60; t_sec = info.u_time - 60 * t_min; while (! eos) { gettimeofday (&cur_time, NULL); c_min = (long) (cur_time.tv_sec - start_time.tv_sec) / (long) 60; c_sec = (cur_time.tv_sec - start_time.tv_sec) - 60 * c_min + ((cur_time.tv_usec - start_time.tv_usec) / 1000000.0); </snip> Scream now! I'm committing... I know time functions like this have easy equivalents on other OSes. Kenneth --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/
Kenneth Arnold wrote:> Does this look okay? :Almost. Consider this case, though. start_time = 00:00:59.6 (tv_sec = 59, tv_usec = 600000) cur_time = 00:01:59.5 (tv_sec = 119, tv_usec = 500000) The code posted calculates c_min = 1, c_sec = -0.9; Here's a fix (I think), assuming that c_min and c_sec are integral types. < c_min = (long) (cur_time.tv_sec - start_time.tv_sec) / (long) 60; < c_sec = (cur_time.tv_sec - start_time.tv_sec) - 60 * c_min + < ((cur_time.tv_usec - start_time.tv_usec) / 1000000.0); ---> c_sec = (cur_time.tv_sec - start_time.tv_sec) + > ((cur_time.tv_usec - start_time.tv_usec) / 1000000.0); > c_min = c_sec / 60; > c_sec -= 60 * c_min;> Scream now! I'm committing...Sorry, I wasn't looking. I promise not to let it happen again... (-: -- K<bob> kbob@jogger-egg.com, http://www.jogger-egg.com/ --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/
Argh! Didn't see ov_time_tell... Now what I've got is much cleaner, and has no mistakes like the one pointed out. Time: 01:08.81 [04:07.93] of 05:16.73, Bitrate: 200.2 if (param.verbose > 0) { info.u_time = ov_time_total (&vf, -1); /* Seconds with double * precision */ t_min = (long) info.u_time / (long) 60; t_sec = info.u_time - 60 * t_min; } while (! eos) { <...> if (param.verbose > 0) { info.u_pos = ov_time_tell (&vf); c_min = (long) info.u_pos / (long) 60; c_sec = info.u_pos - 60 * c_min; r_min = (long) (info.u_time - info.u_pos) / (long) 60; r_sec = (info.u_time - info.u_pos) - 60 * r_min; fprintf (stderr, "\rTime: %02li:%05.2f [%02li:%05.2f] of %02li:%05.2f," " Bitrate: %.1f \r", c_min, c_sec, r_min, r_sec, t_min, t_sec, (float) ov_bitrate_instant (&vf) / 1000.0F); } Kenneth --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/