添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using ASLA Audio API for playing sound in my embedded linux application. Am observing at times that the snd_pcm_writei API returns –EPIPE error and when that error happens I call snd_pcm_prepare (that basically prepares PCM for re-use).

if ((err = snd_pcm_writei (playback_handle, buf, nframes)) < 0) 
    if ((err = snd_pcm_prepare (playback_handle)) < 0)
    return err;

I found some suggestions that instead of snd_pcm_prepare using snd_pcm_recover should be the correct approach in this instance. Before trying the fix I just wanted to know if anybody can help me out in understanding how we to set the PCM device to recover from the underrun or other errors that can happen during write.

The snd_pcm_recover() function handles more error codes, so you should use it. But it ends up calling snd_pcm_prepare() anyway (see the source code).

There's nothing really special about snd_pcm_prepare(); it's just the simplest way of reinitializing the stream.

I have a doubt: is it required that we call snd_pcm_close() after every time we call snd_pcm_drain() ?? – user12345 Jun 11, 2015 at 11:24 Calling snd_pcm_close() is always required. You need snd_pcm_drain() only to ensure that the remaining samples in the buffer are played. – CL. Jun 11, 2015 at 11:33 In my application am calling snd_pcm_open() only once during the initialization. And whenever I see snd_pcm_writei() return -EPIPE or some error I will do snd_pcm_prepare() and snd_pcm_close(). And I feel since i dont call snd_pcm_open() again while application is running. I am facing some issue. After reading through web, I found that snd_pcm_drop() should also work similar to snd_pcm_close(). Please suggest me if that is correct. – user12345 Jun 11, 2015 at 11:43 snd_pcm_drain(): For playback wait for all pending frames to be played and then stop the PCM. snd_pcm_drain() is it a blocking call ? And If I set the mode of open device as SND_PCM_NONBLOCK in snd_pcm_open() - does it be a non blocking call for snd_pcm_drain(). ? – user12345 Jun 16, 2015 at 14:06

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.