I can capture sound to a file from a C program. I can play from the file. But
when i try to playback captured audio directly I get many errors. My code is

   while (1) {
    int nread;
    if ((nread = snd_pcm_readi (capture_handle, buf, BUF_SIZE)) != BUF_SIZE) {
    //if ((nread = snd_pcm_readi (capture_handle, buf, can_read)) != can_read) {
      fprintf (stderr, "read from audio interface failed (%s)\n",
               snd_strerror (nread));
      print_pcm_state(capture_handle, "capture");
      snd_pcm_prepare(capture_handle);
      print_pcm_state(capture_handle, "capture");
      continue;
    }
        
    printf("copying %d\n", nread);

    if ((err = snd_pcm_writei (playback_handle, buf, nread)) != nread) {
      fprintf (stderr, "write to audio interface failed (%s)\n",
               snd_strerror (err));
      //exit (1);
      print_pcm_state(playback_handle, "playback");
      snd_pcm_prepare(playback_handle);
      print_pcm_state(playback_handle, "playback");
    }
    printf("Wrote %d frames\n", err);
    
  }

I get the output 

copying 2048
Wrote 2048 frames
read from audio interface failed (No such device)
state xrun capture
state prepare capture
copying 2048
write to audio interface failed (Broken pipe)
state xrun playback
state prepare playback
Wrote -32 frames
copying 2048
Wrote 2048 frames
read from audio interface failed (Read-only file system)
state xrun capture
state prepare capture
copying 2048

Both devices are set to 44khz, stereo, 16 bit interleaved with two periods per
buffer, buffer size 2048 frames. I'm obviously doing something wrong, but don't
know what.




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user

Reply via email to