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 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()函數的執行。