//Calculate the least common multiple.
unsigned CalLCM(unsigned m, unsigned n)
{
unsigned temp, i;
if(m<n) /*比较大小,使得m中存储大数,n中存储小数*/
{
temp = m;
m = n;
n = temp;
}
for(i=m; i>0; i++) /*从大数开始寻找满足条件的自然数*/
{
if(i%m==0 && i%n==0)
{/*输出满足条件的自然数并结束循环*/
return i;
}
}
return 0;
}
int main ()
{
int div_coef;
int i, j;
int cnt = 0;
unsigned SampleFreq[50];
float temp;
unsigned temp_u32, AllLCM = 1;
// printf("div_coef\tsample_freq\n");
for (div_coef=MIN_DIV_COEF; div_coef<=AD_SAMPLE_RATE_DEFAULT; div_coef++)
{
if (!(AD_SAMPLE_RATE_DEFAULT%div_coef))
{
if (AD_SAMPLE_RATE_DEFAULT/div_coef >= AD_SAMPLE_RATE_DEFAULT/MIN_DIV_COEF/AXIDMA_MAX_NUM_CH)
{
// printf("%d\t\t%d\n", div_coef, AD_SAMPLE_RATE_DEFAULT/div_coef);
SampleFreq[cnt] = AD_SAMPLE_RATE_DEFAULT/div_coef;
cnt++;
}
}
}
printf("%d\n", cnt);
for (i=0; i<cnt; i++)
printf("%f\n", (float)AD_SAMPLE_RATE_DEFAULT/MIN_DIV_COEF/SampleFreq[i]);
for (i=0; i<cnt; i++)
{
AllLCM = CalLCM(AllLCM, 10*AD_SAMPLE_RATE_DEFAULT/MIN_DIV_COEF/SampleFreq[i]);
}
printf("%d\n", AllLCM);
for (i=0; i<cnt; i++)
{
for (j=1; j<cnt; j++)
{
temp = SampleFreq[j]/(float)SampleFreq[i]*AXIDMA_MAX_NUM_CH;
if ((temp_u32=temp) < temp)
{
// printf("%d\t%d\n", SampleFreq[i], SampleFreq[j]);
memmove(SampleFreq+j, SampleFreq+j+1, (cnt-j-1)*sizeof(unsigned));
cnt--;
j--;
}
}
}
// printf("%d\n", cnt);
// for (i=0; i<cnt; i++)
// printf("%d\n", SampleFreq[i]);
return 0;
}