alsa的snd_pcm_readi()函数和snd_pcm_writei()

来源:互联网 发布:网络刷手是可靠吗 编辑:程序博客网 时间:2024/06/07 19:12

snd_pcm_readi ()

snd_pcm_sframes_t snd_pcm_readi ( snd_pcm_t *pcm,

                                                             void*     buffer,

                                                            snd_pcm_uframes_t  size

                                                          )

Read interleaved frames from a PCM.

Parameters:

 pcmPCM handle bufferframes containing buffer sizeframes to be read
Returns:
a positive number of frames actually read otherwise a negative error code
Return values:
 -EBADFDPCM is not in the right state (SND_PCM_STATE_PREPARED orSND_PCM_STATE_RUNNING) -EPIPEan overrun occurred -ESTRPIPEa suspend event occurred (stream is suspended and waiting for an application recovery)

If the blocking behaviour was selected and it is running, then routine waits until all requested frames are filled. The returned number of frames can be less only if a signal or underrun occurred.

If the non-blocking behaviour is selected, then routine doesn't wait at all.

/////////////////////////////////////////////////////////////

snd_pcm_writei()

snd_pcm_sframes_t snd_pcm_writei (snd_pcm_t *pcm,

                                                  const void *buffer,

                                                 snd_pcm_uframes_tsize

                                                   )

Write interleaved frames to a PCM.

Parameters:
 pcmPCM handle bufferframes containing buffer sizeframes to be written
Returns:
a positive number of frames actually written otherwise a negative error code
Return values:
 -EBADFDPCM is not in the right state (SND_PCM_STATE_PREPARED orSND_PCM_STATE_RUNNING) -EPIPEan underrun occurred -ESTRPIPEa suspend event occurred (stream is suspended and waiting for an application recovery)
If the blocking behaviour is selected and it is running, then routine waits until all requested frames are played or put to the playback ring buffer. The returned number of frames can be less only if a signal or underrun occurred.

If the non-blocking behaviour is selected, then routine doesn't wait at all.

我对ALSA录音和播音的理解,当我们通过麦克风讲话的声音搜集到声卡里之后,内存从声卡里读取声音数据的过程就是录音过程,即snd_pcm_readi()函数的执行,把内存中的声音数据写入到声卡的过程就是播音过程,即snd_pcm_writei()函数的执行。

http://blog.csdn.net/woxiaozhi/article/details/6284099

原创粉丝点击