# 廣播 ## 小組成員與負責事項 - 108321036 莊才賢(portaudio) - 108321038 丘世宇(socket) ## 程式說明 ### portaudio 聲音擷取 * 初始化要 callback 的data(recordSamples、currentSoundIdx)、現在傳送的 Frame 的 index(currentSendFrameIdx) * 初始化 stream,並開啟 stream * main 會用 while(1) 偵測 currentSendFrameIdx != data.currentSoundIdx,推斷是否需要發送 #### 程式架構 ![](https://i.imgur.com/lC9RMvv.png) #### portaudio 聲音擷取流程 1. ![t](https://i.imgur.com/2bQOmYN.png) 1. ![t](https://i.imgur.com/MHOcatL.png) 1. ![t](https://i.imgur.com/MTSpY9T.png) <style> img[alt="t"]{ width: 50% } </style> ### portaudio 聲音播出 * 初始化要 callback 的data(recordSamples、currentSoundIdx)、現在傳送的 Frame 的 index(currentGetFrameIdx) * 初始化 stream,並開啟 stream * main 會用 while(1) 偵測 currentSendFrameIdx != data.currentSoundIdx,推斷是否需要接收 #### 程式架構 ![](https://i.imgur.com/nbFPmFQ.png) #### portaudio 聲音擷取流程 1. ![t](https://i.imgur.com/fYqH7AM.png) 1. ![t](https://i.imgur.com/dSAzuze.png) 1. ![t](https://i.imgur.com/FuNgKaa.png) 1. ![t](https://i.imgur.com/6Tzvqt8.png) ### socket #### speaker - 等待 listener 連線 - 若有資料可發送 就將資料分送給所有連接的 listener #### listener - 連上 speaker 後用 while(1) 中寫著 recv 等待 speaker 傳資料過來 ## 遭遇問題 - 如何 include 外部 library - 右鍵 solution explorer > solution - 左鍵 properities - C/C++ > General > Addition Include Directory 放入有 .h 檔的路徑 - Linker > Input> Addition dependencies 放入 .lib 檔的路徑 - 在執行 exe 的目錄底下放 portaudio.dll - 如果在 callback function 裡面放入 socket 程式,聲音會變很奇怪,callback function 裡面感覺只能放不會延遲太久的計算 - 改成放到 main 進行傳送/接收 - 對 socket 概念不熟,程式邏輯改了又改 - 多查多看,想辦法把想法畫成圖