Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int
- alsa_write_float (snd_pcm_t *alsa_dev, float *data, int frames, int channels)
- { static int epipe_count = 0 ;
- int total = 0 ;
- int retval ;
- if (epipe_count > 0)
- epipe_count -- ;
- while (total < frames) {
- retval = snd_pcm_writei (alsa_dev, data + total * channels, frames - total) ;
- if (retval >= 0) {
- total += retval ;
- if (total == frames)
- return total ;
- continue ;
- } ;
- switch (retval)
- { case -EAGAIN :
- puts ("alsa_write_float: EAGAIN") ;
- continue ;
- break ;
- case -EPIPE :
- if (epipe_count > 0)
- { printf ("alsa_write_float: EPIPE %d\n", epipe_count) ;
- if (epipe_count > 140)
- return retval ;
- } ;
- epipe_count += 100 ;
- #if 0
- if (0)
- { snd_pcm_status_t *status ;
- snd_pcm_status_alloca (&status) ;
- if ((retval = snd_pcm_status (alsa_dev, status)) < 0)
- fprintf (stderr, "alsa_out: xrun. can't determine length\n") ;
- else if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN)
- { struct timeval now, diff, tstamp ;
- gettimeofday (&now, 0) ;
- snd_pcm_status_get_trigger_tstamp (status, &tstamp) ;
- timersub (&now, &tstamp, &diff) ;
- fprintf (stderr, "alsa_write_float xrun: of at least %.3f msecs. resetting stream\n",
- diff.tv_sec * 1000 + diff.tv_usec / 1000.0) ;
- }
- else
- fprintf (stderr, "alsa_write_float: xrun. can't determine length\n") ;
- } ;
- #endif
- snd_pcm_prepare (alsa_dev) ;
- break ;
- case -EBADFD :
- fprintf (stderr, "alsa_write_float: Bad PCM state.n") ;
- return 0 ;
- break ;
- case -ESTRPIPE :
- fprintf (stderr, "alsa_write_float: Suspend event.n") ;
- return 0 ;
- break ;
- case -EIO :
- puts ("alsa_write_float: EIO") ;
- return 0 ;
- default :
- fprintf (stderr, "alsa_write_float: retval = %d\n", retval) ;
- return 0 ;
- break ;
- } ; /* switch */
- } ; /* while */
- return total ;
- } /* alsa_write_float */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement