*** freeze/include/audio.h Fri Feb 7 16:03:30 2003 --- hacked/include/audio.h Fri Feb 7 20:57:45 2003 *************** *** 7,14 **** #define MONGAIN 127 /* codec monitor gain */ /* ! * Function prototypes */ ! int audio_init P((char *, int, int)); ! int audio_gain P((int, int, int)); ! void audio_show P((void)); --- 7,14 ---- #define MONGAIN 127 /* codec monitor gain */ /* ! * Function prototypes - all are hacked, blame :RWA: */ ! int audio_init P((char *, int, int, struct refclockproc *)); ! int audio_gain P((struct refclockproc *)); ! void audio_show P((struct refclockproc *)); *** freeze/include/ntp_refclock.h Fri Feb 7 16:03:30 2003 --- hacked/include/ntp_refclock.h Sat Feb 8 23:22:55 2003 *************** *** 131,136 **** --- 131,146 ---- int datalen; /* lenth of data */ SOCKET fd; /* file descriptor */ u_long recvcount; /* count of receive completions */ + + /* + hack to instantiate the audio_* functions :RWA: + */ + + SOCKET md; /* mixer device */ + u_int32 port; /* mixer input channel from wwvunit */ + int gain; /* mixer input volume, 0..255, from wwvunit */ + u_int32 monport; /* monitor output channel (new :RWA:) */ + int mongain; /* monitor output volume, 0..255 from wwvunit */ }; /* *** freeze/libntp/audio.c Fri Feb 7 16:03:31 2003 --- hacked/libntp/audio.c Mon Feb 10 09:49:32 2003 *************** *** 8,14 **** #if defined(HAVE_SYS_AUDIOIO_H) || defined(HAVE_SUN_AUDIOIO_H) || \ defined(HAVE_SYS_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H) ! #include "audio.h" #include "ntp_stdlib.h" #include "ntp_syslog.h" #ifdef HAVE_UNISTD_H --- 8,16 ---- #if defined(HAVE_SYS_AUDIOIO_H) || defined(HAVE_SUN_AUDIOIO_H) || \ defined(HAVE_SYS_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H) ! #include "ntpd.h" ! /* #include "ntp_io.h" */ ! #include "ntp_refclock.h" #include "ntp_stdlib.h" #include "ntp_syslog.h" #ifdef HAVE_UNISTD_H *************** *** 46,75 **** # include #endif /* * Global variables */ #ifdef HAVE_SYS_AUDIOIO_H static struct audio_device device; /* audio device ident */ #endif /* HAVE_SYS_AUDIOIO_H */ #ifdef PCM_STYLE_SOUND - # define INIT_FILE "/etc/ntp.audio" - int agc = SOUND_MIXER_WRITE_RECLEV; /* or IGAIN or LINE */ - int monitor = SOUND_MIXER_WRITE_VOLUME; /* or OGAIN */ int devmask = 0; int recmask = 0; - char cf_c_dev[100], cf_i_dev[100], cf_agc[100], cf_monitor[100]; - - const char *m_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; #else /* not PCM_STYLE_SOUND */ static struct audio_info info; /* audio device info */ #endif /* not PCM_STYLE_SOUND */ - static int ctl_fd; /* audio control file descriptor */ #ifdef PCM_STYLE_SOUND ! static void audio_config_read P((int, char **, char **)); static int mixer_name P((const char *, int)); int mixer_name( --- 48,74 ---- # include #endif + #include "audio.h" + /* * Global variables */ #ifdef HAVE_SYS_AUDIOIO_H static struct audio_device device; /* audio device ident */ #endif /* HAVE_SYS_AUDIOIO_H */ + #ifdef PCM_STYLE_SOUND int devmask = 0; int recmask = 0; #else /* not PCM_STYLE_SOUND */ static struct audio_info info; /* audio device info */ #endif /* not PCM_STYLE_SOUND */ #ifdef PCM_STYLE_SOUND ! static void audio_config_read P((int, char *, char *, struct refclockproc *)); static int mixer_name P((const char *, int)); + const char *m_names[] = SOUND_DEVICE_NAMES; int mixer_name( *************** *** 102,139 **** * * idev /dev/input_device * cdev /dev/control_device ! * agc pcm_input_device {igain,line,line1,...} ! * monitor pcm_monitor_device {ogain,...} * * The device names for the "agc" and "monitor" keywords * can be found by running either the "mixer" program or the * util/audio-pcm program. * * Great hunks of this subroutine were swiped from refclock_oncore.c */ static void audio_config_read( int unit, ! char **c_dev, /* Control device */ ! char **i_dev /* input device */ ) { FILE *fd; ! char device[20], line[100], ab[100]; ! sprintf(device, "%s%d", INIT_FILE, unit); if ((fd = fopen(device, "r")) == NULL) { printf("audio_config_read: <%s> NO\n", device); ! sprintf(device, "%s.%d", INIT_FILE, unit); if ((fd = fopen(device, "r")) == NULL) { printf("audio_config_read: <%s> NO\n", device); ! sprintf(device, "%s.%d", INIT_FILE, unit); if ((fd = fopen(device, "r")) == NULL) { printf("audio_config_read: <%s> NO\n", device); return; } } } printf("audio_config_read: reading <%s>\n", device); while (fgets(line, sizeof line, fd)) { char *cp, *cc, *ca; --- 101,170 ---- * * idev /dev/input_device * cdev /dev/control_device ! * source pcm_rec_device {vol, line, mic, ...} ! * agc pcm_mix_device {rec,igain,line,line1,...} ! * monitor pcm_mix_device {ogain,...} * * The device names for the "agc" and "monitor" keywords * can be found by running either the "mixer" program or the * util/audio-pcm program. * * Great hunks of this subroutine were swiped from refclock_oncore.c + * (apparently without chewing... :RWA:) */ + + #define INIT_FILE "/etc/ntp.audio" + char cf_c_dev[50], /* control (==mixer) device */ + cf_i_dev[50], /* codec device */ + cf_source[25], /* recording source line */ + cf_agc[25], /* agc channel name */ + cf_monitor[25]; /* monitor channel name */ + static void audio_config_read( int unit, ! char *c_dev, /* Control device HINT */ ! char *i_dev, /* input device HINT */ ! struct refclockproc * pp /* io block ptr */ ) { FILE *fd; ! char device[50], line[100], ab[100]; ! /* get hints into place; the effect is to build a skeleton config ! so that in some sense this routine always succeeds. ! */ ! if ( c_dev ) ! strcpy( cf_c_dev, c_dev ); /* use hint to set up a default */ ! if ( i_dev ) ! strcpy( cf_i_dev, i_dev ); /* ditto */ ! ! if ( pp->sloppyclockflag & CLK_FLAG2 ) /* honour flag2 <- input port */ ! strcpy( cf_agc, "line" ); ! else ! strcpy( cf_agc, "mic" ); ! ! strcpy( cf_source, cf_agc ); /* in a sane world these are the same... */ ! strcpy( cf_monitor, "vol" ); ! ! /* try one of the many names for the control file. Will someone ! tell me again what all this complexity buys us? ! My vote is ${INIT_FILE}.${UNIT} and no second chances; KISS! :RWA: ! */ ! sprintf(device, "%s.%d", INIT_FILE, unit); if ((fd = fopen(device, "r")) == NULL) { printf("audio_config_read: <%s> NO\n", device); ! sprintf(device, "%s%d", INIT_FILE, unit); if ((fd = fopen(device, "r")) == NULL) { printf("audio_config_read: <%s> NO\n", device); ! strcpy( device, INIT_FILE ); /* this was botched :RWA: */ if ((fd = fopen(device, "r")) == NULL) { printf("audio_config_read: <%s> NO\n", device); return; } } } + printf("audio_config_read: reading <%s>\n", device); while (fgets(line, sizeof line, fd)) { char *cp, *cc, *ca; *************** *** 182,192 **** } else if (!strncmp(cc, "AGC", (size_t) 3)) { sscanf(ca, "%s", ab); strcpy(cf_agc, ab); ! printf("agc <%s> %d\n", ab, i); } else if (!strncmp(cc, "MONITOR", (size_t) 7)) { sscanf(ca, "%s", ab); strcpy(cf_monitor, ab); ! printf("monitor <%s> %d\n", ab, mixer_name(ab, -1)); } } fclose(fd); --- 213,227 ---- } else if (!strncmp(cc, "AGC", (size_t) 3)) { sscanf(ca, "%s", ab); strcpy(cf_agc, ab); ! printf("agc '%s' %d\n", ab, mixer_name(ab, -1)); } else if (!strncmp(cc, "MONITOR", (size_t) 7)) { sscanf(ca, "%s", ab); strcpy(cf_monitor, ab); ! printf("monitor '%s' %d\n", ab, mixer_name(ab, -1)); ! } else if (!strncmp(cc, "SOURCE", (size_t) 6)) { ! sscanf(ca, "%s", ab); ! strcpy(cf_source, ab); ! printf("source '%s' %d\n", ab, mixer_name(ab, -1)); } } fclose(fd); *************** *** 204,219 **** * codec sample rate (8000 Hz), precision (8 bits), number of channels * (1) and encoding (ITU-T G.711 mu-law companded) have been set by * default. */ int audio_init( ! char *dname, /* device name */ int bufsiz, /* buffer size */ ! int unit /* device unit (0-3) */ ) { #ifdef PCM_STYLE_SOUND # define ACTL_DEV "/dev/mixer%d" char actl_dev[30]; # ifdef HAVE_STRUCT_SND_SIZE struct snd_size s_size; --- 239,265 ---- * codec sample rate (8000 Hz), precision (8 bits), number of channels * (1) and encoding (ITU-T G.711 mu-law companded) have been set by * default. + * + * It DIDN'T set the input port because no one tells it which one is + * wanted!! A weird side-effect in the one-second handler did that. + * Which evil hack, in the PCM case, I've shut down. So instead we'll + * try to pull that out of pp->sloppyclockflag in canonical fashion + * (down in audio_read_config, as a part of the skeleton + * construction.) Oy, gevalt. I don't think anyone's really looked + * at this stuff in a while, it's quite tangled. :RWA: */ + int audio_init( ! char *dname, /* device name HINT */ int bufsiz, /* buffer size */ ! int unit, /* device unit (0-3) */ ! struct refclockproc * pp /* io block pointer */ ) { #ifdef PCM_STYLE_SOUND # define ACTL_DEV "/dev/mixer%d" + int i; char actl_dev[30]; # ifdef HAVE_STRUCT_SND_SIZE struct snd_size s_size; *************** *** 222,228 **** snd_chan_param s_c_p; # endif #endif - int fd; int rval; char *actl = #ifdef PCM_STYLE_SOUND --- 268,273 ---- *************** *** 234,263 **** #ifdef PCM_STYLE_SOUND (void)sprintf(actl_dev, ACTL_DEV, unit); ! ! audio_config_read(unit, &actl, &dname); ! /* If we have values for cf_c_dev or cf_i_dev, use them. */ ! if (*cf_c_dev) ! dname = cf_c_dev; ! if (*cf_i_dev) ! actl = cf_i_dev; #endif /* * Open audio device. Do not complain if not there. */ ! fd = open(dname, O_RDWR | O_NONBLOCK, 0777); ! if (fd < 0) ! return (fd); /* * Open audio control device. */ ! ctl_fd = open(actl, O_RDWR); ! if (ctl_fd < 0) { msyslog(LOG_ERR, "audio_init: invalid control device <%s>\n", actl); ! close(fd); ! return(ctl_fd); } /* --- 279,305 ---- #ifdef PCM_STYLE_SOUND (void) sprintf(actl_dev, ACTL_DEV, unit); ! audio_config_read( unit, actl, dname, pp ); ! /* We now have values for cf_c_dev and cf_i_dev, use them. :RWA: */ ! actl = cf_c_dev; ! dname = cf_i_dev; #endif /* * Open audio device. Do not complain if not there. */ ! pp->io.fd = open(dname, O_RDWR | O_NONBLOCK, 0777); ! if ( pp->io.fd < 0) ! return ( pp->io.fd ); /* * Open audio control device. */ ! pp->io.md = open( actl, O_RDWR ); ! if ( pp->io.md < 0) { msyslog(LOG_ERR, "audio_init: invalid control device <%s>\n", actl); ! close( pp->io.fd ); ! return( pp->io.md ); } /* *************** *** 265,276 **** */ #ifdef PCM_STYLE_SOUND printf("audio_init: <%s> bufsiz %d\n", dname, bufsiz); ! rval = fd; # ifdef HAVE_STRUCT_SND_SIZE ! if (ioctl(fd, AIOGSIZE, &s_size) == -1) printf("audio_init: AIOGSIZE: %s\n", strerror(errno)); ! else printf("audio_init: orig: play_size %d, rec_size %d\n", s_size.play_size, s_size.rec_size); --- 307,318 ---- */ #ifdef PCM_STYLE_SOUND printf("audio_init: <%s> bufsiz %d\n", dname, bufsiz); ! rval = pp->io.fd; # ifdef HAVE_STRUCT_SND_SIZE ! if (ioctl( pp->io.fd, AIOGSIZE, &s_size) == -1) printf("audio_init: AIOGSIZE: %s\n", strerror(errno)); ! else { printf("audio_init: orig: play_size %d, rec_size %d\n", s_size.play_size, s_size.rec_size); *************** *** 278,329 **** printf("audio_init: want: play_size %d, rec_size %d\n", s_size.play_size, s_size.rec_size); ! if (ioctl(fd, AIOSSIZE, &s_size) == -1) printf("audio_init: AIOSSIZE: %s\n", strerror(errno)); ! else printf("audio_init: set: play_size %d, rec_size %d\n", s_size.play_size, s_size.rec_size); # endif /* HAVE_STRUCT_SND_SIZE */ # ifdef AIOGFMT ! if (ioctl(fd, AIOGFMT, &s_c_p) == -1) printf("audio_init: AIOGFMT: %s\n", strerror(errno)); else ! printf("audio_init: play_rate %lu, rec_rate %lu, play_format %#lx, rec_format %#lx\n", ! s_c_p.play_rate, s_c_p.rec_rate, s_c_p.play_format, s_c_p.rec_format); # endif /* Grab the device and record masks */ ! if (ioctl(ctl_fd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) printf("SOUND_MIXER_READ_DEVMASK: %s\n", strerror(errno)); ! if (ioctl(ctl_fd, SOUND_MIXER_READ_RECMASK, &recmask) == -1) printf("SOUND_MIXER_READ_RECMASK: %s\n", strerror(errno)); ! /* validate and set any specified config file stuff */ ! if (*cf_agc) { ! int i; ! i = mixer_name(cf_agc, recmask); if (i >= 0) ! agc = MIXER_WRITE(i); ! else ! printf("input %s not in recmask %#x\n", ! cf_agc, recmask); } ! if (*cf_monitor) { ! int i; ! ! /* devmask */ i = mixer_name(cf_monitor, devmask); if (i >= 0) ! monitor = MIXER_WRITE(i); ! else ! printf("monitor %s not in devmask %#x\n", ! cf_monitor, devmask); } #else /* not PCM_STYLE_SOUND */ AUDIO_INITINFO(&info); info.play.gain = AUDIO_MAX_GAIN; --- 320,398 ---- printf("audio_init: want: play_size %d, rec_size %d\n", s_size.play_size, s_size.rec_size); ! if (ioctl( pp->io.fd, AIOSSIZE, &s_size) == -1) printf("audio_init: AIOSSIZE: %s\n", strerror(errno)); ! else { ! /* let's read them back to make sure... */ ! (void) ioctl( pp->io.fd, AIOGSIZE, &s_size); /* must work! */ printf( "audio_init: set: play_size %d, rec_size %d\n", s_size.play_size, s_size.rec_size); + } + } # endif /* HAVE_STRUCT_SND_SIZE */ # ifdef AIOGFMT ! /* ! this really needs a leading AIOSFMT and failure check for ! completeness; or, for overachievers, we could use the ! AIOGCAP facility to see what we *can* get and then pass that ! back up for use in the compander table build. I'm not ! trying any of that for now. :RWA: ! */ ! ! if (ioctl( pp->io.fd, AIOGFMT, &s_c_p) == -1) printf("audio_init: AIOGFMT: %s\n", strerror(errno)); else ! printf("audio_init: play_rate %lu, rec_rate %lu," ! " play_format %#lx, rec_format %#lx\n", ! s_c_p.play_rate, s_c_p.rec_rate, ! s_c_p.play_format, s_c_p.rec_format); # endif /* Grab the device and record masks */ ! if (ioctl( pp->io.md, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) printf("SOUND_MIXER_READ_DEVMASK: %s\n", strerror(errno)); ! if (ioctl( pp->io.md, SOUND_MIXER_READ_RECMASK, &recmask) == -1) printf("SOUND_MIXER_READ_RECMASK: %s\n", strerror(errno)); ! /* validate and set config file stuff */ ! /* agc */ ! i = mixer_name(cf_agc, devmask); /* was recmask XXX :RWA: */ if (i >= 0) ! pp->io.port = i; ! else { ! printf("agc %s not in devmask %#x\n", cf_agc, devmask); ! pp->io.port = ( pp->sloppyclockflag & CLK_FLAG2 ) ? SOUND_MIXER_LINE : SOUND_MIXER_MIC; } ! /* monitor */ i = mixer_name(cf_monitor, devmask); if (i >= 0) ! pp->io.monport = i; ! else { ! printf("monitor %s not in devmask %#x\n", cf_monitor, devmask); ! pp->io.monport = SOUND_MIXER_VOLUME; } + /* source */ + i = mixer_name( cf_source, recmask ); + if (i < 0) { + printf("source %s not in recmask %#x\n", cf_source, recmask); + i = ( pp->sloppyclockflag & CLK_FLAG2 ) ? SOUND_MIXER_LINE : SOUND_MIXER_MIC; + } + i = 1 << i; /* this is a little non-obvious */ + if ( ioctl( pp->io.md, SOUND_MIXER_WRITE_RECSRC, & i ) < 0 ) + printf("audio_init: source botch: %s\n", strerror( errno ) ); + + /* + pick starting values, twiddle the gain knobs + */ + pp->io.gain = MAXGAIN / 2; + pp->io.mongain = ( pp->sloppyclockflag & CLK_FLAG3 ) ? MONGAIN : 0; + (void) audio_gain( pp ); + #else /* not PCM_STYLE_SOUND */ AUDIO_INITINFO(&info); info.play.gain = AUDIO_MAX_GAIN; *************** *** 331,427 **** # ifdef HAVE_SYS_AUDIOIO_H info.record.buffer_size = bufsiz; # endif /* HAVE_SYS_AUDIOIO_H */ ! rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info); if (rval < 0) { msyslog(LOG_ERR, "audio: invalid control device parameters\n"); ! close(ctl_fd); ! close(fd); return(rval); } - rval = fd; #endif /* not PCM_STYLE_SOUND */ return (rval); } - /* * audio_gain - adjust codec gains and port */ int audio_gain( ! int gain, /* volume level (gain) 0-255 */ ! int mongain, /* input to output mix (monitor gain) 0-255 */ ! int port /* selected I/O port: 1 mic/2 line in */ ) { int rval; - static int o_mongain = -1; - static int o_port = -1; #ifdef PCM_STYLE_SOUND int l, r; ! rval = 0; ! ! r = l = 100 * gain / 255; /* Normalize to 0-100 */ # ifdef DEBUG if (debug > 1) ! printf("audio_gain: gain %d/%d\n", gain, l); # endif l |= r << 8; ! rval = ioctl(ctl_fd, agc, &l); if (rval == -1) { printf("audio_gain: agc write: %s\n", strerror(errno)); ! return (rval); } ! if (o_mongain != mongain) { ! r = l = 100 * mongain / 255; /* Normalize to 0-100 */ ! # ifdef DEBUG ! if (debug > 1) ! printf("audio_gain: mongain %d/%d\n", mongain, l); ! # endif ! l |= r << 8; ! rval = ioctl(ctl_fd, monitor, &l); if (rval == -1) { ! printf("audio_gain: mongain write: %s\n", ! strerror(errno)); ! return (rval); ! } ! o_mongain = mongain; } - if (o_port != port) { - # ifdef DEBUG - if (debug > 1) - printf("audio_gain: port %d\n", port); - # endif - l = (1 << ((port == 2) ? SOUND_MIXER_LINE : SOUND_MIXER_MIC)); - rval = ioctl(ctl_fd, SOUND_MIXER_WRITE_RECSRC, &l); - if (rval == -1) { - printf("SOUND_MIXER_WRITE_RECSRC: %s\n", - strerror(errno)); - return (rval); - } - # ifdef DEBUG - if (debug > 1) { - if (ioctl(ctl_fd, SOUND_MIXER_READ_RECSRC, &l) == -1) - printf("SOUND_MIXER_WRITE_RECSRC: %s\n", - strerror(errno)); - else - printf("audio_gain: recsrc is %d\n", l); - } - # endif - o_port = port; - } #else /* not PCM_STYLE_SOUND */ ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info); info.record.error = 0; ! info.record.gain = gain; ! if (o_mongain != mongain) ! o_mongain = info.monitor_gain = mongain; ! if (o_port != port) ! o_port = info.record.port = port; rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info); if (rval < 0) { msyslog(LOG_ERR, "audio_gain: %m"); --- 400,464 ---- # ifdef HAVE_SYS_AUDIOIO_H info.record.buffer_size = bufsiz; # endif /* HAVE_SYS_AUDIOIO_H */ ! rval = ioctl( pp->io.md, (int)AUDIO_SETINFO, (char *)&info); if (rval < 0) { msyslog(LOG_ERR, "audio: invalid control device parameters\n"); ! close(pp->io.md); ! close(pp->io.fd); return(rval); } #endif /* not PCM_STYLE_SOUND */ + + rval = pp->io.fd; /* XXX this is wrong but I'm stupid right now */ return (rval); } /* * audio_gain - adjust codec gains and port */ int audio_gain( ! struct refclockproc *pp ) { int rval; #ifdef PCM_STYLE_SOUND int l, r; ! r = l = 100 * pp->io.gain / 255; /* Normalize to 0-100 */ # ifdef DEBUG if (debug > 1) ! printf("audio_gain: agc %d/%d\n", pp->io.gain, l); # endif + /* figure out what channel(s) to use. just nuke right for now. */ + r = 0 ; /* setting to zero nicely mutes the channel */ l |= r << 8; ! ! rval = ioctl( pp->io.md, MIXER_WRITE( pp->io.port ), & l); if (rval == -1) { printf( "audio_gain: agc write: %s\n", strerror( errno ) ); ! return rval; } ! r = l = 100 * pp->io.mongain / 255; /* Normalize to 0-100 */ ! rval = ioctl( pp->io.md, MIXER_WRITE( pp->io.monport ), & pp->io.mongain ); if (rval == -1) { ! printf( "audio_gain: mon write: %s\n", strerror( errno ) ); } #else /* not PCM_STYLE_SOUND */ + + static int o_mongain = -1; + static int o_port = -1; + ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info); info.record.error = 0; ! info.record.gain = pp->io.gain; ! if (o_mongain != pp->io.mongain) ! o_mongain = info.monitor_gain = pp->io.mongain; ! if (o_port != pp->io.port) ! o_port = info.record.port = -->io.port; rval = ioctl(ctl_fd, (int)AUDIO_SETINFO, (char *)&info); if (rval < 0) { msyslog(LOG_ERR, "audio_gain: %m"); *************** *** 429,434 **** --- 466,472 ---- } rval = info.record.error; #endif /* not PCM_STYLE_SOUND */ + return (rval); } *************** *** 440,473 **** * verify the ioctl's work. */ void ! audio_show(void) { #ifdef PCM_STYLE_SOUND int recsrc = 0; ! printf("audio_show: ctl_fd %d\n", ctl_fd); ! if (ioctl(ctl_fd, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) printf("SOUND_MIXER_READ_RECSRC: %s\n", strerror(errno)); #else /* not PCM_STYLE_SOUND */ # ifdef HAVE_SYS_AUDIOIO_H ! ioctl(ctl_fd, (int)AUDIO_GETDEV, &device); ! printf("audio: name %s, version %s, config %s\n", device.name, device.version, device.config); # endif /* HAVE_SYS_AUDIOIO_H */ ! ioctl(ctl_fd, (int)AUDIO_GETINFO, (char *)&info); printf( ! "audio: rate %d, chan %d, prec %d, code %d, gain %d, mon %d, port %d\n", info.record.sample_rate, info.record.channels, info.record.precision, info.record.encoding, info.record.gain, info.monitor_gain, info.record.port); printf( ! "audio: samples %d, eof %d, pause %d, error %d, waiting %d, balance %d\n", info.record.samples, info.record.eof, info.record.pause, info.record.error, info.record.waiting, info.record.balance); #endif /* not PCM_STYLE_SOUND */ } ! #else int audio_bs; #endif /* HAVE_{SYS_AUDIOIO,SUN_AUDIOIO,MACHINE_SOUNDCARD,SYS_SOUNDCARD}_H */ --- 478,517 ---- * verify the ioctl's work. */ void ! audio_show( struct refclockproc * pp ) { #ifdef PCM_STYLE_SOUND int recsrc = 0; ! /* ! this is a pretty poor showing, considering what we can ! get if we try. Fix me. :RWA: XXX ! */ ! printf("audio_show: ctl_fd %d\n", pp->io.md ); ! if ( ioctl( pp->io.md, SOUND_MIXER_READ_RECSRC, & recsrc ) < 0 ) printf("SOUND_MIXER_READ_RECSRC: %s\n", strerror(errno)); + printf("audio_show: recording source is %#x\n", recsrc ); #else /* not PCM_STYLE_SOUND */ # ifdef HAVE_SYS_AUDIOIO_H ! ioctl(pp->io.md, (int)AUDIO_GETDEV, &device); ! printf("audio_show: name %s, version %s, config %s\n", device.name, device.version, device.config); # endif /* HAVE_SYS_AUDIOIO_H */ ! ioctl(pp->io.md, (int)AUDIO_GETINFO, (char *)&info); printf( ! "audio_show: rate %d, chan %d, prec %d, code %d, gain %d, mon %d, port %d\n", info.record.sample_rate, info.record.channels, info.record.precision, info.record.encoding, info.record.gain, info.monitor_gain, info.record.port); printf( ! "audio_show: samples %d, eof %d, pause %d, error %d, waiting %d, balance %d\n", info.record.samples, info.record.eof, info.record.pause, info.record.error, info.record.waiting, info.record.balance); #endif /* not PCM_STYLE_SOUND */ } ! ! #else /* ! HAVE_{SYS_AUDIOIO,SUN_AUDIOIO,MACHINE_SOUNDCARD,SYS_SOUNDCARD}_H */ int audio_bs; #endif /* HAVE_{SYS_AUDIOIO,SUN_AUDIOIO,MACHINE_SOUNDCARD,SYS_SOUNDCARD}_H */ *** freeze/ntpd/refclock_chu.c Fri Feb 7 16:03:34 2003 --- hacked/ntpd/refclock_chu.c Mon Feb 10 09:56:44 2003 *************** *** 319,327 **** */ int fd_audio; /* audio port file descriptor */ double comp[SIZE]; /* decompanding table */ - int port; /* codec port */ - int gain; /* codec gain */ - int mongain; /* codec monitor gain */ int clipcnt; /* sample clip count */ int seccnt; /* second interval counter */ --- 319,324 ---- *************** *** 404,410 **** ) { struct chuunit *up; ! struct refclockproc *pp; char device[20]; /* device name */ int fd; /* file descriptor */ #ifdef ICOM --- 401,407 ---- ) { struct chuunit *up; ! struct refclockproc *pp = peer->procptr; /* need this early :RWA: */ char device[20]; /* device name */ int fd; /* file descriptor */ #ifdef ICOM *************** *** 412,436 **** int temp; #endif /* ICOM */ #ifdef HAVE_AUDIO ! int fd_audio; /* audio port file descriptor */ int i; /* index */ double step; /* codec adjustment */ /* ! * Open audio device. */ ! fd_audio = audio_init(DEVICE_AUDIO, AUDIO_BUFSIZ, unit); #ifdef DEBUG ! if (fd_audio > 0 && debug) ! audio_show(); #endif /* * Open serial port in raw mode. */ ! if (fd_audio > 0) { ! fd = fd_audio; ! } else { sprintf(device, DEVICE, unit); fd = refclock_open(device, SPEED232, LDISC_RAW); } --- 409,433 ---- int temp; #endif /* ICOM */ #ifdef HAVE_AUDIO ! int rv_audio; /* audio port success code */ int i; /* index */ double step; /* codec adjustment */ /* ! * Open audio device. Sets gain and mongain. */ ! rv_audio = audio_init(DEVICE_AUDIO, AUDIO_BUFSIZ, unit, pp); #ifdef DEBUG ! if (rv_audio > 0 && debug) ! audio_show(pp); #endif /* * Open serial port in raw mode. */ ! if (rv_audio > 0) ! fd = pp->io.fd; ! else { sprintf(device, DEVICE, unit); fd = refclock_open(device, SPEED232, LDISC_RAW); } *************** *** 454,460 **** return (0); } memset((char *)up, 0, sizeof(struct chuunit)); - pp = peer->procptr; pp->unitptr = (caddr_t)up; pp->io.clock_recv = chu_receive; pp->io.srcclock = (caddr_t)peer; --- 451,456 ---- *************** *** 480,487 **** * contains all the 256 values in the interest of speed. We do * this even if the audio codec is not available. C'est la lazy. */ ! up->fd_audio = fd_audio; ! up->gain = 127; up->comp[0] = up->comp[OFFSET] = 0.; up->comp[1] = 1; up->comp[OFFSET + 1] = -1.; up->comp[2] = 3; up->comp[OFFSET + 2] = -3.; --- 476,482 ---- * contains all the 256 values in the interest of speed. We do * this even if the audio codec is not available. C'est la lazy. */ ! up->fd_audio = pp->io.fd; up->comp[0] = up->comp[OFFSET] = 0.; up->comp[1] = 1; up->comp[OFFSET + 1] = -1.; up->comp[2] = 3; up->comp[OFFSET + 2] = -3.; *************** *** 646,661 **** } /* * Set the input port and monitor gain for the next buffer. */ if (pp->sloppyclockflag & CLK_FLAG2) ! up->port = 2; else ! up->port = 1; if (pp->sloppyclockflag & CLK_FLAG3) ! up->mongain = MONGAIN; else ! up->mongain = 0; } --- 641,667 ---- } /* + in the PCM_STYLE_AUDIO world, all this stuff gets done + by bits in libntp/audio.c q.v. :RWA: + + Later: I suppose you might want this if someone is fiddling + via ntpdc. I must ask the Elder Ones. :RWA: + */ + + #if !defined(HAVE_MACHINE_SOUNDCARD_H) || HAVE_MACHINE_SOUNDCARD_H == 0 + /* * Set the input port and monitor gain for the next buffer. */ if (pp->sloppyclockflag & CLK_FLAG2) ! pp->io.port = 2; else ! pp->io.port = 1; ! if (pp->sloppyclockflag & CLK_FLAG3) ! pp->io.mongain = MONGAIN; else ! pp->io.mongain = 0; ! #endif } *************** *** 1297,1303 **** "%c%1X %4d %3d %02d:%02d:%02d %c%x %+d %d %d %s %d %d %d %d", synchar, qual, pp->year, pp->day, pp->hour, pp->minute, pp->second, leapchar, up->dst, up->dut, ! minset, up->gain, up->ident, up->tai, up->burstcnt, up->mindist, up->ntstamp); else sprintf(pp->a_lastcode, --- 1303,1309 ---- "%c%1X %4d %3d %02d:%02d:%02d %c%x %+d %d %d %s %d %d %d %d", synchar, qual, pp->year, pp->day, pp->hour, pp->minute, pp->second, leapchar, up->dst, up->dut, ! minset, pp->io.gain, up->ident, up->tai, up->burstcnt, up->mindist, up->ntstamp); else sprintf(pp->a_lastcode, *************** *** 1529,1543 **** * wiggle the hardware bits. */ if (up->clipcnt == 0) { ! up->gain += 4; ! if (up->gain > MAXGAIN) ! up->gain = MAXGAIN; } else if (up->clipcnt > MAXCLP) { ! up->gain -= 4; ! if (up->gain < 0) ! up->gain = 0; } ! audio_gain(up->gain, up->mongain, up->port); up->clipcnt = 0; } #endif /* HAVE_AUDIO */ --- 1535,1549 ---- * wiggle the hardware bits. */ if (up->clipcnt == 0) { ! pp->io.gain += 4; ! if (pp->io.gain > MAXGAIN) ! pp->io.gain = MAXGAIN; } else if (up->clipcnt > MAXCLP) { ! pp->io.gain -= 4; ! if (pp->io.gain < 0) ! pp->io.gain = 0; } ! audio_gain(pp); up->clipcnt = 0; } #endif /* HAVE_AUDIO */ *** freeze/ntpd/refclock_irig.c Fri Feb 7 16:03:34 2003 --- hacked/ntpd/refclock_irig.c Mon Feb 10 10:01:43 2003 *************** *** 209,217 **** * Audio codec variables */ double comp[SIZE]; /* decompanding table */ - int port; /* codec port */ - int gain; /* codec gain */ - int mongain; /* codec monitor gain */ int clipcnt; /* sample clipped count */ int seccnt; /* second interval counter */ --- 209,214 ---- *************** *** 307,331 **** struct peer *peer /* peer structure pointer */ ) { ! struct refclockproc *pp; struct irigunit *up; /* * Local variables */ ! int fd; /* file descriptor */ int i; /* index */ double step; /* codec adjustment */ /* ! * Open audio device */ ! fd = audio_init(DEVICE_AUDIO, AUDIO_BUFSIZ, unit); ! if (fd < 0) return (0); #ifdef DEBUG if (debug) ! audio_show(); #endif /* --- 304,328 ---- struct peer *peer /* peer structure pointer */ ) { ! struct refclockproc *pp = peer->procptr; /* need this early on */ struct irigunit *up; /* * Local variables */ ! int rv; /* return value */ int i; /* index */ double step; /* codec adjustment */ /* ! * Open audio device - sets gain and mongain */ ! rv = audio_init( DEVICE_AUDIO, AUDIO_BUFSIZ, unit, pp ); ! if (rv < 0) return (0); #ifdef DEBUG if (debug) ! audio_show( pp ); #endif /* *************** *** 333,339 **** */ if (!(up = (struct irigunit *) emalloc(sizeof(struct irigunit)))) { ! (void) close(fd); return (0); } memset((char *)up, 0, sizeof(struct irigunit)); --- 330,337 ---- */ if (!(up = (struct irigunit *) emalloc(sizeof(struct irigunit)))) { ! (void) close(pp->io.fd); ! (void) close(pp->io.md); return (0); } memset((char *)up, 0, sizeof(struct irigunit)); *************** *** 342,350 **** pp->io.clock_recv = irig_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; ! pp->io.fd = fd; if (!io_addclock(&pp->io)) { ! (void)close(fd); free(up); return (0); } --- 340,349 ---- pp->io.clock_recv = irig_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; ! if (!io_addclock(&pp->io)) { ! (void)close(pp->io.fd); ! (void)close(pp->io.md); free(up); return (0); } *************** *** 358,364 **** up->tc = MINTC; up->decim = 1; up->fdelay = IRIG_B; - up->gain = 127; /* * The companded samples are encoded sign-magnitude. The table --- 357,362 ---- *************** *** 488,503 **** } /* * Set the input port and monitor gain for the next buffer. */ if (pp->sloppyclockflag & CLK_FLAG2) ! up->port = 2; else ! up->port = 1; if (pp->sloppyclockflag & CLK_FLAG3) ! up->mongain = MONGAIN; else ! up->mongain = 0; } /* --- 486,511 ---- } /* + This next bit doesn't make much sense in the PCM audio + worldview. Gain and mongain are set in audio_init; + pp->io.port ditto; though perhaps something LIKE this + is needed to propagate pokes to sloppyclockflag? It all + could be done in audio_gain, who has a much better idea + about what's going on that we do here... + */ + #if !defined(HAVE_MACHINE_SOUNDCARD_H) || HAVE_MACHINE_SOUNDCARD_H == 0 + /* * Set the input port and monitor gain for the next buffer. */ if (pp->sloppyclockflag & CLK_FLAG2) ! pp->io.port = 2; else ! pp->io.port = 1; if (pp->sloppyclockflag & CLK_FLAG3) ! pp->io.mongain = MONGAIN; else ! pp->io.mongain = 0; ! #endif } /* *************** *** 939,945 **** "%02x %c %2d %3d %02d:%02d:%02d %4.0f %3d %6.3f %2d %6.1f %6.1f %s", up->errflg, syncchar, pp->year, pp->day, pp->hour, pp->minute, pp->second, ! up->maxsignal, up->gain, up->modndx, up->tc, up->exing * 1e6 / SECOND, up->freq * 1e6 / SECOND, ulfptoa(&up->wuggle, 6)); pp->lencode = strlen(pp->a_lastcode); --- 947,953 ---- "%02x %c %2d %3d %02d:%02d:%02d %4.0f %3d %6.3f %2d %6.1f %6.1f %s", up->errflg, syncchar, pp->year, pp->day, pp->hour, pp->minute, pp->second, ! up->maxsignal, pp->io.gain, up->modndx, up->tc, up->exing * 1e6 / SECOND, up->freq * 1e6 / SECOND, ulfptoa(&up->wuggle, 6)); pp->lencode = strlen(pp->a_lastcode); *************** *** 1020,1034 **** * wiggle the hardware bits. */ if (up->clipcnt == 0) { ! up->gain += 4; ! if (up->gain > MAXGAIN) ! up->gain = MAXGAIN; } else if (up->clipcnt > MAXCLP) { ! up->gain -= 4; ! if (up->gain < 0) ! up->gain = 0; } ! audio_gain(up->gain, up->mongain, up->port); up->clipcnt = 0; } --- 1028,1042 ---- * wiggle the hardware bits. */ if (up->clipcnt == 0) { ! pp->io.gain += 4; ! if (pp->io.gain > MAXGAIN) ! pp->io.gain = MAXGAIN; } else if (up->clipcnt > MAXCLP) { ! pp->io.gain -= 4; ! if (pp->io.gain < 0) ! pp->io.gain = 0; } ! audio_gain( pp ); up->clipcnt = 0; } *** freeze/ntpd/refclock_wwv.c Fri Feb 7 16:03:35 2003 --- hacked/ntpd/refclock_wwv.c Mon Feb 10 10:03:04 2003 *************** *** 502,511 **** * Audio codec variables */ double comp[SIZE]; /* decompanding table */ int port; /* codec port */ int gain; /* codec gain */ int mongain; /* codec monitor gain */ ! int clipcnt; /* sample clipped count */ /* * Variables used to establish basic system timing --- 502,514 ---- * Audio codec variables */ double comp[SIZE]; /* decompanding table */ + int clipcnt; /* sample clipped count */ + + #if 0 /* this stuff moved into struct refclockio in include/ntp_refclock.h q.v. */ int port; /* codec port */ int gain; /* codec gain */ int mongain; /* codec monitor gain */ ! #endif /* * Variables used to establish basic system timing *************** *** 582,588 **** static double wwv_snr P((double, double)); static int carry P((struct decvec *)); static int wwv_newchan P((struct peer *)); ! static void wwv_newgame P((struct wwvunit *)); static int wwv_qsy P((struct peer *, int)); static double qsy[NCHAN] = {2.5, 5, 10, 15, 20}; /* frequencies (MHz) */ --- 585,591 ---- static double wwv_snr P((double, double)); static int carry P((struct decvec *)); static int wwv_newchan P((struct peer *)); ! static void wwv_newgame P((struct refclockproc *)); static int wwv_qsy P((struct peer *, int)); static double qsy[NCHAN] = {2.5, 5, 10, 15, 20}; /* frequencies (MHz) */ *************** *** 609,615 **** struct peer *peer /* peer structure pointer */ ) { ! struct refclockproc *pp; struct wwvunit *up; #ifdef ICOM int temp; --- 612,618 ---- struct peer *peer /* peer structure pointer */ ) { ! struct refclockproc *pp = peer->procptr; /* we need this early */ struct wwvunit *up; #ifdef ICOM int temp; *************** *** 618,655 **** /* * Local variables */ ! int fd; /* file descriptor */ int i; /* index */ double step; /* codec adjustment */ /* * Open audio device */ ! fd = audio_init(DEVICE_AUDIO, AUDIO_BUFSIZ, unit); ! if (fd < 0) return (0); #ifdef DEBUG if (debug) ! audio_show(); #endif /* * Allocate and initialize unit structure */ ! if (!(up = (struct wwvunit *) ! emalloc(sizeof(struct wwvunit)))) { ! (void) close(fd); return (0); } memset(up, 0, sizeof(struct wwvunit)); - pp = peer->procptr; pp->unitptr = (caddr_t)up; pp->io.clock_recv = wwv_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; ! pp->io.fd = fd; if (!io_addclock(&pp->io)) { ! (void)close(fd); free(up); return (0); } --- 621,661 ---- /* * Local variables */ ! int rv; /* success code */ int i; /* index */ double step; /* codec adjustment */ /* * Open audio device */ ! rv = audio_init( DEVICE_AUDIO, AUDIO_BUFSIZ, unit, pp ); ! if (rv < 0){ ! (void) close(pp->io.fd); ! (void) close(pp->io.md); return (0); + } #ifdef DEBUG if (debug) ! audio_show( pp ); #endif /* * Allocate and initialize unit structure */ ! if (!(up = (struct wwvunit *) emalloc(sizeof(struct wwvunit)))) { ! (void) close(pp->io.fd); ! (void) close(pp->io.md); return (0); } memset(up, 0, sizeof(struct wwvunit)); pp->unitptr = (caddr_t)up; pp->io.clock_recv = wwv_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; ! if (!io_addclock(&pp->io)) { ! (void)close(pp->io.fd); ! (void)close(pp->io.md); free(up); return (0); } *************** *** 690,696 **** up->decvec[DA + 2].radix = 4; up->decvec[YR].radix = 10; /* years */ up->decvec[YR + 1].radix = 10; ! wwv_newgame(up); /* * Initialize autotune if available. Start out at 15 MHz. Note --- 696,702 ---- up->decvec[DA + 2].radix = 4; up->decvec[YR].radix = 10; /* years */ up->decvec[YR + 1].radix = 10; ! wwv_newgame(pp); /* * Initialize autotune if available. Start out at 15 MHz. Note *************** *** 825,838 **** /* * Set the input port and monitor gain for the next buffer. */ if (pp->sloppyclockflag & CLK_FLAG2) ! up->port = 2; else ! up->port = 1; if (pp->sloppyclockflag & CLK_FLAG3) ! up->mongain = MONGAIN; else ! up->mongain = 0; } --- 831,854 ---- /* * Set the input port and monitor gain for the next buffer. */ + + /* + * Excuse me, but what the heck is this part about? Wandering + * input ports?? Are we trying to find one that works better? + * In a PCM audio environment, this is b0rken, and it doesn't + * match the manpages anyhoo. :RWA: + */ + #if !defined(HAVE_MACHINE_SOUNDCARD_H) || HAVE_MACHINE_SOUNDCARD_H == 0 if (pp->sloppyclockflag & CLK_FLAG2) ! pp->io.port = 2; else ! pp->io.port = 1; ! if (pp->sloppyclockflag & CLK_FLAG3) ! pp->io.mongain = MONGAIN; else ! pp->io.mongain = 0; ! #endif } *************** *** 1099,1105 **** */ if (wwv_newchan(peer) == 0 || up->watch >= ACQSN) { ! wwv_newgame(up); up->schan = (up->schan + 1) % NCHAN; wwv_qsy(peer, up->schan); } --- 1115,1121 ---- */ if (wwv_newchan(peer) == 0 || up->watch >= ACQSN) { ! wwv_newgame(pp); up->schan = (up->schan + 1) % NCHAN; wwv_qsy(peer, up->schan); } *************** *** 1116,1122 **** if (!(up->status & SSYNC)) up->alarm |= 1 << SYNERR; if (up->watch > DIGIT && !(up->status & DSYNC)) ! wwv_newgame(up); } } --- 1132,1138 ---- if (!(up->status & SSYNC)) up->alarm |= 1 << SYNERR; if (up->watch > DIGIT && !(up->status & DSYNC)) ! wwv_newgame(pp); } } *************** *** 1365,1371 **** * valid. */ snr = wwv_snr(sp->sigmax, sp->noise); ! isgood = sp->sigmax > ATHR && snr > ASNR && abs(epoch) < AWND * MS; switch (sp->count) { --- 1381,1387 ---- * valid. */ snr = wwv_snr(sp->sigmax, sp->noise); ! isgood = sp->sigmax > ATHR && snr > ASNR || abs(epoch) < AWND * MS; switch (sp->count) { *************** *** 1415,1421 **** if (pp->sloppyclockflag & CLK_FLAG4) { sprintf(tbuf, "wwv8 %d %3d %s %d %5.0f %5.1f %6ld %4ld %.0f", ! up->port, up->gain, sp->refid, sp->count, sp->sigmax, snr, sp->pos, sp->pos % SECOND, sp->epoch); record_clock_stats(&peer->srcadr, tbuf); --- 1431,1437 ---- if (pp->sloppyclockflag & CLK_FLAG4) { sprintf(tbuf, "wwv8 %d %3d %s %d %5.0f %5.1f %6ld %4ld %.0f", ! pp->io.port, pp->io.gain, sp->refid, sp->count, sp->sigmax, snr, sp->pos, sp->pos % SECOND, sp->epoch); record_clock_stats(&peer->srcadr, tbuf); *************** *** 1864,1870 **** if (pp->sloppyclockflag & CLK_FLAG4) { sprintf(tbuf, "wwv5 %2d %04x %3d %4d %d %s %04x %d %.0f/%.1f %s %04x %d %.0f/%.1f", ! up->port, up->status, up->gain, up->repoch, up->errcnt, sp->refid, sp->select, sp->count, sp->synmax, sp->synsnr, rp->refid, rp->select, rp->count, --- 1880,1886 ---- if (pp->sloppyclockflag & CLK_FLAG4) { sprintf(tbuf, "wwv5 %2d %04x %3d %4d %d %s %04x %d %.0f/%.1f %s %04x %d %.0f/%.1f", ! pp->io.port, up->status, pp->io.gain, up->repoch, up->errcnt, sp->refid, sp->select, sp->count, sp->synmax, sp->synsnr, rp->refid, rp->select, rp->count, *************** *** 2000,2006 **** * panic, game over and restart from scratch. */ if (up->watch > PANIC) { ! wwv_newgame(up); return; /* NOTREACHED */ } --- 2016,2022 ---- * panic, game over and restart from scratch. */ if (up->watch > PANIC) { ! wwv_newgame(pp); return; /* NOTREACHED */ } *************** *** 2478,2486 **** */ static void wwv_newgame( ! struct wwvunit *up /* driver unit pointer */ ) { struct chan *cp; int i; --- 2494,2503 ---- */ static void wwv_newgame( ! struct refclockproc *pp ) { + struct wwvunit *up = (struct wwvunit *) pp->unitptr; /* driver unit pointer */ struct chan *cp; int i; *************** *** 2490,2496 **** up->watch = up->status = up->avgint = up->alarm = 0; up->freq = 0; up->sptr = NULL; ! up->gain = MAXGAIN / 2; /* * Initialize the station processes for audio gain, select bit, --- 2507,2513 ---- up->watch = up->status = up->avgint = up->alarm = 0; up->freq = 0; up->sptr = NULL; ! pp->io.gain = MAXGAIN / 2; /* this is a wee bit ad-hoc... */ /* * Initialize the station processes for audio gain, select bit, *************** *** 2499,2505 **** memset(up->mitig, 0, sizeof(up->mitig)); for (i = 0; i < NCHAN; i++) { cp = &up->mitig[i]; ! cp->gain = up->gain; cp->wwv.select = SELV; sprintf(cp->wwv.refid, "WV%.0f", floor(qsy[i])); sprintf(cp->wwvh.refid, "WH%.0f", floor(qsy[i])); --- 2516,2522 ---- memset(up->mitig, 0, sizeof(up->mitig)); for (i = 0; i < NCHAN; i++) { cp = &up->mitig[i]; ! cp->gain = pp->io.gain; cp->wwv.select = SELV; sprintf(cp->wwv.refid, "WV%.0f", floor(qsy[i])); sprintf(cp->wwvh.refid, "WH%.0f", floor(qsy[i])); *************** *** 2526,2539 **** pp = peer->procptr; up = (struct wwvunit *)pp->unitptr; ! up->mitig[up->achan].gain = up->gain; #ifdef ICOM if (up->fd_icom > 0) rval = icom_freq(up->fd_icom, peer->ttl & 0x7f, qsy[chan]); #endif /* ICOM */ up->achan = chan; ! up->gain = up->mitig[up->achan].gain; return (rval); } --- 2543,2556 ---- pp = peer->procptr; up = (struct wwvunit *)pp->unitptr; ! up->mitig[up->achan].gain = pp->io.gain; #ifdef ICOM if (up->fd_icom > 0) rval = icom_freq(up->fd_icom, peer->ttl & 0x7f, qsy[chan]); #endif /* ICOM */ up->achan = chan; ! pp->io.gain = up->mitig[up->achan].gain; return (rval); } *************** *** 2630,2635 **** --- 2647,2658 ---- * clips, it is bumped down. The decoder is relatively insensitive to * amplitude, so this crudity works just fine. The input port is set and * the error flag is cleared, mostly to be ornery. + * + * I don't understand the bit about setting the input port, since that's + * done at device open time and I can't think why we'd want to wiggle it + * on the fly. Especially without any idea of what mixer devices there + * are, and *that* info is only exposed inside libntp/audio.c dammit. + * So I've declared that b0rken and deprecated. :RWA: */ static void wwv_gain( *************** *** 2648,2662 **** * wiggle the hardware bits. */ if (up->clipcnt == 0) { ! up->gain += 4; ! if (up->gain > MAXGAIN) ! up->gain = MAXGAIN; } else if (up->clipcnt > MAXCLP) { ! up->gain -= 4; ! if (up->gain < 0) ! up->gain = 0; } ! audio_gain(up->gain, up->mongain, up->port); up->clipcnt = 0; } --- 2671,2685 ---- * wiggle the hardware bits. */ if (up->clipcnt == 0) { ! pp->io.gain += 4; ! if (pp->io.gain > MAXGAIN) ! pp->io.gain = MAXGAIN; /* don't break the knob! */ } else if (up->clipcnt > MAXCLP) { ! pp->io.gain -= 4; ! if (pp->io.gain < 0) ! pp->io.gain = 0; } ! audio_gain( pp ); up->clipcnt = 0; }