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_tpcm,

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM