File: time.c

package info (click to toggle)
libcue 2.2.1-4%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 272 kB
  • sloc: ansic: 1,273; yacc: 285; lex: 139; makefile: 13
file content (36 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * time.c -- time functions
 *
 * Copyright (C) 2004, 2005, 2006, 2007 Svend Sorensen
 * For license terms, see the file COPYING in this distribution.
 */

#include "time.h"
#include <stdio.h>
#include <stdlib.h>

long time_msf_to_frame(int m, int s, int f)
{
	return (m * 60 + s) * 75 + f;
}

void time_frame_to_msf(long frame, int *m, int *s, int *f)
{
	*f = frame % 75;           /* 0 <= frames <= 74 */
	frame /= 75;
	*s = frame % 60;          /* 0 <= seconds <= 59 */
	frame /= 60;
	*m = frame;               /* 0 <= minutes */
}

/* print frame in mm:ss:ff format */
char *time_frame_to_mmssff(long f)
{
	static char msf[9];
	int minutes, seconds, frames;

	time_frame_to_msf(f, &minutes, &seconds, &frames);
	sprintf(msf, "%02d:%02d:%02d", minutes, seconds, frames);

	return msf;
}