FreeBSD/contrib/ntp/ntpd/refclock_wwv.c
/*
 * wwv_receive - receive data from the audio device
 *
 * This routine reads input samples and adjusts the logical clock to
 * track the A/D sample clock by dropping or duplicating codec samples.
 * It also controls the A/D signal level with an AGC loop to mimimize
 * quantization noise and avoid overload.
 */
receive data from the audio device
This routine reads input samples and adjusts the logical clock to
track the A/D sample clock by dropping or duplicating codec samples.
It also controls the A/D signal level with an AGC loop to mimimize
quantization noise and avoid overload.
receive data from the audio device This routine reads input samples and adjusts the logical clock to track the A / D sample clock by dropping or duplicating codec samples . It also controls the A / D signal level with an AGC loop to mimimize quantization noise and avoid overload .
static void
wwv_receive(
	struct recvbuf *rbufp	
	)
{
	struct peer *peer;
	struct refclockproc *pp;
	struct wwvunit *up;
	double	sample;		
	u_char	*dpt;		
	int	bufcnt;		
	l_fp	ltemp;
	peer = rbufp->recv_peer;
	pp = peer->procptr;
	up = pp->unitptr;
	DTOLFP((double)rbufp->recv_length / WWV_SEC, &ltemp);
	L_SUB(&rbufp->recv_time, &ltemp);
	up->timestamp = rbufp->recv_time;
	dpt = rbufp->recv_buffer;
	for (bufcnt = 0; bufcnt < rbufp->recv_length; bufcnt++) {
		sample = up->comp[~*dpt++ & 0xff];
		if (sample > MAXAMP) {
			sample = MAXAMP;
			up->clipcnt++;
		} else if (sample < -MAXAMP) {
			sample = -MAXAMP;
			up->clipcnt++;
		}
		up->phase += (up->freq + clock_codec) / WWV_SEC;
		if (up->phase >= .5) {
			up->phase -= 1.;
		} else if (up->phase < -.5) {
			up->phase += 1.;
			wwv_rf(peer, sample);
			wwv_rf(peer, sample);
		} else {
			wwv_rf(peer, sample);
		}
		L_ADD(&up->timestamp, &up->tick);
	}
	if (pp->sloppyclockflag & CLK_FLAG2)
		up->port = 2;
	else
		up->port = 1;
	if (pp->sloppyclockflag & CLK_FLAG3)
		up->mongain = MONGAIN;
	else
		up->mongain = 0;
}
static void wwv_receive ( struct recvbuf * rbufp ) { struct peer * peer ; struct refclockproc * pp ; struct wwvunit * up ; double sample ; u_char * dpt ; int bufcnt ; l_fp ltemp ; peer = rbufp -> recv_peer ; pp = peer -> procptr ; up = pp -> unitptr ; DTOLFP ( ( double ) rbufp -> recv_length / WWV_SEC , & ltemp ) ; L_SUB ( & rbufp -> recv_time , & ltemp ) ; up -> timestamp = rbufp -> recv_time ; dpt = rbufp -> recv_buffer ; for ( bufcnt = 0 ; bufcnt < rbufp -> recv_length ; bufcnt ++ ) { sample = up -> comp [ ~ * dpt ++ & 0xff ] ; if ( sample > MAXAMP ) { sample = MAXAMP ; up -> clipcnt ++ ; } else if ( sample < - MAXAMP ) { sample = - MAXAMP ; up -> clipcnt ++ ; } up -> phase += ( up -> freq + clock_codec ) / WWV_SEC ; if ( up -> phase >= .5 ) { up -> phase -= 1. ; } else if ( up -> phase < -.5 ) { up -> phase += 1. ; wwv_rf ( peer , sample ) ; wwv_rf ( peer , sample ) ; } else { wwv_rf ( peer , sample ) ; } L_ADD ( & up -> timestamp , & up -> tick ) ; } if ( pp -> sloppyclockflag & CLK_FLAG2 ) up -> port = 2 ; else up -> port = 1 ; if ( pp -> sloppyclockflag & CLK_FLAG3 ) up -> mongain = MONGAIN ; else up -> mongain = 0 ; }
wwv_receive - receive data from the audio device
 This routine reads input samples and adjusts the logical clock to
 track the A/D sample clock by dropping or duplicating codec samples.
wwv_receive - receive data from the audio device This routine reads input samples and adjusts the logical clock to track the A / D sample clock by dropping or duplicating codec samples .
/* receive buffer structure pointer */ /*
	 * Local variables
	 */ /* codec sample */ /* buffer pointer */ /* buffer counter */ /*
	 * Main loop - read until there ain't no more. Note codec
	 * samples are bit-inverted.
	 */ /*
		 * Clip noise spikes greater than MAXAMP (6000) and
		 * record the number of clips to be used later by the
		 * AGC.
		 */ /*
		 * Variable frequency oscillator. The codec oscillator
		 * runs at the nominal rate of 8000 samples per second,
		 * or 125 us per sample. A frequency change of one unit
		 * results in either duplicating or deleting one sample
		 * per second, which results in a frequency change of
		 * 125 PPM.
		 */ /*
	 * Set the input port and monitor gain for the next buffer.
	 */