2010-11-22 23 views
0

我想用PortAudio庫來播放音頻數據。這個音頻數據來自UDP paquets。如何從UPD paquets打開流?

我看到有Pa_OpenDefaultStream()(和Pa_OpenStream(),這是非常相似)函數打開流:

PaStream *stream; 
PaError err; 
/* Open an audio I/O stream. */ 
err = Pa_OpenDefaultStream(&stream, 
          0,   /* no input channels */ 
          2,   /* stereo output */ 
          paFloat32, /* 32 bit floating point output */ 
          SAMPLE_RATE, 
          256,  /* frames per buffer, i.e. the number 
               of sample frames that PortAudio will 
               request from the callback. Many apps 
               may want to use 
               paFramesPerBufferUnspecified, which 
               tells PortAudio to pick the best, 
               possibly changing, buffer size.*/ 
          patestCallback, /* this is your callback function */ 
          &data); /*This is a pointer that will be passed to 
               your callback*/ 

我想我必須用它來打我的paquets但我不知道如何使用它:

  • 什麼是第一個參數?
  • 爲什麼我必須定義回調函數?

這裏是對PortAudio文檔的鏈接:http://www.portaudio.com/trac/

任何幫助,將不勝感激:)

感謝。

回答

1

第一個參數是指向PaStream類型的輸入/輸出流的指針。音頻數據將從此流讀取/寫入。

您需要編寫一個回調函數,PortAudio庫將在需要從PC讀取音頻或將音頻寫入PC時調用該函數。任何其他您想要做的音頻處理(例如DSP)也將在這裏完成。一個簡單的回調函數只會將輸入複製到輸出,用於流式I/O。如果您在使用回調時遇到問題,請改用Blocking API,這可能會更容易理解。

編譯並運行這些示例以獲取詳細信息(例如,patest_read_record.c),以及那裏的大量信息。

+0

你會如何編寫一個「簡單的回調函數」?我很願意編碼(錄音時聽音頻)。謝謝 – 2010-11-25 00:56:35