/* My code using the ALSA Asynchronous playback wiki */ #include #include #include #include #include #include #define SIZE 126976 /*Global Variables */ int err; const char *device_name = "default"; int main() { snd_pcm_t *pcm_handle; unsigned int rrate = 16000; int fd1,count,bytesread=1,a,err,frames,i,size=SIZE,temp; short int buffer[SIZE]; char d; char errstr[50]; snd_pcm_uframes_t buffer_size = 1024; snd_pcm_uframes_t period_size = 64; snd_pcm_hw_params_t *hw_params; snd_pcm_sw_params_t *sw_params; if((fd1=open("orig.wav",O_RDONLY,0))==-1) { printf("error opening file\n"); return -1; } for(count=0;count<44;count++) { a=read(fd1,&d,sizeof(char)); //first 40 bytes of the wav file } count=0; while(bytesread >0 && count(2*period_size)) { frames = snd_pcm_writei (pcm_handle, buffer, size); printf("frames returned is %d\n",frames); if (frames>0) temp=frames; if (frames == -32){ frames = snd_pcm_recover(pcm_handle, frames, 0); printf("recover returned %d\n",frames); } if (frames < 0){ printf("snd_pcm_writei failed: %s\n", snd_strerror(frames)); return -1; } printf("%d frames written\n",frames); if(temp>0) size=size-temp; } snd_pcm_close (pcm_handle); return 0; }