alsa的snd_pcm_readi()函數和snd_pcm_writei()__函數

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.