Time

## Topics

| Software timer

## Macros

#define | GAVL_TIME_SCALE 1000000
#define | GAVL_TIME_UNDEFINED 0x8000000000000000LL
#define | GAVL_TIME_MAX 0x7fffffffffffffffLL
#define | gavl_seconds_to_time(s)
| Convert seconds (as double) to a gavl time.
#define | gavl_time_to_seconds(t)
| Convert a gavl time to seconds (as double).
#define | GAVL_TIME_STRING_LEN 11
| Length of the string passed to gavl_time_prettyprint.
#define | GAVL_TIME_STRING_LEN_MS 15
| Length of the string passed to gavl_time_prettyprint_ms.

## Typedefs

typedef int64_t | gavl_time_t
| Times in gavl are 64 bit signed integers.

## Functions

GAVL_PUBLIC gavl_time_t | gavl_samples_to_time (int samplerate, int64_t samples)
| Convert a number of samples to a time for a given samplerate.
GAVL_PUBLIC int64_t | gavl_time_to_samples (int samplerate, gavl_time_t time)
| Convert a time to a number of audio samples for a given samplerate.
GAVL_PUBLIC gavl_time_t | gavl_frames_to_time (int rate_num, int rate_den, int64_t frames)
| Convert a number of video frames to a time for a given framerate.
GAVL_PUBLIC int64_t | gavl_time_to_frames (int rate_num, int rate_den, gavl_time_t time)
| Convert a time to a number of video frames for a given framerate.
GAVL_PUBLIC int64_t | gavl_time_scale (int scale, gavl_time_t time)
| Convert a gavl time to a time scaled by another base.
GAVL_PUBLIC gavl_time_t | gavl_time_unscale (int scale, int64_t time)
| Convert a time scaled by another base to a gavl time.
GAVL_PUBLIC int64_t | gavl_time_rescale (int scale1, int scale2, int64_t time)
| Convert a time scaled by one base to a time scaled by another base.
GAVL_PUBLIC void | gavl_time_delay (gavl_time_t *time)
| Sleep for a specified time.
GAVL_PUBLIC void | gavl_time_prettyprint (gavl_time_t time, char str[GAVL_TIME_STRING_LEN])
| Convert a time to a string.
GAVL_PUBLIC void | gavl_time_prettyprint_ms (gavl_time_t time, char str[GAVL_TIME_STRING_LEN_MS])
| Convert a time to a string with millisecond precision.

## Detailed Description

## Macro Definition Documentation

## GAVL_TIME_SCALE

#define GAVL_TIME_SCALE 1000000

Generic time scale: Microsecond tics

## GAVL_TIME_UNDEFINED

#define GAVL_TIME_UNDEFINED 0x8000000000000000LL

Unknown or undefined time

## GAVL_TIME_MAX

#define GAVL_TIME_MAX 0x7fffffffffffffffLL

Maximum possible value

## gavl_seconds_to_time

#define gavl_seconds_to_time | ( |  | s | ) |

Value:
(gavl_time_t)((s)*(double)(GAVL_TIME_SCALE))
gavl_time_t
int64_t gavl_time_t
Times in gavl are 64 bit signed integers.
Definition gavltime.h:54
GAVL_TIME_SCALE
#define GAVL_TIME_SCALE
Definition gavltime.h:39

Convert seconds (as double) to a gavl time.

Parameters

  s | Seconds as double

Returns
  Integer time scaled by GAVL_TIME_SCALE

## gavl_time_to_seconds

#define gavl_time_to_seconds | ( |  | t | ) |

Value:
((double)(t)/(double)(GAVL_TIME_SCALE))

Convert a gavl time to seconds (as double).

Parameters

  t | Integer time scaled by GAVL_TIME_SCALE

Returns
  Seconds as double

## GAVL_TIME_STRING_LEN

#define GAVL_TIME_STRING_LEN 11

Length of the string passed to gavl_time_prettyprint.

Referenced by gavl_time_prettyprint().

## GAVL_TIME_STRING_LEN_MS

#define GAVL_TIME_STRING_LEN_MS 15

Length of the string passed to gavl_time_prettyprint_ms.

Referenced by gavl_time_prettyprint_ms().

## Typedef Documentation

## gavl_time_t

typedef int64_t gavl_time_t

Times in gavl are 64 bit signed integers.

## Function Documentation

## gavl_samples_to_time()

GAVL_PUBLIC gavl_time_t gavl_samples_to_time | ( | int | samplerate,
|  | int64_t | samples )

Convert a number of samples to a time for a given samplerate.

## gavl_time_to_samples()

GAVL_PUBLIC int64_t gavl_time_to_samples | ( | int | samplerate,
|  | gavl_time_t | time )

Convert a time to a number of audio samples for a given samplerate.

Parameters

  samplerate | Samplerate
  time | Time

Returns
  Number of audio samples

## gavl_frames_to_time()

GAVL_PUBLIC gavl_time_t gavl_frames_to_time | ( | int | rate_num,
|  | int | rate_den,
|  | int64_t | frames )

Convert a number of video frames to a time for a given framerate.

## gavl_time_to_frames()

GAVL_PUBLIC int64_t gavl_time_to_frames | ( | int | rate_num,
|  | int | rate_den,
|  | gavl_time_t | time )

Convert a time to a number of video frames for a given framerate.

Parameters

  rate_num | Numerator of the framerate
  rate_den | Denominator of the framerate
  time | Time

Returns
  Number of frames

## gavl_time_scale()

GAVL_PUBLIC int64_t gavl_time_scale | ( | int | scale,
|  | gavl_time_t | time )

Convert a gavl time to a time scaled by another base.

Parameters

  scale | Time scale
  time | Time scaled by GAVL_TIME_SCALE

Returns
  Time scaled by scale

## gavl_time_unscale()

GAVL_PUBLIC gavl_time_t gavl_time_unscale | ( | int | scale,
|  | int64_t | time )

Convert a time scaled by another base to a gavl time.

Parameters

  scale | Time scale
  time | Time scaled by scale

Returns
  Time scaled by GAVL_TIME_SCALE

## gavl_time_rescale()

GAVL_PUBLIC int64_t gavl_time_rescale | ( | int | scale1,
|  | int | scale2,
|  | int64_t | time )

Convert a time scaled by one base to a time scaled by another base.

Parameters

  scale1 | Initial time base
  scale2 | New time base
  time | Time scaled by scale1

Returns
  Time scaled by scale2

## gavl_time_delay()

GAVL_PUBLIC void gavl_time_delay | ( | gavl_time_t * | time | ) |

Sleep for a specified time.

Parameters

  time | Time after which execution of the current thread is resumed

## gavl_time_prettyprint()

GAVL_PUBLIC void gavl_time_prettyprint | ( | gavl_time_t | time,
|  | char | str[GAVL_TIME_STRING_LEN] )

Convert a time to a string.

Parameters

  time | Time to print
  str | String

This prints a gavl_time into ASCII string if a format suitable for player displays. The format is: -hhh:mm:ss

References GAVL_TIME_STRING_LEN.

## gavl_time_prettyprint_ms()

GAVL_PUBLIC void gavl_time_prettyprint_ms | ( | gavl_time_t | time,
|  | char | str[GAVL_TIME_STRING_LEN_MS] )

Convert a time to a string with millisecond precision.

Parameters

  time | Time to print
  str | String

This prints a gavl_time into ASCII string if a format suitable for player displays. The format is: -hhh:mm:ss.MMM

Since 1.1.1

References GAVL_TIME_STRING_LEN_MS.