| 1 |
/* Copyright (C) 2008 Vincent Penquerc'h. |
| 2 |
This file is part of the Kate codec library. |
| 3 |
Written by Vincent Penquerc'h. |
| 4 |
|
| 5 |
Use, distribution and reproduction of this library is governed |
| 6 |
by a BSD style source license included with this source in the |
| 7 |
file 'COPYING'. Please read these terms before distributing. */ |
| 8 |
|
| 9 |
|
| 10 |
#ifdef HAVE_CONFIG_H |
| 11 |
#include "config.h" |
| 12 |
#endif |
| 13 |
#include <stdio.h> |
| 14 |
#ifdef HAVE_STDLIB_H |
| 15 |
#include <stdlib.h> |
| 16 |
#endif |
| 17 |
#include <ogg/ogg.h> |
| 18 |
#include "kate/kate.h" |
| 19 |
#include "kutil.h" |
| 20 |
|
| 21 |
static int time_total_milliseconds(kate_float t) |
| 22 |
{ |
| 23 |
return (int)(t*1000+(kate_float)0.5); |
| 24 |
} |
| 25 |
|
| 26 |
int time_hours(kate_float t) |
| 27 |
{ |
| 28 |
return time_total_milliseconds(t)/(60*60*1000); |
| 29 |
} |
| 30 |
|
| 31 |
int time_minutes(kate_float t) |
| 32 |
{ |
| 33 |
return time_total_milliseconds(t)/(60*1000)%60; |
| 34 |
} |
| 35 |
|
| 36 |
int time_seconds(kate_float t) |
| 37 |
{ |
| 38 |
return time_total_milliseconds(t)/1000%60; |
| 39 |
} |
| 40 |
|
| 41 |
int time_milliseconds(kate_float t) |
| 42 |
{ |
| 43 |
return time_total_milliseconds(t)%1000; |
| 44 |
} |
| 45 |
|
| 46 |
kate_float time_float_seconds(kate_float t) |
| 47 |
{ |
| 48 |
return time_milliseconds(t)/(kate_float)1000+time_seconds(t); |
| 49 |
} |
| 50 |
|
| 51 |
void granule_to_hmsms(const kate_info *ki,ogg_int64_t granpos,int *h,int *m,int *s,int *ms) |
| 52 |
{ |
| 53 |
*h=(granpos*ki->gps_denominator)/ki->gps_numerator/(60*60); |
| 54 |
granpos-=(*h*ki->gps_numerator+ki->gps_denominator/2)/ki->gps_denominator*60*60; |
| 55 |
*m=(granpos*ki->gps_denominator)/ki->gps_numerator/60; |
| 56 |
granpos-=(*m*ki->gps_numerator+ki->gps_denominator/2)/ki->gps_denominator*60; |
| 57 |
*s=(granpos*ki->gps_denominator)/ki->gps_numerator; |
| 58 |
granpos-=(*s*ki->gps_numerator+ki->gps_denominator/2)/ki->gps_denominator; |
| 59 |
*ms=(1000*granpos*ki->gps_denominator)/ki->gps_numerator; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
const char *eat_arg(int argc,char **argv,int *n) |
| 64 |
{ |
| 65 |
if (*n==argc-1) { |
| 66 |
fprintf(stderr,"%s needs an argument\n",argv[*n]); |
| 67 |
exit(-1); |
| 68 |
} |
| 69 |
return argv[++*n]; |
| 70 |
} |
| 71 |
|