File: timebase.h

package info (click to toggle)
audacity 2.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,076 kB
  • sloc: cpp: 192,859; ansic: 158,072; sh: 34,021; python: 24,248; lisp: 7,495; makefile: 3,667; xml: 573; perl: 31; sed: 16
file content (85 lines) | stat: -rw-r--r-- 3,405 bytes parent folder | download | duplicates (12)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* timebase.h -- management of calls, time bases and heaps for moxc */

#define STOPRATE 0xFFFFL

/***************************************************************************
* call structure
****************************************************************************/

/* ---NOTE!!! if you change MAX_CALL_ARGS, change CALLARGS macro below--- */
#define MAX_CALL_ARGS 8
typedef struct call_args_struct {
  long arg[MAX_CALL_ARGS];
} call_args_node;

typedef struct call {
    union {
        struct {
            time_type time;     /* virtual time of this call */
            int priority;       /* an 8-bit the priority, low priority first */
            int (*routine)();   /* who to call */
            call_args_node p; /* what to pass */
        } e;
        struct call *p; /* used to link free calls */
    } u;
} *call_type, call_node;

/* CALLARGS - given a call_type, this macro generates an argument list */
/*
 * NOTE: originally, I thought call->u.e.p (a structure), would do it, but
 * Lattice C for the Amiga has a compiler bug, and even in places where the
 * bug doesn't show up, the code generated for the structure passing is 
 * a sequence of two loops: one to copy data to a local area on the stack,
 * and one to push this data (a byte at a time!) to the top of the stack.
 * With Lattice (and perhaps others, I haven't checked), it's better to 
 * push the data in-line.
 */
#ifdef LATTICE
#define CARG(n) call->u.e.p.arg[n]
#define CALLARGS(call) CARG(0), CARG(1), CARG(2), CARG(3), \
                CARG(4), CARG(5), CARG(6), CARG(7)
#else
#define CALLARGS(call) call->u.e.p
#endif

/***************************************************************************
* timebase structure
****************************************************************************/

typedef struct timebase_struct {
    struct timebase_struct *next;       /* used for list */
    time_type next_time;
    time_type virt_base;
    time_type real_base;
    time_type rate; /* ratio of real/virt time, STOPRATE or more is infinity */
    short heap_size;
    short heap_max;
    call_type *heap;
} timebase_node, *timebase_type;

extern timebase_type timebase_queue;

#define call_alloc() ((call_type) memget(sizeof(call_node)))
#define call_free(c) memfree((char *) (c), sizeof(call_node))

timebase_type   timebase_create(int maxsize);
void            callinsert(timebase_type base, call_type call);
void            callshow(call_type call);
void            timebase_free(timebase_type timebase);
void            insert_base(timebase_type timebase);
void            remove_base(timebase_type timebase);
call_type       remove_call(timebase_type a_timebase);
void            set_rate(timebase_type base, time_type rate);
void            set_virttime(timebase_type base, time_type vtime);
void            timebase_use(timebase_type base);

#define real_to_virt(base, rtime) ((base)->rate == 0 ? MAXTIME : \
 ((base)->virt_base + (((rtime) - (base)->real_base) << 8) / (base)->rate))

#define virt_to_real(base, vtime) ((base)->rate >= STOPRATE ? \
 ((base)->virt_base > vtime ? (base)->real_base : MAXTIME) : \
 (base)->real_base + ((((vtime) - (base)->virt_base) * (base)->rate) >> 8))

#define virt_to_real_256(base, vtime) ((base)->rate >= STOPRATE ? \
 ((base)->virt_base > vtime ? (base)->real_base << 8 : MAXTIME) : \
 ((base)->real_base << 8) + ((((vtime) - (base)->virt_base) * (base)->rate)))