$NetBSD: patch-ac,v 1.3 2007/02/16 14:54:16 joerg Exp $ --- cmp3volume.c.orig 2001-07-01 04:38:08.000000000 +0000 +++ cmp3volume.c @@ -3,8 +3,8 @@ */ #include "cmp3funcs.h" -#if defined(__FreeBSD__) -#include +#if defined(__NetBSD__) +#include #else #include #endif @@ -16,6 +16,63 @@ static int mixernum, * Initialize volume control * Returns: nothing ****************************************************************************/ +#if defined(__NetBSD__) + +int device_id; +mixer_ctrl_t *m, *values; + +extern void initvol() +{ + int i, ndev; + char *mixer_device; + mixer_devinfo_t dinfo, *infos; + + mixer_device = getenv("MIXERDEVICE"); + if (mixer_device == NULL) + mixer_device = "/dev/mixer0"; + + if ((mixernum=open(mixer_device, O_RDWR)) < 0) { + fprintf(stderr, "open mixer device: %s", strerror(errno)); + enditall(SIGSEGV); + } + + for (ndev = 0; ; ndev++) { + dinfo.index = ndev; + if (ioctl(mixernum, AUDIO_MIXER_DEVINFO, &dinfo) < 0) + break; + } + infos = calloc(ndev, sizeof *infos); + values = calloc(ndev, sizeof *values); + + for (i = 0; i < ndev; i++) { + infos[i].index = i; + ioctl(mixernum, AUDIO_MIXER_DEVINFO, &infos[i]); + } + + for (i = 0; i < ndev; i++) { + if (infos[i].type == AUDIO_MIXER_VALUE) { + values[i].dev = i; + values[i].type = infos[i].type; + } + if (strcmp(infos[i].label.name, AudioNdac) == 0) { + device_id = i; + break; + } + } + + values[device_id].un.value.num_channels = 2; + + m = &values[device_id]; + ioctl(mixernum, AUDIO_MIXER_READ, m); + vol = m->un.value.level[0] * 100 / AUDIO_MAX_GAIN; + mvprintw(3,COLS/2-1,"-"); + mvprintw(LINES-7,COLS/2-1,"-"); + mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1,"*"); + return; +} + +#else + extern void initvol() { if ((mixernum=open("/dev/mixer", O_RDWR)) < 0) { @@ -30,6 +87,8 @@ extern void initvol() return; } +#endif + extern void endvol() { close(mixernum); @@ -61,6 +120,23 @@ extern void volclean() * Although I hate users in general, we should probably do it. * Returns: nothing ****************************************************************************/ +#if defined(__NetBSD__) + +extern void volup() +{ + mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," "); + vol += 3; + if (vol > 100) + vol = 100; + m = &values[device_id]; + ioctl(mixernum, AUDIO_MIXER_WRITE, m); + m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100; + mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*"); + return; +} + +#else + extern void volup() { int i; @@ -75,10 +151,29 @@ extern void volup() return; } +#endif + /**************************************************************************** * It's too loud junior, turn it down! * Returns: nothing ****************************************************************************/ +#if defined(__NetBSD__) + +extern void voldown() +{ + mvprintw((LINES-8)-(vol*(LINES-12)/100),COLS/2-1," "); + vol -= 3; + if (vol < 0) + vol = 0; + m = &values[device_id]; + ioctl(mixernum, AUDIO_MIXER_WRITE, m); + m->un.value.level[0] = m->un.value.level[1] = vol * AUDIO_MAX_GAIN / 100; + mvprintw((LINES-8)-(vol*(LINES-12)/100), COLS/2-1, "*"); + return; +} + +#else + extern void voldown() { int i; @@ -93,4 +188,6 @@ extern void voldown() return; } +#endif + /* EOF */