player_fifo.c
3.74 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*************************************************************
player_fifo.c : Nintendo 64 Music Tools Programmers Library
(c) Copyright 1997/1998, Software Creations (Holdings) Ltd.
Version 3.14
Music library fifo functions.
**************************************************************/
static int fifo_start;
static int fifo_current;
static int fifo_limit;
static fifo_t *fifo_addr;
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[INTERNAL FUNCTION]
__MusIntFifoOpen(commands)
[Parameters]
commands number of commands to support in fifo
[Explanation]
Initialise fifo command buffer. The fifo command buffer is used to pass commands
to the player from the current thread, these commands are commands that would
suffer it the current thread was interrupted by the players thread.
The number of commands supported is set in the library config structure.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void __MusIntFifoOpen(int commands)
{
if (commands<MIN_FIFO_COMMANDS)
{
#ifdef _AUDIODEBUG
osSyncPrintf("PLAYER_FIFO.C: Using minimum fifo size.\n");
#endif
commands = MIN_FIFO_COMMANDS;
}
else if (commands>MAX_FIFO_COMMANDS)
{
#ifdef _AUDIODEBUG
osSyncPrintf("PLAYER_FIFO.C: Using maximum fifo size.\n");
#endif
commands = MAX_FIFO_COMMANDS;
}
fifo_addr = __MusIntMemMalloc(commands*sizeof(fifo_t));
fifo_limit = commands;
fifo_start = fifo_current = 0;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[INTERNAL FUNCTION]
__MusIntFifoProcess()
[Explanation]
Process any commands in the fifo buffer, these commands will be processed before
the player is updated.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void __MusIntFifoProcess(void)
{
if (fifo_start==fifo_current)
return;
while (fifo_start!=fifo_current)
{
__MusIntFifoProcessCommand(&fifo_addr[fifo_start]);
fifo_start++;
if (fifo_start==fifo_limit)
fifo_start=0;
}
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[INTERNAL FUNCTION]
__MusIntFifoProcessCommand(command)
[Parameters]
command address of fifo command
[Explanation]
Process the specified fifo command.
[Return value]
NONE
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void __MusIntFifoProcessCommand(fifo_t *command)
{
switch (command->command)
{
case FIFOCMD_PAUSE:
__MusIntHandleSetFlag(command->data, ~CHFLAG_PAUSE, CHFLAG_PAUSE);
break;
case FIFOCMD_UNPAUSE:
__MusIntHandleSetFlag(command->data, ~CHFLAG_PAUSE, 0);
break;
case FIFOCMD_CHANGEFX:
#ifdef SUPPORT_FXCHANGE
ChangeCustomEffect(command->data);
#endif
break;
#ifdef _AUDIODEBUG
default:
osSyncPrintf("PLAYER_FIFO.C: Unknown fifo command found!\n");
#endif
}
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[INTERNAL FUNCTION]
__MusIntFifoAddCommand(command)
[Parameters]
command address of fifo command
[Explanation]
Store the given command in the fifo list.
[Return value]
0 if the fifo list is full, <>0 if the command was stored.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static int __MusIntFifoAddCommand(fifo_t *command)
{
int index;
index = (fifo_current+1)%fifo_limit;
if (index==fifo_start)
{
#ifdef _AUDIODEBUG
osSyncPrintf("PLAYER_FIFO.C: Fifo is full ignoring last command!\n");
#endif
return (0);
}
__MusIntMemMove(&fifo_addr[fifo_current], command, sizeof(fifo_t));
fifo_current = index;
return (1);
}
/* end of file */