/* SigLib FIR Filter Add Samples Example */

#include <stdio.h>
#include <siglib.h>

/* Define constants */
#define	FILTER_LENGTH			5L
#define	SAMPLE_INSERT_LENGTH	3L

/* Declare global variables */
			/* Initialise filter coefficients */
SLData_t	FilterCoeffs[FILTER_LENGTH] = {
	0., 0., 0., 0., 1.
	};

SLData_t	SourceData[] = {
	0., 1., 2., 3., 4., 5., 6., 7., 8., 9.,
	10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
	20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
	};

SLData_t	FilterDelay[FILTER_LENGTH];

SLArrayIndex_t	FilterIndex;

void	main(void);

void main(void)
{
	SLFixData_t	i = ((SLFixData_t)0);
	SLData_t	*pSrcData = SourceData;

	SIF_Fir (FilterDelay,							/* Pointer to filter state array */
			&FilterIndex,							/* Pointer to filter index register */
			FILTER_LENGTH);							/* Filter length */

	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */

	SDS_FirAddSample (*pSrcData++,					/* Input sample to add to delay line */
					  FilterDelay,					/* Pointer to filter state array */
					  &FilterIndex,					/* Pointer to filter index register */
					  FILTER_LENGTH);				/* Filter length */

	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */

	SDS_FirAddSample (*pSrcData++,					/* Input sample to add to delay line */
					  FilterDelay,					/* Pointer to filter state array */
					  &FilterIndex,					/* Pointer to filter index register */
					  FILTER_LENGTH);				/* Filter length */

	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */

	SDA_FirAddSamples (pSrcData,					/* Pointer to input samples to add to delay line */
					   FilterDelay,					/* Pointer to filter state array */
					   &FilterIndex,				/* Pointer to filter index register */
					   FILTER_LENGTH,				/* Filter length */
					   SAMPLE_INSERT_LENGTH);		/* Number of samples to insert */
	pSrcData += SAMPLE_INSERT_LENGTH;

	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */
	printf ("Output[%ld] = %lf\n", i++, SDS_Fir (*pSrcData++,		/* Input data sample to be filtered */
												 FilterDelay,		/* Pointer to filter state array */
												 FilterCoeffs,		/* Pointer to filter coefficients */
												 &FilterIndex,		/* Pointer to filter index register */
												 FILTER_LENGTH));	/* Filter length */

}


