getbit() { int length=0; do length++; while (getsample()==1); do length++; while (getsample()==0); return length<3 ? 1 : 0; }
int main(int argc, char *argv[]) { int numbers[10]; getsample(numbers, 10); heapsort_iterative(numbers, 10); return 0; }
void fill_audio(void *udata, uint8_t *stream, int len) { int i; if (len > bsize) len = bsize; for(i = 0; i<len; i++) buf[i] = getsample(); SDL_MixAudio(stream, buf, len, SDL_MIX_MAXVOLUME); }
int state10(void) { unsigned char RecBuf[2]; char v=1; int otime,ctime; unsigned char Data_next; int Control=0; serialinit(); initAudio(); initCompr(); /* Synch with PC... */ serialtransmit('A'); otime=10000000; starttimer(SAMPLE_DELAY); ctime=gettimer(); while ( otime > ctime ) { otime=ctime; ctime=gettimer(); } RecBuf[0] = (getsample()); otime=1000; while (1) { /*starttimer(SAMPLE_DELAY);*/ while ( otime > (otime= gettimer() > 0) ); RecBuf[v] = (getsample()); if (v) { Control = compress(RecBuf[0],RecBuf[1]); } else { Control = serialtransmit(Control); if (Control) { serialclose(); return Control; } } v=1-v; } }
static int getamp(double *ambuff, int nb) { #define BLKIN 4096 static short inbuff[2*BLKIN]; int n,ns; static double PhaseOsc = 0.0; static double mamp=0.5; double amp; double DPhi; #define DFc 50.0 ns=getsample(inbuff, nb > BLKIN ? BLKIN : nb); for (n = 0; n < ns; n++) { double in; in=((double)inbuff[n*nbch+nch]/32768.0); mamp=AGCK*mamp+(1.0-AGCK)*fabs(in); amp=2.0*in*cos(PhaseOsc); ambuff[n] = amp; //fprintf(stderr,"%g %g %g\n",in,cos(PhaseOsc),amp); /* delta phase */ DPhi=-in/(mamp*M_SQRT2)*(sin(PhaseOsc)-sin(3.0*PhaseOsc)); /* loop filter */ PhaseOsc += 2.0 * M_PI * (DPLL_C2 * DPhi + FreqOsc); if (PhaseOsc > M_PI) PhaseOsc -= 2.0 * M_PI; if (PhaseOsc <= -M_PI) PhaseOsc += 2.0 * M_PI; FreqOsc += DPLL_C1 * DPhi; if (FreqOsc > ((Fc + DFc) / Fe)) FreqOsc = (Fc + DFc) / Fe; if (FreqOsc < ((Fc - DFc) / Fe)) FreqOsc = (Fc - DFc) / Fe; } return (ns); }
/* * Return next pre-emphasized signal frame from input stream. * Return 0 if no frames can be read and 1 otherwise. * * NOTE: the frame sample buffer s *must* be kept untouched between two successive calls. */ int get_next_sig_frame(sigstream_t *f, int ch, int l, int d, float a, sample_t *s) { static double prev = 0.0; /* pre-emphasis filter memory */ static unsigned long bp = 0; /* current position in the stream buffer */ unsigned long nread; /* number of samples read in buffer */ unsigned short i, j; void *p; double v; /* channel sanity check */ if (ch < 1 || ch > f->nchannels) return(0); if (f->nread == 0) { /* first call ==> we have to read completely the first frame */ bp = 0; prev = 0.0; j = 0; } else /* next calls ==> reuse l-d samples and add d new samples */ for (i = d, j = 0; i < l; i++, j++) *(s+j) = *(s+i); /* memmove should be much faster */ nread = 1; /* ugly trick to get into the while loop ;) */ p = f->buf->s + (ch - 1) * f->nbps; while (j < l && nread) { if (bp == f->buf->n) { /* this means buffer is empty! */ nread = sig_stream_read(f); bp = 0; } if (nread) while (j < l && bp < f->buf->n) { v = getsample(p, bp, f->nbps); *(s+j) = (sample_t)(v - a * prev); prev = v; j++; bp += f->nchannels; } else /* we failed to read additionnal samples */ return(0); } return(1); }