Line | Count | Source |
1 | | /* |
2 | | * time.c -- time functions |
3 | | * |
4 | | * Copyright (C) 2004, 2005, 2006, 2007 Svend Sorensen |
5 | | * For license terms, see the file COPYING in this distribution. |
6 | | */ |
7 | | |
8 | | #include "time.h" |
9 | | #include <stdio.h> |
10 | | #include <stdlib.h> |
11 | | #include <string.h> |
12 | | |
13 | | long time_msf_to_frame(int m, int s, int f) |
14 | 4.07k | { |
15 | 4.07k | if (m < 0 || m > 99 || s < 0 || s >= 60 || f < 0 || f >= 75) { |
16 | 3.46k | return -1; |
17 | 3.46k | } |
18 | 611 | return (m * 60 + s) * 75 + f; |
19 | 4.07k | } |
20 | | |
21 | | void time_frame_to_msf(long frame, int *m, int *s, int *f) |
22 | 0 | { |
23 | 0 | *f = frame % 75; /* 0 <= frames <= 74 */ |
24 | 0 | frame /= 75; |
25 | 0 | *s = frame % 60; /* 0 <= seconds <= 59 */ |
26 | 0 | frame /= 60; |
27 | 0 | *m = frame; /* 0 <= minutes */ |
28 | 0 | } |
29 | | |
30 | | /* print frame in mm:ss:ff format */ |
31 | | char *time_frame_to_mmssff(long f) |
32 | 0 | { |
33 | 0 | static char msf[9]; |
34 | 0 | int minutes, seconds, frames; |
35 | |
|
36 | 0 | if (f < 0 || f >= 75 * 60 * 100) { |
37 | 0 | strcpy(msf, "00:00:00"); |
38 | 0 | return msf; |
39 | 0 | } |
40 | | |
41 | 0 | time_frame_to_msf(f, &minutes, &seconds, &frames); |
42 | 0 | snprintf(msf, sizeof(msf), "%02d:%02d:%02d", minutes, seconds, frames); |
43 | |
|
44 | 0 | return msf; |
45 | 0 | } |