if ((numin = AVAIL(0)) > 0) {
while(count < numin) {
IT_IN(0);
totalCount++;
val=inp(0);
if(val==0.0 && theState== STATE_SILENCE) {
if(IT_OUT(0)) {
fprintf(stderr,"setsnr.s buffer 0 overflow\n");
return(99);
}
out(0)=val;
}else {
wbuffer_P[windowCount]=val;
windowCount++;
if(theState == STATE_PREAMBLE ) {
// store samples into preamble buffer
buffer_P[preambleCount]=val;
preambleCount++;
if(preambleCount == preambleSize) {
if(verbose) fprintf(stderr,"STATE= STATE_SYMBOLS count=%d\n",totalCount);
theState= STATE_SYMBOLS;
preambleCount=0;
}
windowCount=0;
}
if(windowCount== windowSize) {
windowFull=1;
sum=0;
for(i=0; isilenceThreshold && theState==STATE_SILENCE) {
if(verbose)fprintf(stderr,"STATE= STATE_PREAMBLE count=%d sum=%f \n",totalCount,sum);
theState=STATE_PREAMBLE;
for(i=0; i 100) {
fprintf(stderr,"setsnr.s: problem with random number generator\n");
return(2);
}
/* get two random numbers in the interval (-1,1) */
s = random();
u = -1.0 + 2.0*(s/max);
t = random();
v = -1.0 + 2.0*(t/max);
w = u*u + v*v;
/* is point (u,v) in the unit circle? */
} while (w >= 1.0 || w == 0.0);
x = sqrt((-2.0 * log(w))/w);
/* find two independent values of y */
y1 = dev * u * x;
y2 = dev * v * x;
/****************** End of Gauss Code ****************************/
if(IT_OUT(0)) {
fprintf(stderr,"setsnr.s buffer 0 overflow\n");
return(99);
}
val=buffer_P[preambleCount];
val += y1;
out(0)=val;
preambleCount++;
}
}
if(dumpWindow && windowFull) {
// output window buffer
dumpWindow=0;
windowFull=0;
if(verbose) fprintf(stderr,"DUMPING WINDOW\n");
for(i=0; i< windowSize; i++) {
if(IT_OUT(0)) {
fprintf(stderr,"setsnr.s buffer 0 overflow\n");
return(99);
}
/****************************************************************/
/* gauss */
/* code written by Prayson Pate */
/* This code generates two random variables that are normally */
/* distributed with mean 0 and variance 1 i.e N(0,1). */
/* The polar method is used to generate normally distributed */
/* samples from a sequence that is uniform on (-1,1). The */
/* resulting distribution is described exactly by N(0,1). */
/* This method is based on the inverse distribution function. */
/****************************************************************/
trouble = 0;
do {
if(++trouble > 100) {
fprintf(stderr,"setsnr.s: problem with random number generator\n");
return(2);
}
/* get two random numbers in the interval (-1,1) */
s = random();
u = -1.0 + 2.0*(s/max);
t = random();
v = -1.0 + 2.0*(t/max);
w = u*u + v*v;
/* is point (u,v) in the unit circle? */
} while (w >= 1.0 || w == 0.0);
x = sqrt((-2.0 * log(w))/w);
/* find two independent values of y */
y1 = dev * u * x;
y2 = dev * v * x;
/****************** End of Gauss Code ****************************/
val=wbuffer_P[i];
val += y1;
out(0)=val;
} // end for loop
} // end else
break;
}
}
++count;
}
}
return(0);