/* audior: audio recording program using the Indy audio libraries written by Jason A. Gayman */ #include #include #include #include #include #include long ALgetwidth(ALconfig config); int ALsetwidth(ALconfig config, long samplesize); int main(int argc, char **argv) { ALconfig Config1; ALport Port1; unsigned char samples[5000]; unsigned char lookup[65536]; int i,j,k; int bits=8,bitconst=1; /**************************/ int bit=10; int silcomp=1; /**************************/ int bitpow=1; int minlevel=225; int maxlevel=30; int mincomplen=126; unsigned int tempint; float temp; unsigned char buffer[254]; unsigned char bufferlen=0; long buf[10]={AL_LEFT_INPUT_ATTEN,120,AL_RIGHT_INPUT_ATTEN,120,AL_INPUT_RATE,8000,AL_OUTPUT_RATE,8000,AL_MIC_MODE,AL_MONO}; bitpow=pow(2,17-bit); if (silcomp==0) { minlevel=254; maxlevel=1; } Config1=ALnewconfig(); Port1=ALopenport("AudioPort1","r", Config1); ALsetwidth(Config1, AL_SAMPLE_16); ALsetparams(AL_DEFAULT_DEVICE,buf,10); ALsetconfig(Port1, Config1); ALsetqueuesize(Config1,100000); for (i=0;i<=65535;i++) { if (i<32768) { lookup[i]=(int) 127.0*log(1+255*(float)i/32768)/log(256); } else { lookup[i]=256 - (int) 127.0*log(1+255*(65536 -(float)i)/32768)/log(256); } } while (1) { ALreadsamps(Port1, samples, 254); for (j=0;j<=1012;j+=4) samples[j/2]=lookup[((int)(samples[j]*256+samples[j+1])/bitpow)*bitpow]; for (j=0;j<=506;j+=2) { if (samples[j]==255) samples[j]=0; buffer[++bufferlen]=samples[j]; if ( (j==506)||((samples[j]maxlevel)) ) { if (bufferlen>=mincomplen) { putchar(255); putchar(bufferlen); } else { for (k=1;k<=bufferlen;k++) putchar(buffer[k]); } bufferlen=0; } } } /* note: this is never executed. */ sleep(2); ALfreeconfig(Config1); ALcloseport(Port1); exit (0); }