funcs/func_resonance.c
static float iir_filter(
float input, /* new input sample */
FILTER *iir /* pointer to FILTER structure */
)
{
	unsigned int i;
	float *hist1_ptr,*hist2_ptr,*coef_ptr;
	float output,new_hist,history1,history2;

	/* allocate history array if different size than last call */

	if(!iir->history) {
		iir->history = (float *) ast_calloc(2*iir->length,sizeof(float));
		if(!iir->history) {
			printf("\nUnable to allocate history array in iir_filter\n");
			exit(1);
		}
	}

	coef_ptr = iir->coef; /* coefficient pointer */

	hist1_ptr = iir->history; /* first history */
	hist2_ptr = hist1_ptr + 1; /* next history */

	/* 1st number of coefficients array is overall input scale factor,
	* or filter gain */
	output = input * (*coef_ptr++);

	for (i = 0 ; i < iir->length; i++) {
		history1 = *hist1_ptr; /* history values */
		history2 = *hist2_ptr;

		output = output - history1 * (*coef_ptr++);
		new_hist = output - history2 * (*coef_ptr++);	/* poles */

		output = new_hist + history1 * (*coef_ptr++);
		output = output + history2 * (*coef_ptr++); /* zeros */

		*hist2_ptr++ = *hist1_ptr;
		*hist1_ptr++ = new_hist;
		hist1_ptr++;
		hist2_ptr++;
	}

	return(output);
}
/*
* --------------------------------------------------------------------
* 
* iir_filter - Perform IIR filtering sample by sample on floats
* 
* Implements cascaded direct form II second order sections.
* Requires FILTER structure for history and coefficients.
* The length in the filter structure specifies the number of sections.
* The size of the history array is 2*iir->length.
* The size of the coefficient array is 4*iir->length + 1 because
* the first coefficient is the overall scale factor for the filter.
* Returns one output sample for each input sample. Allocates history
* array if not previously allocated.
* 
* float iir_filter(float input,FILTER *iir)
* 
* float input new float input sample
* FILTER *iir pointer to FILTER structure
* 
* Returns float value giving the current output.
* 
* Allocation errors cause an error message and a call to exit.
* --------------------------------------------------------------------
*/
Perform IIR filtering sample by sample on floats
Implements cascaded direct form II second order sections.
Requires FILTER structure for history and coefficients.
The length in the filter structure specifies the number of sections.
The size of the history array is 2*iir->length.
The size of the coefficient array is 4*iir->length + 1 because
the first coefficient is the overall scale factor for the filter.
Returns one output sample for each input sample. Allocates history
array if not previously allocated.



float input new float input sample
FILTER *iir pointer to FILTER structure

Returns float value giving the current output.

Allocation errors cause an error message and a call to exit.
Perform IIR filtering sample by sample on floats Implements cascaded direct form II second order sections . Requires FILTER structure for history and coefficients . The length in the filter structure specifies the number of sections . The size of the history array is 2 * iir - > length . The size of the coefficient array is 4 * iir - > length + 1 because the first coefficient is the overall scale factor for the filter . Returns one output sample for each input sample . Allocates history array if not previously allocated . float input new float input sample FILTER * iir pointer to FILTER structure Returns float value giving the current output . Allocation errors cause an error message and a call to exit .
static float iir_filter(
float input, 
FILTER *iir 
)
{
	unsigned int i;
	float *hist1_ptr,*hist2_ptr,*coef_ptr;
	float output,new_hist,history1,history2;
	if(!iir->history) {
		iir->history = (float *) ast_calloc(2*iir->length,sizeof(float));
		if(!iir->history) {
			printf("\nUnable to allocate history array in iir_filter\n");
			exit(1);
		}
	}
	coef_ptr = iir->coef; 
	hist1_ptr = iir->history; 
	hist2_ptr = hist1_ptr + 1; 
	output = input * (*coef_ptr++);
	for (i = 0 ; i < iir->length; i++) {
		history1 = *hist1_ptr; 
		history2 = *hist2_ptr;
		output = output - history1 * (*coef_ptr++);
		new_hist = output - history2 * (*coef_ptr++);	
		output = new_hist + history1 * (*coef_ptr++);
		output = output + history2 * (*coef_ptr++); 
		*hist2_ptr++ = *hist1_ptr;
		*hist1_ptr++ = new_hist;
		hist1_ptr++;
		hist2_ptr++;
	}
	return(output);
}
static float iir_filter ( float input , FILTER * iir ) { unsigned int i ; float * hist1_ptr , * hist2_ptr , * coef_ptr ; float output , new_hist , history1 , history2 ; if ( ! iir -> history ) { iir -> history = ( float * ) ast_calloc ( 2 * iir -> length , sizeof ( float ) ) ; if ( ! iir -> history ) { printf ( " \n \n " ) ; exit ( 1 ) ; } } coef_ptr = iir -> coef ; hist1_ptr = iir -> history ; hist2_ptr = hist1_ptr + 1 ; output = input * ( * coef_ptr ++ ) ; for ( i = 0 ; i < iir -> length ; i ++ ) { history1 = * hist1_ptr ; history2 = * hist2_ptr ; output = output - history1 * ( * coef_ptr ++ ) ; new_hist = output - history2 * ( * coef_ptr ++ ) ; output = new_hist + history1 * ( * coef_ptr ++ ) ; output = output + history2 * ( * coef_ptr ++ ) ; * hist2_ptr ++ = * hist1_ptr ; * hist1_ptr ++ = new_hist ; hist1_ptr ++ ; hist2_ptr ++ ; } return ( output ) ; }
iir_filter - Perform IIR filtering sample by sample on floats
Implements cascaded direct form II second order sections.
iir_filter - Perform IIR filtering sample by sample on floats Implements cascaded direct form II second order sections .
/* new input sample */ /* pointer to FILTER structure */ /* allocate history array if different size than last call */ /* coefficient pointer */ /* first history */ /* next history */ /* 1st number of coefficients array is overall input scale factor,
	* or filter gain */ /* history values */ /* poles */ /* zeros */