Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1655 | giacomo | 1 | /* Project: HARTIK 3.0 */ |
2 | /* Description: Hard Real TIme Kernel for 386 & higher machines */ |
||
3 | /* Author: Paolo Gai <pgai@rsk.it> */ |
||
4 | /* Advanced Linux Sound Architecture (ALSA) */ |
||
5 | /* Copyright (c) by Jaroslav Kysela <perex@jcu.cz> */ |
||
6 | /* Luca Abeni */ |
||
7 | /* FFTW by M. Frigo and S. G. Johnson */ |
||
8 | |||
9 | /* Date: 08/09/1999 */ |
||
10 | |||
11 | /* File: fftplay.c */ |
||
12 | /* Revision: 1.00 (Kernel 0.1.4; Library 0.0.9; Util 0.0.4) */ |
||
13 | |||
14 | |||
15 | |||
16 | #include "demo.h" |
||
17 | |||
18 | //#include <kernel/types.h> |
||
19 | //#include <kernel/model.h> |
||
20 | #include <kernel/func.h> |
||
21 | |||
22 | //#include <modules/cabs.h> |
||
23 | |||
24 | #include <string.h> |
||
25 | #include <stdlib.h> |
||
26 | |||
27 | #include <drivers/keyb.h> |
||
28 | //#include <drivers/crtwin.h> |
||
29 | #include <drivers/glib.h> |
||
30 | //#include <drivers/sound.h> |
||
31 | //#include <ports/rfftw.h> |
||
32 | |||
33 | |||
34 | |||
35 | /* Informations about the sampling rate and buffers */ |
||
36 | WORD rawdata_nsamples; |
||
37 | WORD rawdata_buffer_size; |
||
38 | WORD rawdata_freq; |
||
39 | |||
40 | /* graphic mutex... */ |
||
41 | mutex_t mutex; |
||
42 | |||
43 | /* useful colors... */ |
||
44 | int white; |
||
45 | int black; |
||
46 | int red; |
||
47 | int gray; |
||
48 | |||
49 | void app_mutex_init(mutex_t *m); |
||
50 | |||
51 | |||
52 | static void version( void ) |
||
53 | { |
||
54 | cprintf( "Hartik FFT Play 1.0\n" ); |
||
55 | cprintf( "-----------------------\n" ); |
||
56 | cprintf( "by Paolo Gai 1999\n" ); |
||
57 | cprintf( " <pj@hartik.sssup.it>\n" ); |
||
58 | cprintf( "-----------------------\n" ); |
||
59 | } |
||
60 | |||
61 | void reverse(char s[]) |
||
62 | { |
||
63 | int c, i, j; |
||
64 | |||
65 | for (i = 0, j = strlen(s)-1; i<j; i++, j--) |
||
66 | { |
||
67 | c = s[i]; |
||
68 | s[i] = s[j]; |
||
69 | s[j] = c; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | char * itoa(int n, char *s) |
||
74 | { |
||
75 | int i, sign; |
||
76 | |||
77 | if ((sign = n) < 0) |
||
78 | n = -n; |
||
79 | |||
80 | i = 0; |
||
81 | |||
82 | do |
||
83 | { |
||
84 | s[i++] = n % 10 + '0'; |
||
85 | } while ((n /= 10) > 0); |
||
86 | |||
87 | if (sign < 0) |
||
88 | s[i++] = '-'; |
||
89 | |||
90 | s[i] = 0; |
||
91 | |||
92 | reverse(s); |
||
93 | |||
94 | return s; |
||
95 | } |
||
96 | |||
97 | void display_jet(PID i) |
||
98 | { |
||
99 | char st[200]; |
||
100 | TIME sum, max; |
||
101 | int n; |
||
102 | |||
103 | if (jet_getstat(i, &sum, &max, &n, NULL) != -1) { |
||
104 | if (n==0) n=1; |
||
105 | sprintf(st, "PID=%2d st=%3d Mean=%5d Max=%5d na=%10s", |
||
106 | (int)i, |
||
107 | (int)proc_table[i].status, (int)sum/n, (int)max, |
||
108 | proc_table[i].name); |
||
109 | mutex_lock(&mutex); |
||
110 | grx_text(st, 0, 400+i*8, 255, 0); |
||
111 | mutex_unlock(&mutex); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | |||
116 | |||
117 | void scenario(int f) |
||
118 | { |
||
119 | grx_text("HARTIK 4.0 - LEGO Version" , 0,0, rgb16(0,255,0), black ); |
||
120 | grx_text("Thesis Demo", 0,8, rgb16(0,255,0), black ); |
||
121 | |||
122 | #ifdef FFT_ON |
||
123 | scenario_fftplay(f); |
||
124 | #endif |
||
125 | |||
126 | #ifdef FRAMEGRABBER_ON |
||
127 | scenario_framegrabber(); |
||
128 | #endif |
||
129 | |||
130 | #ifdef JET_ON |
||
131 | scenario_jetcontrol(); |
||
132 | #endif |
||
133 | |||
134 | #ifdef BALL_ON |
||
135 | scenario_ball(); |
||
136 | #endif |
||
137 | } |
||
138 | |||
139 | |||
140 | void my_close(void *arg) |
||
141 | { |
||
142 | grx_close(); |
||
143 | } |
||
144 | |||
145 | |||
146 | void endfun(KEY_EVT *k) |
||
147 | { |
||
148 | grx_close(); |
||
149 | cprintf("Ctrl-Brk pressed! Ending...\n"); |
||
150 | sys_end(); |
||
151 | } |
||
152 | |||
153 | void zerofun(KEY_EVT *k) |
||
154 | { |
||
155 | int i; |
||
156 | for (i=0; i<MAX_PROC; i++) jet_delstat(i); |
||
157 | } |
||
158 | |||
159 | void printeventqueue(void *arg) |
||
160 | { |
||
161 | struct event *p; |
||
162 | extern struct event *firstevent; |
||
163 | |||
164 | kern_cli(); |
||
165 | grx_close(); |
||
166 | kern_cli(); |
||
167 | for (p = firstevent; p != NULL; p = p->next) { |
||
168 | kern_printf("par:%d time:%ld.%ld p:%d handler:%d\n", |
||
169 | (int)p->par, p->time.tv_sec, p->time.tv_nsec/1000, (int)p, (int)p->handler); |
||
170 | } |
||
171 | kern_sti(); |
||
172 | } |
||
173 | |||
174 | int main(int argc, char **argv) |
||
175 | { |
||
176 | int modenum; |
||
177 | |||
178 | int f; |
||
179 | |||
180 | KEY_EVT k; |
||
181 | |||
182 | srand(4); |
||
183 | |||
184 | version(); |
||
185 | |||
186 | #ifdef FRAMEGRABBER_ON |
||
187 | if (argc == 1) |
||
188 | { |
||
189 | cprintf("type x fftplay <freq>"); |
||
190 | return 0; |
||
191 | } |
||
192 | |||
193 | f = atoi(argv[1]); |
||
194 | compute_params(&f,&rawdata_nsamples); |
||
195 | #endif |
||
196 | |||
197 | keyb_set_map(itaMap); |
||
198 | k.flag = CNTR_BIT; |
||
199 | k.scan = KEY_C; |
||
200 | k.ascii = 'c'; |
||
201 | keyb_hook(k,endfun); |
||
202 | k.flag = CNTL_BIT; |
||
203 | k.scan = KEY_C; |
||
204 | k.ascii = 'c'; |
||
205 | keyb_hook(k,endfun); |
||
206 | k.flag = ALTL_BIT; |
||
207 | k.scan = KEY_C; |
||
208 | k.ascii = 'c'; |
||
209 | keyb_hook(k,zerofun); |
||
210 | k.flag = 0; |
||
211 | k.scan = KEY_ENT; |
||
212 | k.ascii = 13; |
||
213 | keyb_hook(k,endfun); |
||
214 | |||
215 | sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
||
216 | |||
217 | |||
218 | grx_init(); |
||
219 | modenum = grx_getmode(640, 480, 16); |
||
220 | |||
221 | grx_setmode(modenum); |
||
222 | |||
223 | /* init the graphic mutex */ |
||
224 | app_mutex_init(&mutex); |
||
225 | |||
226 | /* useful colors ... */ |
||
227 | white = rgb16(255,255,255); |
||
228 | black = rgb16(0,0,0); |
||
229 | red = rgb16(255,0,0); |
||
230 | gray = rgb16(128,128,128); |
||
231 | |||
232 | scenario(f/2); |
||
233 | // grx_close(); |
||
234 | // clear(); |
||
235 | #ifdef FFT_ON |
||
236 | init_fftplay(f); |
||
237 | #endif |
||
238 | |||
239 | #ifdef FRAMEGRABBER_ON |
||
240 | init_framegrabber(); |
||
241 | #endif |
||
242 | |||
243 | #ifdef JET_ON |
||
244 | init_jetcontrol(); |
||
245 | #endif |
||
246 | |||
247 | #ifdef BALL_ON |
||
248 | init_ball(); |
||
249 | #endif |
||
250 | |||
251 | group_activate(1); |
||
252 | |||
253 | #ifdef FRAMEGRABBER_ON |
||
254 | start_framegrabber(); |
||
255 | #endif |
||
256 | |||
257 | return 0; |
||
258 | } |
||
259 | |||
260 |