timer.c File Reference

Implements mad_timer_t methods, used when decoding header frames. More...

#include "global.h"
#include <stdio.h>
#include "timer.h"

Include dependency graph for timer.c:

Go to the source code of this file.

Functions

int mad_timer_compare (mad_timer_t timer1, mad_timer_t timer2)
 Indicates relative order of two timers.
void mad_timer_negate (mad_timer_t *timer)
 Inverts the sign of a timer.
mad_timer_t mad_timer_abs (mad_timer_t timer)
 Returns the absolute value of a timer.
static void reduce_timer (mad_timer_t *timer)
 Carrys timer fraction into seconds.
static unsigned long gcd (unsigned long num1, unsigned long num2)
 Computes greatest common denominator.
static void reduce_rational (unsigned long *numer, unsigned long *denom)
 Converts rational expression to lowest terms.
static unsigned long scale_rational (unsigned long numer, unsigned long denom, unsigned long scale)
 Solves numer/denom == ?/scale avoiding overflowing.
void mad_timer_set (mad_timer_t *timer, unsigned long seconds, unsigned long numer, unsigned long denom)
 Sets timer to specific (positive) value.
void mad_timer_add (mad_timer_t *timer, mad_timer_t incr)
 Adds one timer to another.
void mad_timer_multiply (mad_timer_t *timer, signed long scalar)
 Multiplies a timer by a scalar value.
signed long mad_timer_count (mad_timer_t timer, enum mad_units units)
 Returns timer value in selected units.
unsigned long mad_timer_fraction (mad_timer_t timer, unsigned long denom)
 Returns fractional part of timer in arbitrary terms.
void mad_timer_string (mad_timer_t timer, char *dest, char const *format, enum mad_units units, enum mad_units fracunits, unsigned long subparts)
 Writes a string representation of a timer using a template.

Variables

mad_timer_t const mad_timer_zero = { 0, 0 }


Detailed Description

Implements mad_timer_t methods, used when decoding header frames.

Definition in file timer.c.


Function Documentation

static unsigned long gcd ( unsigned long  num1,
unsigned long  num2 
) [static]

Computes greatest common denominator.

Definition at line 101 of file timer.c.

Referenced by reduce_rational().

mad_timer_t mad_timer_abs ( mad_timer_t  timer  ) 

Returns the absolute value of a timer.

Definition at line 79 of file timer.c.

References mad_timer_negate(), and mad_timer_t::seconds.

Referenced by mad_timer_fraction(), and mad_timer_string().

Here is the call graph for this function:

void mad_timer_add ( mad_timer_t timer,
mad_timer_t  incr 
)

Adds one timer to another.

Definition at line 224 of file timer.c.

References mad_timer_t::fraction, MAD_TIMER_RESOLUTION, reduce_timer(), and mad_timer_t::seconds.

Referenced by mad_timer_multiply().

Here is the call graph for this function:

int mad_timer_compare ( mad_timer_t  timer1,
mad_timer_t  timer2 
)

Indicates relative order of two timers.

Definition at line 44 of file timer.c.

References mad_timer_t::fraction, and mad_timer_t::seconds.

signed long mad_timer_count ( mad_timer_t  timer,
enum mad_units  units 
)

unsigned long mad_timer_fraction ( mad_timer_t  timer,
unsigned long  denom 
)

Returns fractional part of timer in arbitrary terms.

Definition at line 315 of file timer.c.

References mad_timer_t::fraction, mad_timer_abs(), MAD_TIMER_RESOLUTION, and scale_rational().

Here is the call graph for this function:

void mad_timer_multiply ( mad_timer_t timer,
signed long  scalar 
)

Multiplies a timer by a scalar value.

Definition at line 236 of file timer.c.

References mad_timer_add(), and mad_timer_negate().

Here is the call graph for this function:

void mad_timer_negate ( mad_timer_t timer  ) 

Inverts the sign of a timer.

Definition at line 66 of file timer.c.

References mad_timer_t::fraction, MAD_TIMER_RESOLUTION, and mad_timer_t::seconds.

Referenced by mad_timer_abs(), and mad_timer_multiply().

void mad_timer_set ( mad_timer_t timer,
unsigned long  seconds,
unsigned long  numer,
unsigned long  denom 
)

Sets timer to specific (positive) value.

Definition at line 153 of file timer.c.

References mad_timer_t::fraction, MAD_TIMER_RESOLUTION, reduce_timer(), scale_rational(), and mad_timer_t::seconds.

Referenced by mad_header_decode().

Here is the call graph for this function:

void mad_timer_string ( mad_timer_t  timer,
char *  dest,
char const *  format,
enum mad_units  units,
enum mad_units  fracunits,
unsigned long  subparts 
)

static void reduce_rational ( unsigned long *  numer,
unsigned long *  denom 
) [static]

Converts rational expression to lowest terms.

Definition at line 118 of file timer.c.

References assert, and gcd().

Referenced by scale_rational().

Here is the call graph for this function:

static void reduce_timer ( mad_timer_t timer  )  [static]

Carrys timer fraction into seconds.

Definition at line 91 of file timer.c.

References mad_timer_t::fraction, MAD_TIMER_RESOLUTION, and mad_timer_t::seconds.

Referenced by mad_timer_add(), and mad_timer_set().

static unsigned long scale_rational ( unsigned long  numer,
unsigned long  denom,
unsigned long  scale 
) [static]

Solves numer/denom == ?/scale avoiding overflowing.

Definition at line 134 of file timer.c.

References assert, and reduce_rational().

Referenced by mad_timer_count(), mad_timer_fraction(), mad_timer_set(), and mad_timer_string().

Here is the call graph for this function:


Variable Documentation

mad_timer_t const mad_timer_zero = { 0, 0 }

Definition at line 39 of file timer.c.

Referenced by mad_header_init().


Generated on Tue Jun 10 12:14:18 2008 for libmad by  doxygen 1.5.5