/**************************************************************************/
/**************************************************************************/
/*
preemph.c: This file contains the analysis code for the first order
	filter H[N] = (1,-1). It is used for pre-emphisis, so it does not
	return on failure as does the f1 filter. Otherwise, its the same.
	Also, this filter does not use a long, since overflow is wrapped.
*/
/**************************************************************************/
/*
Copyright, 1995 Atari Corporation.
Written for Atari by Highlight Software Solutions.
*/
/**************************************************************************/

#include "hdef.h"	/* this file contains the data types and constants. */


/**************************************************************************/
/*
Function: pre_emph

definition:
	This function implements a first order filter H[N] = (1,-1).
	The calling parameters choose the number of elements to act on.
	The calling parameters include an array of previous elements to
		allow for continuous states.
	The calling parameters also include an input block of elements
		and a pointer to the desired output block of elements.
	The array returns the bits needed to pack the outputs of the
		filter for use by the calling function in determining the
		winning filter.
arguments:
	statearray: this pointer points to an array of HWORDS that must
		contain the last samples from the previous block equal
		to the order of the filter. This 1st order filter uses
		only the first element in this list.
	elements: the number of elements to use this digital filter over.
	datain: this pointer points to a sequential array of HWORDS that
		contain the input words to the filter.
	fout: this pointer points to a sequential array of HWORDS that
		will contain the output words from the filter after
		completion of the filter.
-------------------------------------------------------
returns:
	an HINT with the maximum number of bits needed
	to pack the output of the filter. If TOOMANYBITS or more
	(see defines for value) then TOOMANYBITS are returned.
-------------------------------------------------------
example:
packbits = filter1(statearray, 32, databuf, outbuf);
calls this function which implements the first order filter on 32 elements
	starting at databuf, places the output at outbuf, and returns the
	number of bits needed to pack the filter in packbits.
	The elements at statearray are assumed to have preceeded the elements
	at databuf.
	For this first order filter, statearray[0] is the only element used
		from this list.
*/
/**************************************************************************/

HINT pre_emph(LPHWORD statearray, HINT elements, LPHWORD datain, LPHWORD fout)
{
HINT i;
HINT packbits;
HINT	temp;	/* temporary values need to be 16 bit word */

for (i = 0; i < elements; i++) {
	switch(i) {
		case 0:
			temp = ((HWORD) datain[0]) - ((HWORD) statearray[0]);
			fout[0] = (HINT) temp;
			break;
		default:
			temp = ((HWORD) datain[i]) - ((HWORD) datain[i-1]);
			fout[i] = (HINT) temp;
			break;
	}

}
packbits = maxbits(elements, fout);
return(packbits);
} /* pre_emph */




