/* audiop: audio playback program using the Indy audio libraries written by Jason A. Gayman */ #include #include #include #include #include long ALgetwidth(ALconfig config); int ALsetwidth(ALconfig config, long samplesize); int main(int argc, char **argv) { ALconfig Config1; ALport Port2; unsigned char samples[2000]; unsigned char tempsamples[2000]; unsigned int temp; unsigned char lookup1[256]; unsigned char lookup2[256]; float p; int i,j,k,numzeros; long buf[10]={AL_LEFT_SPEAKER_GAIN,255,AL_RIGHT_SPEAKER_GAIN,255,AL_INPUT_RATE,8000,AL_OUTPUT_RATE,8000,AL_MIC_MODE,AL_MONO}; Config1=ALnewconfig(); Port2=ALopenport("AudioPort2","w", Config1); ALsetwidth(Config1, AL_SAMPLE_16); ALsetparams(AL_DEFAULT_DEVICE,buf,10); ALsetconfig(Port2, Config1); ALsetqueuesize(Config1,100000); for (i=0;i<=255;i++) { p=(float) i; if (i<128) { temp=(int) ((exp(p*log(256)/127)-1)*32768/255); lookup1[i]=(int) temp/256; lookup2[i]=temp % 256; } else { temp=(int) (65536-((exp((256-p)*log(256)/127)-1)*32768/255)); lookup1[i]=(int) temp/256; lookup2[i]=temp % 256; } } while (1) { for (j=0;j<=506;j+=2) { samples[j]=getchar(); samples[j+1]=samples[j]; if (samples[j]==255) { numzeros=getchar(); for (k=0;k506) k=numzeros; samples[j+k*2]=0; samples[j+1+k*2]=0; } j+=(numzeros-2)*2+2; } } if (numzeros<254) { for (j=0;j<=1012;j+=4) { tempsamples[j]=lookup1[samples[j/2]]; tempsamples[j+1]=lookup2[samples[j/2]]; tempsamples[j+2]=tempsamples[j]; tempsamples[j+3]=tempsamples[j+1]; } ALwritesamps(Port2, tempsamples, 254); } } /* note: this code is never executed. */ sleep(2); ALfreeconfig(Config1); ALcloseport(Port2); exit (0); }