| 1 | /*****************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * smmixer.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 26.06.1996 Started |
| 30 | * 0.2 11.05.1997 introduced hdrvcomm.h |
| 31 | * 0.3 05.01.2000 glibc compile fixes |
| 32 | */ |
| 33 | |
| 34 | /*****************************************************************************/ |
| 35 | |
| 36 | #include <stdlib.h> |
| 37 | #include <stdio.h> |
| 38 | #include <sys/time.h> |
| 39 | #include <sys/types.h> |
| 40 | #include <sys/stat.h> |
| 41 | #include <unistd.h> |
| 42 | #include <string.h> |
| 43 | #include <net/if.h> |
| 44 | #include "hdrvcomm.h" |
| 45 | |
| 46 | #include <config.h> |
| 47 | #include <scm-version.h> |
| 48 | |
| 49 | /* ---------------------------------------------------------------------- */ |
| 50 | |
| 51 | static char *progname; |
| 52 | static unsigned int mixdevice; |
| 53 | |
| 54 | /* ---------------------------------------------------------------------- */ |
| 55 | |
| 56 | static int do_mix_ioctl(int cmd, struct sm_mixer_data *mixdat) |
| 57 | { |
| 58 | struct sm_ioctl par; |
| 59 | int i; |
| 60 | |
| 61 | par.cmd = cmd; |
| 62 | par.data.mix = *mixdat; |
| 63 | i = hdrvc_sm_ioctl(cmd, &par); |
| 64 | *mixdat = par.data.mix; |
| 65 | return i; |
| 66 | } |
| 67 | |
| 68 | /* ---------------------------------------------------------------------- */ |
| 69 | |
| 70 | static unsigned char get_mixer_reg(unsigned char addr) |
| 71 | { |
| 72 | int i; |
| 73 | struct sm_mixer_data mixdat; |
| 74 | |
| 75 | mixdat.reg = addr; |
| 76 | i = do_mix_ioctl(SMCTL_GETMIXER, &mixdat); |
| 77 | if (i < 0) { |
| 78 | perror("do_mix_ioctl: SMCTL_GETMIXER"); |
| 79 | exit(1); |
| 80 | } |
| 81 | if (!i) |
| 82 | fprintf(stderr, "warning: mixer device %u register %u not " |
| 83 | "accessible for reading!\n", mixdat.mixer_type, |
| 84 | addr); |
| 85 | if (mixdat.mixer_type != mixdevice) { |
| 86 | fprintf(stderr, "error: mixer type changed !?\n"); |
| 87 | exit(2); |
| 88 | } |
| 89 | return mixdat.data; |
| 90 | } |
| 91 | |
| 92 | /* ---------------------------------------------------------------------- */ |
| 93 | |
| 94 | static void set_mixer_reg(unsigned char addr, unsigned char data) |
| 95 | { |
| 96 | struct sm_mixer_data mixdat; |
| 97 | |
| 98 | mixdat.reg = addr; |
| 99 | mixdat.data = data; |
| 100 | mixdat.mixer_type = mixdevice; |
| 101 | if (do_mix_ioctl(SMCTL_SETMIXER, &mixdat) < 0) { |
| 102 | perror("do_mix_ioctl: SMCTL_SETMIXER"); |
| 103 | exit(1); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* ---------------------------------------------------------------------- */ |
| 108 | |
| 109 | static void display_mixer_ad1848(void) |
| 110 | { |
| 111 | static const char *src[4] = { "Line", "Aux1", "Mic", "Dac" }; |
| 112 | unsigned char data; |
| 113 | |
| 114 | data = get_mixer_reg(0); |
| 115 | printf("Left input: Source: %-4s Gain: %3ddB\n", src[(data>>6)&3], |
| 116 | (((data & 0xe0) == 0xa0) ? 20 : 0) + (data & 0xf) * 3 / 2); |
| 117 | data = get_mixer_reg(1); |
| 118 | printf("Right input: Source: %-4s Gain: %3ddB\n", src[(data>>6)&3], |
| 119 | (((data & 0xe0) == 0xa0) ? 20 : 0) + (data & 0xf) * 3 / 2); |
| 120 | data = get_mixer_reg(2); |
| 121 | if (!(data & 0x80)) |
| 122 | printf("Left Aux1 mixing: Gain: %3ddB\n", |
| 123 | (8 - (int)(data & 0x1f)) * 3 / 2); |
| 124 | data = get_mixer_reg(3); |
| 125 | if (!(data & 0x80)) |
| 126 | printf("Right Aux1 mixing: Gain: %3ddB\n", |
| 127 | (8 - (int)(data & 0x1f)) * 3 / 2); |
| 128 | data = get_mixer_reg(4); |
| 129 | if (!(data & 0x80)) |
| 130 | printf("Left Aux2 mixing: Gain: %3ddB\n", |
| 131 | (8 - (int)(data & 0x1f)) * 3 / 2); |
| 132 | data = get_mixer_reg(5); |
| 133 | if (!(data & 0x80)) |
| 134 | printf("Right Aux2 mixing: Gain: %3ddB\n", |
| 135 | (8 - (int)(data & 0x1f)) * 3 / 2); |
| 136 | data = get_mixer_reg(6); |
| 137 | if (data & 0x80) |
| 138 | printf("Left output: muted\n"); |
| 139 | else |
| 140 | printf("Left output: Gain: %3ddB\n", |
| 141 | ((int)(data & 0x3f)) * (-3) / 2); |
| 142 | data = get_mixer_reg(7); |
| 143 | if (data & 0x80) |
| 144 | printf("Right output: muted\n"); |
| 145 | else |
| 146 | printf("Right output: Gain: %3ddB\n", |
| 147 | ((int)(data & 0x3f)) * (-3) / 2); |
| 148 | data = get_mixer_reg(13); |
| 149 | if (data & 1) |
| 150 | printf("Digital mix: Gain: %3ddB\n", |
| 151 | ((int)((data >> 2) & 0x3f)) * (-3) / 2); |
| 152 | } |
| 153 | |
| 154 | /* ---------------------------------------------------------------------- */ |
| 155 | |
| 156 | static void display_mixer_cs423x(void) |
| 157 | { |
| 158 | unsigned char data; |
| 159 | |
| 160 | display_mixer_ad1848(); |
| 161 | data = get_mixer_reg(26); |
| 162 | printf("Mono: %s%s%s Gain: %3ddB\n", |
| 163 | (data & 0x80) ? "input muted, " : "", |
| 164 | (data & 0x40) ? "output muted, " : "", |
| 165 | (data & 0x20) ? "bypass, " : "", |
| 166 | (int)(data & 0xf) * (-3)); |
| 167 | data = get_mixer_reg(27); |
| 168 | if (data & 0x80) |
| 169 | printf("Left output: muted\n"); |
| 170 | else |
| 171 | printf("Left output: Gain: %3ddB\n", |
| 172 | ((int)(data & 0xf)) * (-2)); |
| 173 | data = get_mixer_reg(29); |
| 174 | if (data & 0x80) |
| 175 | printf("Right output: muted\n"); |
| 176 | else |
| 177 | printf("Right output: Gain: %3ddB\n", |
| 178 | ((int)(data & 0xf)) * (-2)); |
| 179 | |
| 180 | } |
| 181 | |
| 182 | /* ---------------------------------------------------------------------- */ |
| 183 | |
| 184 | static void display_mixer_ct1335(void) |
| 185 | { |
| 186 | unsigned char data; |
| 187 | |
| 188 | data = get_mixer_reg(0x2); |
| 189 | printf("Master volume: %3ddB\n", |
| 190 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 191 | data = get_mixer_reg(0xa); |
| 192 | printf("Voice volume: %3ddB\n", |
| 193 | (((int)((data >> 1) & 3)) - 3) * 46 / 3); |
| 194 | data = get_mixer_reg(0x6); |
| 195 | printf("MIDI volume: %3ddB\n", |
| 196 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 197 | data = get_mixer_reg(0x8); |
| 198 | printf("CD volume: %3ddB\n", |
| 199 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 200 | } |
| 201 | |
| 202 | /* ---------------------------------------------------------------------- */ |
| 203 | |
| 204 | static void display_mixer_ct1345(void) |
| 205 | { |
| 206 | static const char *src[4] = { "Mic", "CD", "Mic", "Line" }; |
| 207 | unsigned char data, data2; |
| 208 | |
| 209 | data = get_mixer_reg(0xc); |
| 210 | data2 = get_mixer_reg(0xe); |
| 211 | printf("Input source: %s\n", src[(data >> 1) & 3]); |
| 212 | if (!(data & data2 & 0x20)) { |
| 213 | printf("Filter: Low pass %s kHz: ", (data & 0x8) ? |
| 214 | "8.8" : "3.2"); |
| 215 | if (data & 0x20) |
| 216 | printf("output\n"); |
| 217 | else |
| 218 | printf("input%s\n", (data2 & 0x20) ? "" : ", output"); |
| 219 | } |
| 220 | if (data2 & 2) |
| 221 | printf("stereo\n"); |
| 222 | |
| 223 | data = get_mixer_reg(0x22); |
| 224 | printf("Master volume: Left: %3ddB Right: %3ddB\n", |
| 225 | (((int)((data >> 5) & 7)) - 7) * 46 / 7, |
| 226 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 227 | data = get_mixer_reg(0x4); |
| 228 | printf("Voice volume: Left: %3ddB Right: %3ddB\n", |
| 229 | (((int)((data >> 5) & 7)) - 7) * 46 / 7, |
| 230 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 231 | data = get_mixer_reg(0x26); |
| 232 | printf("MIDI volume: Left: %3ddB Right: %3ddB\n", |
| 233 | (((int)((data >> 5) & 7)) - 7) * 46 / 7, |
| 234 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 235 | data = get_mixer_reg(0x28); |
| 236 | printf("CD volume: Left: %3ddB Right: %3ddB\n", |
| 237 | (((int)((data >> 5) & 7)) - 7) * 46 / 7, |
| 238 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 239 | data = get_mixer_reg(0x2e); |
| 240 | printf("Line volume: Left: %3ddB Right: %3ddB\n", |
| 241 | (((int)((data >> 5) & 7)) - 7) * 46 / 7, |
| 242 | (((int)((data >> 1) & 7)) - 7) * 46 / 7); |
| 243 | data = get_mixer_reg(0x0a); |
| 244 | printf("Mic mixing volume: %3ddB\n", |
| 245 | (((int)((data >> 1) & 3)) - 3) * 46 / 3); |
| 246 | } |
| 247 | |
| 248 | /* ---------------------------------------------------------------------- */ |
| 249 | |
| 250 | static void display_mixer_ct1745(void) |
| 251 | { |
| 252 | unsigned char data, data2; |
| 253 | |
| 254 | printf("Master volume: Left: %3ddB Right: %3ddB\n", |
| 255 | ((int)((get_mixer_reg(0x30) >> 3) & 0x1f) - 31) * 2, |
| 256 | ((int)((get_mixer_reg(0x31) >> 3) & 0x1f) - 31) * 2); |
| 257 | printf("Voice volume: Left: %3ddB Right: %3ddB\n", |
| 258 | ((int)((get_mixer_reg(0x32) >> 3) & 0x1f) - 31) * 2, |
| 259 | ((int)((get_mixer_reg(0x33) >> 3) & 0x1f) - 31) * 2); |
| 260 | printf("MIDI volume: Left: %3ddB Right: %3ddB\n", |
| 261 | ((int)((get_mixer_reg(0x34) >> 3) & 0x1f) - 31) * 2, |
| 262 | ((int)((get_mixer_reg(0x35) >> 3) & 0x1f) - 31) * 2); |
| 263 | printf("CD volume: Left: %3ddB Right: %3ddB\n", |
| 264 | ((int)((get_mixer_reg(0x36) >> 3) & 0x1f) - 31) * 2, |
| 265 | ((int)((get_mixer_reg(0x37) >> 3) & 0x1f) - 31) * 2); |
| 266 | printf("Line volume: Left: %3ddB Right: %3ddB\n", |
| 267 | ((int)((get_mixer_reg(0x38) >> 3) & 0x1f) - 31) * 2, |
| 268 | ((int)((get_mixer_reg(0x39) >> 3) & 0x1f) - 31) * 2); |
| 269 | printf("Mic volume: %3ddB\n", |
| 270 | ((int)((get_mixer_reg(0x3a) >> 3) & 0x1f) - 31) * 2); |
| 271 | printf("PC speaker volume: %3ddB\n", |
| 272 | ((int)((get_mixer_reg(0x3b) >> 6) & 0x3) - 3) * 6); |
| 273 | printf("Mic gain: %s\n", |
| 274 | (get_mixer_reg(0x43) & 1) ? "fixed 20dB" : "AGC"); |
| 275 | printf("Output gain: Left: %3ddB Right: %3ddB\n", |
| 276 | ((int)((get_mixer_reg(0x41) >> 6) & 3)) * 6, |
| 277 | ((int)((get_mixer_reg(0x42) >> 6) & 3)) * 6); |
| 278 | printf("Input gain: Left: %3ddB Right: %3ddB\n", |
| 279 | ((int)((get_mixer_reg(0x3f) >> 6) & 3)) * 6, |
| 280 | ((int)((get_mixer_reg(0x40) >> 6) & 3)) * 6); |
| 281 | data = (get_mixer_reg(0x44) >> 4) & 0xf; |
| 282 | if (data > 7) |
| 283 | data--; |
| 284 | data2 = (get_mixer_reg(0x45) >> 4) & 0xf; |
| 285 | if (data2 > 7) |
| 286 | data2--; |
| 287 | printf("Treble: Left: %3ddB Right: %3ddB\n", |
| 288 | ((int)data - 7) * 2, ((int)data2 - 7) * 2); |
| 289 | data = (get_mixer_reg(0x46) >> 4) & 0xf; |
| 290 | if (data > 7) |
| 291 | data--; |
| 292 | data2 = (get_mixer_reg(0x47) >> 4) & 0xf; |
| 293 | if (data2 > 7) |
| 294 | data2--; |
| 295 | printf("Bass: Left: %3ddB Right: %3ddB\n", |
| 296 | ((int)data - 7) * 2, ((int)data2 - 7) * 2); |
| 297 | data = get_mixer_reg(0x3c); |
| 298 | printf("Output sources left: PCSpeaker Voice.L%s%s%s\n", |
| 299 | (data & 1) ? " Mic" : "", (data & 4) ? " CD.L" : "", |
| 300 | (data & 0x10) ? " Line.L" : ""); |
| 301 | printf("Output sources right: PCSpeaker Voice.R%s%s%s\n", |
| 302 | (data & 1) ? " Mic" : "", (data & 2) ? " CD.R" : "", |
| 303 | (data & 8) ? " Line.R" : ""); |
| 304 | data = get_mixer_reg(0x3d); |
| 305 | printf("Input sources left: %s%s%s%s%s%s%s\n", |
| 306 | (data & 1) ? " Mic" : "", (data & 2) ? " CD.R" : "", |
| 307 | (data & 4) ? " CD.L" : "", (data & 8) ? " Line.R" : "", |
| 308 | (data & 0x10) ? " Line.L" : "", (data & 0x20) ? " Midi.R" : "", |
| 309 | (data & 0x40) ? " Midi.L" : ""); |
| 310 | data = get_mixer_reg(0x3e); |
| 311 | printf("Input sources right: %s%s%s%s%s%s%s\n", |
| 312 | (data & 1) ? " Mic" : "", (data & 2) ? " CD.R" : "", |
| 313 | (data & 4) ? " CD.L" : "", (data & 8) ? " Line.R" : "", |
| 314 | (data & 0x10) ? " Line.L" : "", (data & 0x20) ? " Midi.R" : "", |
| 315 | (data & 0x40) ? " Midi.L" : ""); |
| 316 | } |
| 317 | |
| 318 | /* ---------------------------------------------------------------------- */ |
| 319 | |
| 320 | static int parse_ad_src(const char *cp) |
| 321 | { |
| 322 | if (!strcasecmp(cp, "line")) |
| 323 | return 0; |
| 324 | if (!strcasecmp(cp, "aux1")) |
| 325 | return 1; |
| 326 | if (!strcasecmp(cp, "mic")) |
| 327 | return 2; |
| 328 | if (!strcasecmp(cp, "dac")) |
| 329 | return 3; |
| 330 | return -1; |
| 331 | } |
| 332 | |
| 333 | /* ---------------------------------------------------------------------- */ |
| 334 | |
| 335 | static int set_mixer_ad1848(int argc, char *argv[]) |
| 336 | { |
| 337 | unsigned int mask = 0; |
| 338 | int olvll = 0, olvlr = 0; |
| 339 | int isrcl = 0, isrcr = 0; |
| 340 | int ilvll = 0, ilvlr = 0; |
| 341 | unsigned int data; |
| 342 | |
| 343 | for (; argc >= 1; argc--, argv++) { |
| 344 | if (!strncasecmp(argv[0], "ol=", 3)) { |
| 345 | olvll = strtol(argv[0]+3, NULL, 0); |
| 346 | mask |= 1; |
| 347 | if (olvll < -46 || olvll > 0) { |
| 348 | fprintf(stderr, "output level out of range " |
| 349 | "-100..0dB\n"); |
| 350 | return -1; |
| 351 | } |
| 352 | } else if (!strncasecmp(argv[0], "or=", 3)) { |
| 353 | olvlr = strtol(argv[0]+3, NULL, 0); |
| 354 | mask |= 2; |
| 355 | if (olvlr < -46 || olvlr > 0) { |
| 356 | fprintf(stderr, "output level out of range " |
| 357 | "-100..0dB\n"); |
| 358 | return -1; |
| 359 | } |
| 360 | } else if (!strncasecmp(argv[0], "o=", 2)) { |
| 361 | olvll = olvlr = strtol(argv[0]+2, NULL, 0); |
| 362 | mask |= 3; |
| 363 | if (olvll < -46 || olvll > 0) { |
| 364 | fprintf(stderr, "output level out of range " |
| 365 | "-100..0dB\n"); |
| 366 | return -1; |
| 367 | } |
| 368 | } else if (!strncasecmp(argv[0], "il=", 3)) { |
| 369 | ilvll = strtol(argv[0]+3, NULL, 0); |
| 370 | mask |= 4; |
| 371 | if (ilvll < 0 || ilvll > 43) { |
| 372 | fprintf(stderr, "input gain out of range " |
| 373 | "0..43dB\n"); |
| 374 | return -1; |
| 375 | } |
| 376 | } else if (!strncasecmp(argv[0], "ir=", 3)) { |
| 377 | ilvlr = strtol(argv[0]+3, NULL, 0); |
| 378 | mask |= 8; |
| 379 | if (ilvll < 0 || ilvll > 43) { |
| 380 | fprintf(stderr, "input gain out of range " |
| 381 | "0..43dB\n"); |
| 382 | return -1; |
| 383 | } |
| 384 | } else if (!strncasecmp(argv[0], "i=", 2)) { |
| 385 | ilvll = ilvlr = strtol(argv[0]+2, NULL, 0); |
| 386 | mask |= 12; |
| 387 | if (ilvll < 0 || ilvll > 43) { |
| 388 | fprintf(stderr, "input gain out of range " |
| 389 | "0..43dB\n"); |
| 390 | return -1; |
| 391 | } |
| 392 | } else if (!strncasecmp(argv[0], "sl=", 3)) { |
| 393 | mask |= 16; |
| 394 | isrcl = parse_ad_src(argv[0] + 3); |
| 395 | if (isrcl < 0) { |
| 396 | fprintf(stderr, "invalid input source, must " |
| 397 | "be either line, aux1, mic or dac\n"); |
| 398 | return -1; |
| 399 | } |
| 400 | } else if (!strncasecmp(argv[0], "sr=", 3)) { |
| 401 | mask |= 32; |
| 402 | isrcr = parse_ad_src(argv[0] + 3); |
| 403 | if (isrcr < 0) { |
| 404 | fprintf(stderr, "invalid input source, must " |
| 405 | "be either line, aux1, mic or dac\n"); |
| 406 | return -1; |
| 407 | } |
| 408 | } else if (!strncasecmp(argv[0], "s=", 2)) { |
| 409 | mask |= 48; |
| 410 | isrcl = isrcr = parse_ad_src(argv[0] + 2); |
| 411 | if (isrcl < 0) { |
| 412 | fprintf(stderr, "invalid input source, must " |
| 413 | "be either line, aux1, mic or dac\n"); |
| 414 | return -1; |
| 415 | } |
| 416 | } else { |
| 417 | fprintf(stderr, "invalid parameter \"%s\"\n", argv[0]); |
| 418 | return -1; |
| 419 | } |
| 420 | } |
| 421 | data = get_mixer_reg(0x00); |
| 422 | if (mask & 4) { |
| 423 | data &= 0xc0; |
| 424 | if (ilvll > 23) { |
| 425 | data |= 0x20; |
| 426 | ilvll -= 20; |
| 427 | } |
| 428 | data |= ilvll * 2 / 3; |
| 429 | } |
| 430 | if (mask & 16) |
| 431 | data = (data & 0x3f) | (isrcl << 6); |
| 432 | if ((data & 0xc0) != 0x80) |
| 433 | data &= ~0x20; |
| 434 | set_mixer_reg(0x00, data); |
| 435 | data = get_mixer_reg(0x01); |
| 436 | if (mask & 8) { |
| 437 | data &= 0xc0; |
| 438 | if (ilvlr > 23) { |
| 439 | data |= 0x20; |
| 440 | ilvlr -= 20; |
| 441 | } |
| 442 | data |= ilvlr * 2 / 3; |
| 443 | } |
| 444 | if (mask & 32) |
| 445 | data = (data & 0x3f) | (isrcr << 6); |
| 446 | if ((data & 0xc0) != 0x80) |
| 447 | data &= ~0x20; |
| 448 | set_mixer_reg(0x01, data); |
| 449 | set_mixer_reg(0x02, 0x80); |
| 450 | set_mixer_reg(0x03, 0x80); |
| 451 | set_mixer_reg(0x04, 0x80); |
| 452 | set_mixer_reg(0x05, 0x80); |
| 453 | if (mask & 1) { |
| 454 | if (olvll < -95) |
| 455 | set_mixer_reg(0x06, 0x80); |
| 456 | else |
| 457 | set_mixer_reg(0x06, (olvll * (-2) / 3)); |
| 458 | } |
| 459 | if (mask & 2) { |
| 460 | if (olvlr < -95) |
| 461 | set_mixer_reg(0x07, 0x80); |
| 462 | else |
| 463 | set_mixer_reg(0x07, (olvlr * (-2) / 3)); |
| 464 | } |
| 465 | set_mixer_reg(0x0d, 0x00); |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | /* ---------------------------------------------------------------------- */ |
| 470 | |
| 471 | static int set_mixer_ct1335(int argc, char *argv[]) |
| 472 | { |
| 473 | unsigned int mask = 0; |
| 474 | int olvl = 0; |
| 475 | |
| 476 | for (; argc >= 1; argc--, argv++) { |
| 477 | if (!strncasecmp(argv[0], "o=", 2)) { |
| 478 | olvl = strtol(argv[0]+2, NULL, 0); |
| 479 | mask |= 1; |
| 480 | if (olvl < -46 || olvl > 0) { |
| 481 | fprintf(stderr, "output level out of range " |
| 482 | "-46..0dB\n"); |
| 483 | return -1; |
| 484 | } |
| 485 | } else { |
| 486 | fprintf(stderr, "invalid parameter \"%s\"\n", argv[0]); |
| 487 | return -1; |
| 488 | } |
| 489 | } |
| 490 | if (mask & 1) |
| 491 | set_mixer_reg(0x02, (((olvl * 7 / 46) + 7) << 1)); |
| 492 | set_mixer_reg(0x06, 0x00); |
| 493 | set_mixer_reg(0x08, 0x00); |
| 494 | set_mixer_reg(0x0a, 0x06); |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* ---------------------------------------------------------------------- */ |
| 499 | |
| 500 | static int set_mixer_ct1345(int argc, char *argv[]) |
| 501 | { |
| 502 | unsigned int mask = 0; |
| 503 | int olvll = 0, olvlr = 0; |
| 504 | int isrc = 0; |
| 505 | unsigned int data; |
| 506 | |
| 507 | for (; argc >= 1; argc--, argv++) { |
| 508 | if (!strncasecmp(argv[0], "ol=", 3)) { |
| 509 | olvll = strtol(argv[0]+3, NULL, 0); |
| 510 | mask |= 1; |
| 511 | if (olvll < -46 || olvll > 0) { |
| 512 | fprintf(stderr, "output level out of range " |
| 513 | "-46..0dB\n"); |
| 514 | return -1; |
| 515 | } |
| 516 | } else if (!strncasecmp(argv[0], "or=", 3)) { |
| 517 | olvlr = strtol(argv[0]+3, NULL, 0); |
| 518 | mask |= 2; |
| 519 | if (olvlr < -46 || olvlr > 0) { |
| 520 | fprintf(stderr, "output level out of range " |
| 521 | "-46..0dB\n"); |
| 522 | return -1; |
| 523 | } |
| 524 | } else if (!strncasecmp(argv[0], "o=", 2)) { |
| 525 | olvll = olvlr = strtol(argv[0]+2, NULL, 0); |
| 526 | mask |= 3; |
| 527 | if (olvll < -46 || olvll > 0) { |
| 528 | fprintf(stderr, "output level out of range " |
| 529 | "-46..0dB\n"); |
| 530 | return -1; |
| 531 | } |
| 532 | } else if (!strncasecmp(argv[0], "s=", 2)) { |
| 533 | mask |= 4; |
| 534 | if (!strcasecmp(argv[0]+2, "mic")) |
| 535 | isrc = 0; |
| 536 | else if (!strcasecmp(argv[0]+2, "cd")) |
| 537 | isrc = 1; |
| 538 | else if (!strcasecmp(argv[0]+2, "line")) |
| 539 | isrc = 3; |
| 540 | else { |
| 541 | fprintf(stderr, "invalid input source, must " |
| 542 | "be either mic, cd or line\n"); |
| 543 | return -1; |
| 544 | } |
| 545 | } else { |
| 546 | fprintf(stderr, "invalid parameter \"%s\"\n", argv[0]); |
| 547 | return -1; |
| 548 | } |
| 549 | } |
| 550 | set_mixer_reg(0x04, 0xee); |
| 551 | set_mixer_reg(0x0a, 0x00); |
| 552 | if (mask & 4) |
| 553 | data = (isrc & 3) << 1; |
| 554 | else |
| 555 | data = get_mixer_reg(0x0c) & 0x06; |
| 556 | set_mixer_reg(0x0c, data | 0x20); |
| 557 | set_mixer_reg(0x0e, 0x20); |
| 558 | data = get_mixer_reg(0x22); |
| 559 | if (mask & 1) |
| 560 | data = (data & 0x0f) | (((olvll * 7 / 46) + 7) << 5); |
| 561 | if (mask & 2) |
| 562 | data = (data & 0xf0) | (((olvlr * 7 / 46) + 7) << 1); |
| 563 | set_mixer_reg(0x22, data); |
| 564 | set_mixer_reg(0x26, 0x00); |
| 565 | set_mixer_reg(0x28, 0x00); |
| 566 | set_mixer_reg(0x2e, 0x00); |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | /* ---------------------------------------------------------------------- */ |
| 571 | |
| 572 | static int set_mixer_ct1745(int argc, char *argv[]) |
| 573 | { |
| 574 | unsigned int mask = 0; |
| 575 | int olvll = 0, olvlr = 0; |
| 576 | int ilvll = 0, ilvlr = 0; |
| 577 | unsigned int insrc = 0; |
| 578 | unsigned int data; |
| 579 | |
| 580 | for (; argc >= 1; argc--, argv++) { |
| 581 | if (!strncasecmp(argv[0], "ol=", 3)) { |
| 582 | olvll = strtol(argv[0]+3, NULL, 0); |
| 583 | mask |= 1; |
| 584 | if (olvll < -62 || olvll > 18) { |
| 585 | fprintf(stderr, "output level out of range " |
| 586 | "-62..18dB\n"); |
| 587 | return -1; |
| 588 | } |
| 589 | } else if (!strncasecmp(argv[0], "or=", 3)) { |
| 590 | olvlr = strtol(argv[0]+3, NULL, 0); |
| 591 | mask |= 2; |
| 592 | if (olvlr < -62 || olvlr > 18) { |
| 593 | fprintf(stderr, "output level out of range " |
| 594 | "-62..18dB\n"); |
| 595 | return -1; |
| 596 | } |
| 597 | } else if (!strncasecmp(argv[0], "o=", 2)) { |
| 598 | olvll = olvlr = strtol(argv[0]+2, NULL, 0); |
| 599 | mask |= 3; |
| 600 | if (olvll < -62 || olvll > 18) { |
| 601 | fprintf(stderr, "output level out of range " |
| 602 | "-62..18dB\n"); |
| 603 | return -1; |
| 604 | } |
| 605 | } else if (!strncasecmp(argv[0], "il=", 3)) { |
| 606 | ilvll = strtol(argv[0]+3, NULL, 0); |
| 607 | mask |= 4; |
| 608 | if (ilvll < -62 || ilvll > 18) { |
| 609 | fprintf(stderr, "input gain out of range " |
| 610 | "-62..18dB\n"); |
| 611 | return -1; |
| 612 | } |
| 613 | } else if (!strncasecmp(argv[0], "ir=", 3)) { |
| 614 | ilvlr = strtol(argv[0]+3, NULL, 0); |
| 615 | mask |= 8; |
| 616 | if (ilvll < -62 || ilvll > 18) { |
| 617 | fprintf(stderr, "input gain out of range " |
| 618 | "-62..18dB\n"); |
| 619 | return -1; |
| 620 | } |
| 621 | } else if (!strncasecmp(argv[0], "i=", 2)) { |
| 622 | ilvll = ilvlr = strtol(argv[0]+2, NULL, 0); |
| 623 | mask |= 12; |
| 624 | if (ilvll < -62 || ilvll > 18) { |
| 625 | fprintf(stderr, "input gain out of range " |
| 626 | "-62..18dB\n"); |
| 627 | return -1; |
| 628 | } |
| 629 | } else if (!strncasecmp(argv[0], "s=", 2)) { |
| 630 | mask |= 16; |
| 631 | if (!strcasecmp(argv[0]+2, "mic")) |
| 632 | insrc |= 1; |
| 633 | else if (!strcasecmp(argv[0]+2, "cd.r")) |
| 634 | insrc |= 2; |
| 635 | else if (!strcasecmp(argv[0]+2, "cd.l")) |
| 636 | insrc |= 4; |
| 637 | else if (!strcasecmp(argv[0]+2, "cd")) |
| 638 | insrc |= 6; |
| 639 | else if (!strcasecmp(argv[0]+2, "line.r")) |
| 640 | insrc |= 0x08; |
| 641 | else if (!strcasecmp(argv[0]+2, "line.l")) |
| 642 | insrc |= 0x10; |
| 643 | else if (!strcasecmp(argv[0]+2, "line")) |
| 644 | insrc |= 0x18; |
| 645 | else if (!strcasecmp(argv[0]+2, "midi.r")) |
| 646 | insrc |= 0x20; |
| 647 | else if (!strcasecmp(argv[0]+2, "midi.l")) |
| 648 | insrc |= 0x40; |
| 649 | else if (!strcasecmp(argv[0]+2, "midi")) |
| 650 | insrc |= 0x60; |
| 651 | else { |
| 652 | fprintf(stderr, "invalid input source, must " |
| 653 | "be either line, cd, mic or midi\n"); |
| 654 | return -1; |
| 655 | } |
| 656 | } else { |
| 657 | fprintf(stderr, "invalid parameter \"%s\"\n", argv[0]); |
| 658 | return -1; |
| 659 | } |
| 660 | } |
| 661 | if (mask & 3) { |
| 662 | set_mixer_reg(0x3c, 0); /* output src: only voice and pcspk */ |
| 663 | set_mixer_reg(0x44, 4<<4); /* treble.l: -6dB */ |
| 664 | set_mixer_reg(0x45, 4<<4); /* treble.r: -6dB */ |
| 665 | set_mixer_reg(0x46, 6<<4); /* bass.l: -2dB */ |
| 666 | set_mixer_reg(0x47, 6<<4); /* bass.r: -2dB */ |
| 667 | set_mixer_reg(0x3b, 0); /* PC speaker vol -18dB */ |
| 668 | } |
| 669 | if (mask & 12) |
| 670 | set_mixer_reg(0x43, 1); /* mic: agc off, fixed 20dB gain */ |
| 671 | if (mask & 1) { |
| 672 | data = 0; |
| 673 | while (olvll > 0) { |
| 674 | olvll -= 6; |
| 675 | data += 0x40; |
| 676 | } |
| 677 | set_mixer_reg(0x41, data); /* output gain */ |
| 678 | set_mixer_reg(0x30, 0xf8); /* master vol */ |
| 679 | set_mixer_reg(0x32, (olvll / 2 + 31) << 3); /* voice vol */ |
| 680 | } |
| 681 | if (mask & 2) { |
| 682 | data = 0; |
| 683 | while (olvlr > 0) { |
| 684 | olvlr -= 6; |
| 685 | data += 0x40; |
| 686 | } |
| 687 | set_mixer_reg(0x42, data); /* output gain */ |
| 688 | set_mixer_reg(0x31, 0xf8); /* master vol */ |
| 689 | set_mixer_reg(0x33, (olvlr / 2 + 31) << 3); /* voice vol */ |
| 690 | } |
| 691 | if (mask & 4) { |
| 692 | data = 0; |
| 693 | while (ilvll > 0) { |
| 694 | ilvll -= 6; |
| 695 | data += 0x40; |
| 696 | } |
| 697 | set_mixer_reg(0x3f, data); /* input gain */ |
| 698 | data = (ilvll / 2 + 31) << 3; |
| 699 | set_mixer_reg(0x34, data); /* midi vol */ |
| 700 | set_mixer_reg(0x36, data); /* cd vol */ |
| 701 | set_mixer_reg(0x38, data); /* line vol */ |
| 702 | set_mixer_reg(0x3a, data); /* mic vol */ |
| 703 | } |
| 704 | if (mask & 8) { |
| 705 | data = 0; |
| 706 | while (ilvlr > 0) { |
| 707 | ilvlr -= 6; |
| 708 | data += 0x40; |
| 709 | } |
| 710 | set_mixer_reg(0x40, data); /* input gain */ |
| 711 | data = (ilvlr / 2 + 31) << 3; |
| 712 | set_mixer_reg(0x35, data); /* midi vol */ |
| 713 | set_mixer_reg(0x37, data); /* cd vol */ |
| 714 | set_mixer_reg(0x39, data); /* line vol */ |
| 715 | set_mixer_reg(0x3a, data); /* mic vol */ |
| 716 | } |
| 717 | if (mask & 16) { |
| 718 | set_mixer_reg(0x3d, insrc); /* input sources */ |
| 719 | set_mixer_reg(0x3e, insrc); /* input sources */ |
| 720 | } |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | /* ---------------------------------------------------------------------- */ |
| 725 | |
| 726 | static const char *usage_str = |
| 727 | "[-i smif]\n\n"; |
| 728 | |
| 729 | int main(int argc, char *argv[]) |
| 730 | { |
| 731 | int c; |
| 732 | struct sm_mixer_data mixdat; |
| 733 | |
| 734 | progname = *argv; |
| 735 | printf("%s: Version " FULL_VER "; (C) 1996-1997 by Thomas Sailer HB9JNX/AE4WA\n", *argv); |
| 736 | hdrvc_args(&argc, argv, "sm0"); |
| 737 | while ((c = getopt(argc, argv, "")) != -1) { |
| 738 | switch (c) { |
| 739 | default: |
| 740 | printf("usage: %s %s", *argv, usage_str); |
| 741 | exit(-1); |
| 742 | } |
| 743 | } |
| 744 | hdrvc_init(); |
| 745 | mixdat.reg = 0; |
| 746 | if (do_mix_ioctl(SMCTL_GETMIXER, &mixdat) < 0) { |
| 747 | perror("do_mix_ioctl: SMCTL_GETMIXER"); |
| 748 | exit(1); |
| 749 | } |
| 750 | mixdevice = mixdat.mixer_type; |
| 751 | switch (mixdevice) { |
| 752 | case SM_MIXER_INVALID: |
| 753 | printf("invalid mixer device\n"); |
| 754 | exit(1); |
| 755 | case SM_MIXER_AD1848: |
| 756 | if (optind < argc) |
| 757 | set_mixer_ad1848(argc - optind, argv + optind); |
| 758 | display_mixer_ad1848(); |
| 759 | break; |
| 760 | case SM_MIXER_CRYSTAL: |
| 761 | if (optind < argc) |
| 762 | set_mixer_ad1848(argc - optind, argv + optind); |
| 763 | display_mixer_cs423x(); |
| 764 | break; |
| 765 | case SM_MIXER_CT1335: |
| 766 | if (optind < argc) |
| 767 | set_mixer_ct1335(argc - optind, argv + optind); |
| 768 | display_mixer_ct1335(); |
| 769 | break; |
| 770 | case SM_MIXER_CT1345: |
| 771 | if (optind < argc) |
| 772 | set_mixer_ct1345(argc - optind, argv + optind); |
| 773 | display_mixer_ct1345(); |
| 774 | break; |
| 775 | case SM_MIXER_CT1745: |
| 776 | if (optind < argc) |
| 777 | set_mixer_ct1745(argc - optind, argv + optind); |
| 778 | display_mixer_ct1745(); |
| 779 | break; |
| 780 | default: |
| 781 | printf("unknown mixer device %d\n", mixdevice); |
| 782 | exit(1); |
| 783 | } |
| 784 | exit(0); |
| 785 | } |
| 786 | |
| 787 | /* ---------------------------------------------------------------------- */ |