Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2010
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. static int
  2. alsa_write_float (snd_pcm_t *alsa_dev, float *data, int frames, int channels)
  3. { static int epipe_count = 0 ;
  4.  
  5. int total = 0 ;
  6. int retval ;
  7.  
  8. if (epipe_count > 0)
  9. epipe_count -- ;
  10.  
  11. while (total < frames) {
  12. retval = snd_pcm_writei (alsa_dev, data + total * channels, frames - total) ;
  13.  
  14. if (retval >= 0) {
  15. total += retval ;
  16. if (total == frames)
  17. return total ;
  18.  
  19. continue ;
  20. } ;
  21.  
  22. switch (retval)
  23. { case -EAGAIN :
  24. puts ("alsa_write_float: EAGAIN") ;
  25. continue ;
  26. break ;
  27.  
  28. case -EPIPE :
  29. if (epipe_count > 0)
  30. { printf ("alsa_write_float: EPIPE %d\n", epipe_count) ;
  31. if (epipe_count > 140)
  32. return retval ;
  33. } ;
  34. epipe_count += 100 ;
  35.  
  36. #if 0
  37. if (0)
  38. { snd_pcm_status_t *status ;
  39.  
  40. snd_pcm_status_alloca (&status) ;
  41. if ((retval = snd_pcm_status (alsa_dev, status)) < 0)
  42. fprintf (stderr, "alsa_out: xrun. can't determine length\n") ;
  43. else if (snd_pcm_status_get_state (status) == SND_PCM_STATE_XRUN)
  44. { struct timeval now, diff, tstamp ;
  45.  
  46. gettimeofday (&now, 0) ;
  47. snd_pcm_status_get_trigger_tstamp (status, &tstamp) ;
  48. timersub (&now, &tstamp, &diff) ;
  49.  
  50. fprintf (stderr, "alsa_write_float xrun: of at least %.3f msecs. resetting stream\n",
  51. diff.tv_sec * 1000 + diff.tv_usec / 1000.0) ;
  52. }
  53. else
  54. fprintf (stderr, "alsa_write_float: xrun. can't determine length\n") ;
  55. } ;
  56. #endif
  57.  
  58. snd_pcm_prepare (alsa_dev) ;
  59. break ;
  60.  
  61. case -EBADFD :
  62. fprintf (stderr, "alsa_write_float: Bad PCM state.n") ;
  63. return 0 ;
  64. break ;
  65.  
  66. case -ESTRPIPE :
  67. fprintf (stderr, "alsa_write_float: Suspend event.n") ;
  68. return 0 ;
  69. break ;
  70.  
  71. case -EIO :
  72. puts ("alsa_write_float: EIO") ;
  73. return 0 ;
  74.  
  75. default :
  76. fprintf (stderr, "alsa_write_float: retval = %d\n", retval) ;
  77. return 0 ;
  78. break ;
  79. } ; /* switch */
  80. } ; /* while */
  81.  
  82. return total ;
  83. } /* alsa_write_float */
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement