alsa的snd_pcm_readi()函数和snd_pcm_writei()
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:
-
pcm PCM handle buffer frames containing buffer size frames to be read
- Returns:
- a positive number of frames actually read otherwise a negative error code
- Return values:
-
-EBADFD PCM is not in the right state (SND_PCM_STATE_PREPARED or SND_PCM_STATE_RUNNING) -EPIPE an overrun occurred -ESTRPIPE a 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_t size
)
Write interleaved frames to a PCM.
- Parameters:
-
pcm PCM handle buffer frames containing buffer size frames to be written
- Returns:
- a positive number of frames actually written otherwise a negative error code
- Return values:
-
-EBADFD PCM is not in the right state (SND_PCM_STATE_PREPARED or SND_PCM_STATE_RUNNING) -EPIPE an underrun occurred -ESTRPIPE a suspend event occurred (stream is suspended and waiting for an application recovery)
If the non-blocking behaviour is selected, then routine doesn't wait at all.
我对ALSA录音和播音的理解,当我们通过麦克风讲话的声音搜集到声卡里之后,内存从声卡里读取声音数据的过程就是录音过程,即snd_pcm_readi()函数的执行,把内存中的声音数据写入到声卡的过程就是播音过程,即snd_pcm_writei()函数的执行。