Debian Codegraph @

hdlcutil/fl/xfsmmixer_main.cxx

raw symbols SCIP
1 /*****************************************************************************/
2
3 /*
4 * xfsmmixer_main.c -- kernel soundcard radio modem driver mixer utility.
5 *
6 * Copyright (C) 1996,1997,2000 Thomas Sailer ([email protected])
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 *
23 * Please note that the GPL allows you to use the driver, NOT the radio.
24 * In order to use the radio, you need a license from the communications
25 * authority of your country.
26 *
27 *
28 * History:
29 * 0.1 14.12.1996 Started
30 * 0.2 11.05.1997 introduced hdrvcomm.h
31 * 0.3 05.01.2000 upgraded to fltk 1.0.7
32 */
33
34 /*****************************************************************************/
35
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <net/if.h>
41 //#include <forms.h>
42 #include "hdrvcomm.h"
43 #include "xfsmmixer.h"
44
45 #include <config.h>
46 #include <scm-version.h>
47
48 /* ---------------------------------------------------------------------- */
49
50 static char *progname;
51 static unsigned int mixdevice;
52
53 /* ---------------------------------------------------------------------- */
54
55 static int do_mix_ioctl(int cmd, struct sm_mixer_data *mixdat)
56 {
57 struct sm_ioctl par;
58 int i;
59
60 par.cmd = cmd;
61 par.data.mix = *mixdat;
62 i = hdrvc_sm_ioctl(cmd, &par);
63 *mixdat = par.data.mix;
64 return i;
65 }
66
67 /* ---------------------------------------------------------------------- */
68
69 static unsigned char get_mixer_reg(unsigned char addr)
70 {
71 int i;
72 struct sm_mixer_data mixdat;
73
74 mixdat.reg = addr;
75 if ((i = do_mix_ioctl(SMCTL_GETMIXER, &mixdat)) < 0) {
76 perror("do_mix_ioctl: SMCTL_GETMIXER");
77 exit(1);
78 }
79 if (!i)
80 fprintf(stderr, "warning: mixer device %u register %u not "
81 "accessible for reading!\n", mixdat.mixer_type,
82 addr);
83 if (mixdat.mixer_type != mixdevice) {
84 fprintf(stderr, "error: mixer type changed !?\n");
85 exit(2);
86 }
87 return mixdat.data;
88 }
89
90 /* ---------------------------------------------------------------------- */
91
92 static void set_mixer_reg(unsigned char addr, unsigned char data)
93 {
94 struct sm_mixer_data mixdat;
95
96 mixdat.reg = addr;
97 mixdat.data = data;
98 mixdat.mixer_type = mixdevice;
99 if (do_mix_ioctl(SMCTL_SETMIXER, &mixdat) < 0) {
100 perror("do_mix_ioctl: SMCTL_SETMIXER");
101 exit(1);
102 }
103 }
104
105 /* ---------------------------------------------------------------------- */
106
107 void update_ad1848(Fl_Widget *widget, void *udata)
108 {
109 unsigned char mdata;
110 float mval;
111
112 mdata = 0;
113 if (ad1848_srcl_line->value())
114 mdata = 0x00;
115 else if (ad1848_srcl_aux1->value())
116 mdata = 0x40;
117 else if (ad1848_srcl_mic->value())
118 mdata = 0x80;
119 else if (ad1848_srcl_dac->value())
120 mdata = 0xc0;
121 mval = ad1848_inl->value();
122 if (mdata == 0x80 && mval >= 20) {
123 mval -= 20;
124 mdata |= 0x20;
125 }
126 mval *= 0.666666;
127 if (mval > 15)
128 mval = 15;
129 mdata |= (int)mval;
130 set_mixer_reg(0x00, mdata);
131 mdata = 0;
132 if (ad1848_srcr_line->value())
133 mdata = 0x00;
134 else if (ad1848_srcr_aux1->value())
135 mdata = 0x40;
136 else if (ad1848_srcr_mic->value())
137 mdata = 0x80;
138 else if (ad1848_srcr_dac->value())
139 mdata = 0xc0;
140 mval = ad1848_inr->value();
141 if (mdata == 0x80 && mval >= 20) {
142 mval -= 20;
143 mdata |= 0x20;
144 }
145 mval *= 0.666666;
146 if (mval > 15)
147 mval = 15;
148 mdata |= (int)mval;
149 set_mixer_reg(0x01, mdata);
150 set_mixer_reg(0x02, 0x80);
151 set_mixer_reg(0x03, 0x80);
152 set_mixer_reg(0x04, 0x80);
153 set_mixer_reg(0x05, 0x80);
154 mval = ad1848_outl->value();
155 if (mval < -95)
156 set_mixer_reg(0x06, 0x80);
157 else
158 set_mixer_reg(0x06, (unsigned char)(mval * (-0.66666666)));
159 mval = ad1848_outr->value();
160 if (mval < -95)
161 set_mixer_reg(0x07, 0x80);
162 else
163 set_mixer_reg(0x07, (unsigned char)(mval * (-0.66666666)));
164 set_mixer_reg(0x0d, 0x00);
165 }
166
167 /* ---------------------------------------------------------------------- */
168
169 void update_ct1335(Fl_Widget *widget, void *udata)
170 {
171 float mval;
172
173 mval = ct1335_out->value() * (7.0 / 46.0);
174 set_mixer_reg(0x02, ((((int)(mval)) + 7) << 1));
175 set_mixer_reg(0x06, 0x00);
176 set_mixer_reg(0x08, 0x00);
177 set_mixer_reg(0x0a, 0x06);
178 }
179
180 /* ---------------------------------------------------------------------- */
181
182 void update_ct1345(Fl_Widget *widget, void *udata)
183 {
184 unsigned char mdata;
185 double mval;
186
187 set_mixer_reg(0x04, 0xee);
188 set_mixer_reg(0x0a, 0x00);
189 mdata = 0x20;
190 if (ct1345_src_mic->value())
191 mdata = 0x20;
192 else if (ct1345_src_cd->value())
193 mdata = 0x22;
194 else if (ct1345_src_line->value())
195 mdata = 0x26;
196 set_mixer_reg(0x0c, mdata);
197 set_mixer_reg(0x0e, 0x20);
198 mval = ct1345_outl->value() * (7.0 / 46.0);
199 mdata = (((int)(mval))+7) << 5;
200 mval = ct1345_outr->value() * (7.0 / 46.0);
201 mdata |= (((int)(mval))+7) << 1;
202 set_mixer_reg(0x22, mdata);
203 set_mixer_reg(0x26, 0x00);
204 set_mixer_reg(0x28, 0x00);
205 set_mixer_reg(0x2e, 0x00);
206 }
207
208 /* ---------------------------------------------------------------------- */
209
210 void update_ct1745(Fl_Widget *widget, void *udata)
211 {
212 unsigned char mdata;
213 float mval;
214
215 set_mixer_reg(0x3c, 0); /* output src: only voice and pcspk */
216 mval = ct1745_treble->value();
217 set_mixer_reg(0x44, ((int)mval)<<4); /* treble.l */
218 set_mixer_reg(0x45, ((int)mval)<<4); /* treble.r */
219 mval = ct1745_bass->value();
220 set_mixer_reg(0x46, ((int)mval)<<4); /* bass.l */
221 set_mixer_reg(0x47, ((int)mval)<<4); /* bass.r */
222 set_mixer_reg(0x3b, 0); /* PC speaker vol -18dB */
223 set_mixer_reg(0x43, 1); /* mic: agc off, fixed 20dB gain */
224 mval = ct1745_outl->value();
225 mdata = 0;
226 while (mval > 0) {
227 mval -= 6;
228 mdata += 0x40;
229 }
230 set_mixer_reg(0x41, mdata); /* output gain */
231 set_mixer_reg(0x30, 0xf8); /* master vol */
232 set_mixer_reg(0x32, ((int)(mval * 0.5) + 31) << 3); /* voice vol */
233 mval = ct1745_outr->value();
234 mdata = 0;
235 while (mval > 0) {
236 mval -= 6;
237 mdata += 0x40;
238 }
239 set_mixer_reg(0x42, mdata); /* output gain */
240 set_mixer_reg(0x31, 0xf8); /* master vol */
241 set_mixer_reg(0x33, ((int)(mval * 0.5) + 31) << 3); /* voice vol */
242 mval = ct1745_inl->value();
243 mdata = 0;
244 while (mval > 0) {
245 mval -= 6;
246 mdata += 0x40;
247 }
248 set_mixer_reg(0x3f, mdata); /* input gain */
249 mdata = ((int)(mval * 0.5) + 31) << 3;
250 set_mixer_reg(0x34, mdata); /* midi vol */
251 set_mixer_reg(0x36, mdata); /* cd vol */
252 set_mixer_reg(0x38, mdata); /* line vol */
253 set_mixer_reg(0x3a, mdata); /* mic vol */
254 mval = ct1745_inr->value();
255 mdata = 0;
256 while (mval > 0) {
257 mval -= 6;
258 mdata += 0x40;
259 }
260 set_mixer_reg(0x40, mdata); /* input gain */
261 mdata = ((int)(mval * 0.5) + 31) << 3;
262 set_mixer_reg(0x35, mdata); /* midi vol */
263 set_mixer_reg(0x37, mdata); /* cd vol */
264 set_mixer_reg(0x39, mdata); /* line vol */
265 mdata = 0;
266 if (ct1745_srcl_mic->value())
267 mdata |= 0x01;
268 if (ct1745_srcl_cdl->value())
269 mdata |= 0x04;
270 if (ct1745_srcl_cdr->value())
271 mdata |= 0x02;
272 if (ct1745_srcl_linel->value())
273 mdata |= 0x10;
274 if (ct1745_srcl_liner->value())
275 mdata |= 0x08;
276 if (ct1745_srcl_midil->value())
277 mdata |= 0x40;
278 if (ct1745_srcl_midir->value())
279 mdata |= 0x20;
280 set_mixer_reg(0x3d, mdata); /* input sources left */
281 mdata = 0;
282 if (ct1745_srcr_mic->value())
283 mdata |= 0x01;
284 if (ct1745_srcr_cdl->value())
285 mdata |= 0x04;
286 if (ct1745_srcr_cdr->value())
287 mdata |= 0x02;
288 if (ct1745_srcr_linel->value())
289 mdata |= 0x10;
290 if (ct1745_srcr_liner->value())
291 mdata |= 0x08;
292 if (ct1745_srcr_midil->value())
293 mdata |= 0x40;
294 if (ct1745_srcr_midir->value())
295 mdata |= 0x20;
296 set_mixer_reg(0x3e, mdata); /* input sources right*/
297 }
298
299 /* ---------------------------------------------------------------------- */
300
301 void cb_quit(Fl_Button *, long)
302 {
303 exit (0);
304 }
305
306 /* ---------------------------------------------------------------------- */
307
308 static const char *usage_str =
309 "[-i smif]\n"
310 " -i: specify the name of the soundmodem kernel driver interface\n\n";
311
312 /* ---------------------------------------------------------------------- */
313
314 int main(int argc, char *argv[])
315 {
316 int c, i;
317 struct sm_mixer_data mixdat;
318 unsigned char mdata;
319
320 progname = *argv;
321 printf("%s: Version " FULL_VER "; (C) 1996,1997,2000 by Thomas Sailer HB9JNX/AE4WA\n", progname);
322 hdrvc_args(&argc, argv, "sm0");
323 for (i = 1; i < argc; ) {
324 c = i;
325 Fl::arg(argc, argv, c);
326 if (c <= 0) {
327 i++;
328 continue;
329 }
330 memmove(&argv[i], &argv[i+c], (argc-i) * sizeof(char *));
331 argc -= c;
332 }
333 #if 0
334 while ((ret = getopt(argc, argv, "")) != -1) {
335 switch (ret) {
336 default:
337 printf("usage: %s %s", progname, usage_str);
338 exit(-1);
339 }
340 }
341 #endif
342 hdrvc_init();
343 /*
344 * set mixer
345 */
346 mixdat.reg = 0;
347 if (do_mix_ioctl(SMCTL_GETMIXER, &mixdat) < 0) {
348 perror("do_mix_ioctl: SMCTL_GETMIXER");
349 mixdevice = SM_MIXER_INVALID;
350 } else
351 mixdevice = mixdat.mixer_type;
352 switch (mixdevice) {
353 case SM_MIXER_INVALID:
354 printf("invalid mixer device\n");
355 exit(1);
356
357 case SM_MIXER_AD1848:
358 case SM_MIXER_CRYSTAL:
359 printf("Mixer device: %s\n", mixdevice == SM_MIXER_CRYSTAL ?
360 "CS423x" : "AD1848");
361 create_form_ad1848();
362 mdata = get_mixer_reg(0);
363 ad1848_inl->step(1.5);
364 ad1848_inl->bounds(42.5, 0);
365 ad1848_inl->value((((mdata & 0xe0) == 0xa0) ? 20 : 0) + (mdata & 0xf) * 1.5);
366 ad1848_srcl_line->value((mdata & 0xc0) == 0x00);
367 ad1848_srcl_aux1->value((mdata & 0xc0) == 0x40);
368 ad1848_srcl_mic->value((mdata & 0xc0) == 0x80);
369 ad1848_srcl_dac->value((mdata & 0xc0) == 0xc0);
370 mdata = get_mixer_reg(1);
371 ad1848_inr->step(1.5);
372 ad1848_inr->bounds(42.5, 0);
373 ad1848_inr->value((((mdata & 0xe0) == 0xa0) ? 20 : 0) + (mdata & 0xf) * 1.5);
374 ad1848_srcr_line->value((mdata & 0xc0) == 0x00);
375 ad1848_srcr_aux1->value((mdata & 0xc0) == 0x40);
376 ad1848_srcr_mic->value((mdata & 0xc0) == 0x80);
377 ad1848_srcr_dac->value((mdata & 0xc0) == 0xc0);
378 mdata = get_mixer_reg(6);
379 ad1848_outl->step(1.5);
380 ad1848_outl->bounds(0, -100);
381 ad1848_outl->value((mdata & 0x80) ? -100 : (mdata & 0x3f) * -1.5);
382 mdata = get_mixer_reg(7);
383 ad1848_outr->step(1.5);
384 ad1848_outr->bounds(0, -100);
385 ad1848_outr->value((mdata & 0x80) ? -100 : (mdata & 0x3f) * -1.5);
386 mixer_ad1848->show();
387 break;
388
389 case SM_MIXER_CT1335:
390 printf("Mixer device: CT1335\n");
391 create_form_ct1335();
392 mdata = get_mixer_reg(0x2);
393 ct1335_out->step(46.0/7.0);
394 ct1335_out->bounds(0, -46);
395 ct1335_out->value((((int)((mdata >> 1) & 7)) - 7) * (46.0/7.0));
396 mixer_ct1335->show();
397 break;
398
399 case SM_MIXER_CT1345:
400 printf("Mixer device: CT1345\n");
401 create_form_ct1345();
402 mdata = get_mixer_reg(0x22);
403 ct1345_outl->step(46.0/7.0);
404 ct1345_outl->bounds(0, -46);
405 ct1345_outl->value((((int)((mdata >> 5) & 7)) - 7) * (46.0/7.0));
406 ct1345_outr->step(46.0/7.0);
407 ct1345_outr->bounds(0, -46);
408 ct1345_outr->value((((int)((mdata >> 1) & 7)) - 7) * (46.0/7.0));
409 mdata = get_mixer_reg(0xc);
410 ct1345_src_mic->value((mdata & 6) == 0 || (mdata & 6) == 4);
411 ct1345_src_cd->value((mdata & 6) == 2);
412 ct1345_src_line->value((mdata & 6) == 6);
413 mixer_ct1345->show();
414 break;
415
416 case SM_MIXER_CT1745:
417 printf("Mixer device: CT1745\n");
418 create_form_ct1745();
419 ct1745_outl->step(2);
420 ct1745_outl->bounds(0, -62);
421 ct1745_outl->value(((int)((get_mixer_reg(0x32) >> 3) & 0x1f) - 31) * 2 +
422 ((get_mixer_reg(0x41) >> 6) & 0x3) * 6);
423 ct1745_outr->step(2);
424 ct1745_outr->bounds(0, -62);
425 ct1745_outr->value(((int)((get_mixer_reg(0x33) >> 3) & 0x1f) - 31) * 2 +
426 ((get_mixer_reg(0x42) >> 6) & 0x3) * 6);
427 ct1745_inl->step(2);
428 ct1745_inl->bounds(0, -62);
429 ct1745_inl->value(((int)((get_mixer_reg(0x38) >> 3) & 0x1f) - 31) * 2 +
430 ((get_mixer_reg(0x3f) >> 6) & 0x3) * 6);
431 ct1745_inr->step(2);
432 ct1745_inr->bounds(0, -62);
433 ct1745_inr->value(((int)((get_mixer_reg(0x39) >> 3) & 0x1f) - 31) * 2 +
434 ((get_mixer_reg(0x40) >> 6) & 0x3) * 6);
435 mdata = get_mixer_reg(0x3d);
436 ct1745_srcl_mic->value(!!(mdata & 1));
437 ct1745_srcl_cdl->value(!!(mdata & 4));
438 ct1745_srcl_cdr->value(!!(mdata & 2));
439 ct1745_srcl_linel->value(!!(mdata & 0x10));
440 ct1745_srcl_liner->value(!!(mdata & 8));
441 ct1745_srcl_midil->value(!!(mdata & 0x40));
442 ct1745_srcl_midir->value(!!(mdata & 0x20));
443 mdata = get_mixer_reg(0x3e);
444 ct1745_srcr_mic->value(!!(mdata & 1));
445 ct1745_srcr_cdl->value(!!(mdata & 4));
446 ct1745_srcr_cdr->value(!!(mdata & 2));
447 ct1745_srcr_linel->value(!!(mdata & 0x10));
448 ct1745_srcr_liner->value(!!(mdata & 8));
449 ct1745_srcr_midil->value(!!(mdata & 0x40));
450 ct1745_srcr_midir->value(!!(mdata & 0x20));
451 ct1745_treble->step(1);
452 ct1745_treble->bounds(7, -8);
453 ct1745_treble->value((get_mixer_reg(0x44) >> 4) & 0xf);
454 ct1745_bass->step(1);
455 ct1745_bass->bounds(7, -8);
456 ct1745_bass->value((get_mixer_reg(0x46) >> 4) & 0xf);
457 mixer_ct1745->show();
458 break;
459
460 default:
461 printf("unknown mixer device %d\n", mixdevice);
462 exit(1);
463 }
464 Fl::run();
465 exit(0);
466 }