📄 testmain.c
字号:
/*
* Copyright (c) 1998,2000 TriMedia Technologies Inc.
*
* +------------------------------------------------------------------+
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such |
* | a license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided|
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | this code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +------------------------------------------------------------------+
*
* Module name : floatMain.c
*
* Created : 01/14/99
*
* Last update : 01/14/99
*
* Description : test program for the IIR filter
* (floating point)
* This is for the case study on optimizing
* IIR filters only !!!
*
*/
/* --------------------------- includes ----------------------------------- */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ops/custom_defs.h>
#include "iirFloatCoeff.h"
/* --------------------------- defines ------------------------------------ */
#define SAMPLENUMBER 512
#define FREQUENCY 4 /* corresponds to a cutoff frequency of 100 Hz */
#define LOWHIGHA 0 /* 0 corresponds to lowpass filtering */
#define LOWHIGHB 1 /* 1 corresponds to highpass filtering */
#define COEFFNUMBER 5
#define FILTNUMBER 10
#define LOOPNUMBER 2
#define INPUTSHIFT 15
#define OUTPUTSHIFT 15
/* ------------------------------------------------------------------------ */
void main( int argc, char *argv[] )
{
FILE *pInFile, *pOutFileA, *pOutFileB, *pOutFile[FILTNUMBER];
short psInData[SAMPLENUMBER];
short psOutDataA[SAMPLENUMBER], psOutDataB[SAMPLENUMBER];
int done, i, j, n, rval, noInSamples, noOutSamples;
float fltInputBuffer[SAMPLENUMBER], fltOutputBuffer[SAMPLENUMBER];
float fltState[4], *fltCoeffA, *fltCoeffB;
int intInputBufferA[SAMPLENUMBER], intOutputBufferA[SAMPLENUMBER];
int intInputBufferB[SAMPLENUMBER], intOutputBufferB[SAMPLENUMBER];
int intState[4], intStateA[6], intStateB[6];
int intCoeffA[5], intCoeffB[5];
char *fileName;
int totalSampleNumber;
if(( pInFile = fopen( argv[1], "rb")) == NULL)
{
printf("\nfile %s does not exist\n", argv[1]);
exit(1);
}
for( i=0, fileName=" "; i < 9 ; i++ )
{
sprintf( fileName, "iirOut%d.pcm", i+1 );
if(( pOutFile[i] = fopen( fileName, "wb")) == NULL )
printf("\nerror while opening output files\n", fileName );
strcpy( fileName, " " );
}
if(( pOutFileA = fopen( "outA.pcm", "wb")) == NULL )
printf("\nerror while opening output files\n", "outA.pcm");
if(( pOutFileB = fopen( "outB.pcm", "wb")) == NULL )
printf("\nerror while opening output files\n", "outB.pcm");
fltCoeffA = ( &coeffLib[0] + COEFFNUMBER*(2*FREQUENCY + LOWHIGHA) );
fltCoeffB = ( &coeffLib[0] + COEFFNUMBER*(2*FREQUENCY + LOWHIGHB) );
rval = convertCoeff( intCoeffA, fltCoeffA, COEFFNUMBER );
if ( rval != 0 )
printf("error %x in convertCoeff\n", rval );
rval = convertCoeff( intCoeffB, fltCoeffB, COEFFNUMBER );
if ( rval != 0 )
printf("error %x in convertCoeff\n", rval );
for( n=1, totalSampleNumber=0; n<(FILTNUMBER+1); n++ )
{
printf("\n");
for( i=0; i<4; i++ )
{
fltState[i] = 0.0;
intState[i] = 0;
}
for( i=0; i<6; i++ )
{
intStateA[i] = 0;
intStateB[i] = 0;
}
for( j=0; j<LOOPNUMBER; j++ )
{
done=1;
printf("iirFilter_%d, loop %d (1 to %d)\n", n, j+1, LOOPNUMBER);
while( done == 1 )
{
noInSamples = fread( psInData, sizeof( short ), SAMPLENUMBER, pInFile );
if( noInSamples < SAMPLENUMBER )
done = 0;
if( noInSamples > 0 )
{
if( n<6 )
{
for( i=0; i < noInSamples; i++ )
{
fltInputBuffer[i] = (float)psInData[i];
if( n==1 )
totalSampleNumber++;
}
}
else
for( i=0; i < noInSamples; i++ )
{
intInputBufferA[i] = (int)psInData[i] << INPUTSHIFT;
intInputBufferB[i] = (int)psInData[i] << INPUTSHIFT;
}
switch(n)
{
case 1:
rval = iirFilter_1( fltInputBuffer, fltOutputBuffer, fltCoeffA, fltState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_1\n", rval );
break;
case 2:
rval = iirFilter_2( fltInputBuffer, fltOutputBuffer, fltCoeffA, fltState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_2\n", rval );
break;
case 3:
rval = iirFilter_3( fltInputBuffer, fltOutputBuffer, fltCoeffA, fltState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_3\n", rval );
break;
case 4:
rval = iirFilter_4( fltInputBuffer, fltOutputBuffer, fltCoeffA, fltState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_4\n", rval );
break;
case 5:
rval = iirFilter_5( fltInputBuffer, fltOutputBuffer, fltCoeffA, fltState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_5\n", rval );
break;
case 6:
rval = iirFilter_6( intInputBufferA, intOutputBufferA, intCoeffA, intState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_6\n", rval );
break;
case 7:
rval = iirFilter_7( intInputBufferA, intOutputBufferA, intCoeffA, intState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_7\n", rval );
break;
case 8:
rval = iirFilter_8( intInputBufferA, intOutputBufferA, intCoeffA, intState, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_8\n", rval );
break;
case 9:
rval = iirFilter_9( intInputBufferA, intOutputBufferA, intCoeffA, intStateA, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_9\n", rval );
break;
case 10:
rval = iirFilter_10( intInputBufferA, intInputBufferB,
intOutputBufferA, intOutputBufferB,
intCoeffA, intCoeffB, intStateA, intStateB, noInSamples );
if ( rval != 0 )
printf("error %x in iirFilter_10\n", rval );
break;
default: break;
}
if( j==(LOOPNUMBER-1) )
{
if( n<6 )
{
for( i=0; i < noInSamples; i++ )
psOutDataA[i] = (short)(iclipi((int)fltOutputBuffer[i], 0x7FFF));
noOutSamples = fwrite( psOutDataA, sizeof( short ), noInSamples, pOutFile[n-1] );
if( noOutSamples != noInSamples )
printf("\nnoOutSamples != noInSamples ???\n");
}
else
{
if( n<10 )
{
for( i=0; i < noInSamples; i++ )
psOutDataA[i] = (short)(iclipi(intOutputBufferA[i] >> OUTPUTSHIFT, 0x7FFF));
noOutSamples = fwrite( psOutDataA, sizeof( short ), noInSamples, pOutFile[n-1] );
if( noOutSamples != noInSamples )
printf("\nnoOutSamples != noInSamples ???\n");
}
else
{
for( i=0; i < noInSamples; i++ )
{
psOutDataA[i] = (short)(iclipi(intOutputBufferA[i] >> OUTPUTSHIFT, 0x7FFF));
psOutDataB[i] = (short)(iclipi(intOutputBufferB[i] >> OUTPUTSHIFT, 0x7FFF));
}
noOutSamples = fwrite( psOutDataA, sizeof( short ), noInSamples, pOutFileA );
if( noOutSamples != noInSamples )
printf("\nnoOutSamples != noInSamples ???\n");
noOutSamples = fwrite( psOutDataB, sizeof( short ), noInSamples, pOutFileB );
if( noOutSamples != noInSamples )
printf("\nnoOutSamples != noInSamples ???\n");
}
}
}
}
}
rewind(pInFile);
}
}
printf("total number of samples processed is %d\n", totalSampleNumber);
fclose(pInFile); fclose(pOutFileA); fclose(pOutFileB);
for(i=0;i<FILTNUMBER;i++)
fclose(pOutFile[i]);
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -