Download Digital Signal Processing with V850 and V850E Devices Application

Transcript
Chapter 7
Application Examples
_WORD i, j, index ;
signed short u0 ;
signed int u1[8], u2[8], u3[8] ;
unsigned int u7[8], max1, max2, average, decisionlevel ;
signed short ar1[8], br1[8] ;
unsigned int y, z ;
unsigned int freq_mix ;
char *results ;
unsigned int resultsize ;
unsigned int number_of_samples ;
signed short *audio ;
_WORD static volatile time ;
cpu_init() ;
/* reset all
y = 0 ; z
for (i=0;
{
u1[i] =
}
memories */
= 0 ;
i<8; i++)
0 ; u2[i] = 0 ; u7[i] = 0 ;
number_of_samples = in_size ;
/* limit the number of samples to a ´reasonable´ value */
if (number_of_samples > 20000) number_of_samples = 20000 ;
audio = in ;
resultsize = (number_of_samples / SAMPLELIMIT) + 2 ;
results = (char *) malloc(resultsize * sizeof(*results)) ;
if (results == NULL) exit(-1) ; /* heap overflow. give up */
for (i=0; i<resultsize; i++)
{ /* reset results */
results[i] = 0 ;
}
#ifndef PREDEFINEDCOEFF
/* initialize filter coefficients (scaled by 16384) */
ar1[0] = 16384 *
-cos(2*PI* (float) 697 /(float)in_SamplesPerSecond) ;
br1[0] = 16384 * 2 * cos(2*PI* (float) 697 /(float)in_SamplesPerSecond) ;
ar1[1] = 16384 *
-cos(2*PI* (float) 770 /(float)in_SamplesPerSecond) ;
br1[1] = 16384 * 2 * cos(2*PI* (float) 770 /(float)in_SamplesPerSecond) ;
ar1[2] = 16384 *
-cos(2*PI* (float) 852 /(float)in_SamplesPerSecond) ;
br1[2] = 16384 * 2 * cos(2*PI* (float) 852 /(float)in_SamplesPerSecond) ;
ar1[3] = 16384 *
-cos(2*PI* (float) 941 /(float)in_SamplesPerSecond) ;
br1[3] = 16384 * 2 * cos(2*PI* (float) 941 /(float)in_SamplesPerSecond) ;
ar1[4] = 16384 *
-cos(2*PI* (float) 1209/(float)in_SamplesPerSecond) ;
br1[4] = 16384 * 2 * cos(2*PI* (float) 1209/(float)in_SamplesPerSecond) ;
ar1[5] = 16384 *
-cos(2*PI* (float) 1336/(float)in_SamplesPerSecond) ;
br1[5] = 16384 * 2 * cos(2*PI* (float) 1336/(float)in_SamplesPerSecond) ;
ar1[6] = 16384 *
-cos(2*PI* (float) 1477/(float)in_SamplesPerSecond) ;
br1[6] = 16384 * 2 * cos(2*PI* (float) 1477/(float)in_SamplesPerSecond) ;
ar1[7] = 16384 *
-cos(2*PI* (float) 1633/(float)in_SamplesPerSecond) ;
br1[7] = 16384 * 2 * cos(2*PI* (float) 1633/(float)in_SamplesPerSecond) ;
#else
/* predefined values for 8 kHz sampling rate */
ar1[0] = -13989 ; ar1[1] = -13478 ; ar1[2] = -12850 ; ar1[3] = -12109 ;
ar1[4] = -9536 ; ar1[5] = -8162 ; ar1[6] = -6542 ; ar1[7] = -4657 ;
br1[0] = 27979 ; br1[1] = 26956 ; br1[2] = 25701 ; br1[3] = 24218 ;
br1[4] = 19072 ; br1[5] = 16324 ; br1[6] = 13084 ; br1[7] =
9314 ;
Application Note U17285EE2V0AN00
49