日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Qt--使用RtAudio進行錄音以及播放

Qt--使用RtAudio進行錄音以及播放

來源:程序員人生   發布時間:2016-11-21 08:32:41 閱讀次數:6435次

其實,本篇博客主要是介紹1下RtAudio,只是在qt中使用罷了!

甚么是RtAudio?
RtAudio provides a common API for realtime audio input/output across Linux (native ALSA, Jack, and OSS), Macintosh OS X (CoreAudio and Jack), and Windows(DirectSound, ASIO and WASAPI) operating systems.

官方地址:
http://www.music.mcgill.ca/~gary/rtaudio/

github地址:
https://github.com/thestk/rtaudio

下載rtaudio:
最新版本 (22 February 2016): Version 4.1.2

官方文檔利用例子:

#include "RtAudio.h" #include <iostream> #include <cstdlib> #include <cstring> int record( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData ) { if ( status ) std::cout << "Stream overflow detected!" << std::endl; // Do something with the data in the "inputBuffer" buffer. return 0; } int main() { RtAudio adc; if ( adc.getDeviceCount() < 1 ) { std::cout << "\nNo audio devices found!\n"; exit( 0 ); } RtAudio::StreamParameters parameters; parameters.deviceId = adc.getDefaultInputDevice(); parameters.nChannels = 2; parameters.firstChannel = 0; unsigned int sampleRate = 44100; unsigned int bufferFrames = 256; // 256 sample frames try { adc.openStream( NULL, &parameters, RTAUDIO_SINT16, sampleRate, &bufferFrames, &record ); adc.startStream(); } catch ( RtAudioError& e ) { e.printMessage(); exit( 0 ); } char input; std::cout << "\nRecording ... press <enter> to quit.\n"; std::cin.get( input ); try { // Stop the stream adc.stopStream(); } catch (RtAudioError& e) { e.printMessage(); } if ( adc.isStreamOpen() ) adc.closeStream(); return 0; }

Qt中的利用

功能:
1左聲道
2右聲道
3雙聲道

封裝1個類,叫ThreadRecord,在多線程中使用RrAudio,固然是繼承QThread:

class ThreadRecord :public QThread { public: ThreadRecord(); static int record(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData); bool flag; int type;//通過type進行判斷是使用左聲道、右聲道、雙聲道 protected: void run(); private: RtAudio adc; RtAudio::StreamParameters input; RtAudio::StreamParameters output; };

實現threadrecord.cc:

int ThreadRecord::record(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData) { if (status) cout << "Stream overflow detected!" << std::endl; short* output = static_cast<short*>(outputBuffer); short* input = static_cast<short*>(inputBuffer); short n = nBufferFrames; int i = *(static_cast<int*>(userData)); if(i == 2) { for (i = 0; i < nBufferFrames; i += 1) { output[i] = input[i]; } } else { for (; i < nBufferFrames; i += 2) { output[i] = input[i]; } } return 0; } void ThreadRecord::run() { //adc為成員變量:RtAudio adc_; // adc_.getDeviceCount()取得音頻裝備數量 for(int i = 0 ; i < adc_.getDeviceCount() ; i++) { qDebug()<< i << adc_.getDeviceInfo(i).name.c_str(); } if (adc_.getDeviceCount() < 1) { cout << "\nNo audio devices found!\n"; exit( 0 ); } //adc_.getDefaultInputDevice();取得默許輸入裝備 input.deviceId = adc_.getDefaultInputDevice(); input.nChannels = 2; input.firstChannel = 0; output.deviceId = adc_.getDefaultOutputDevice(); output.nChannels = 2; output.firstChannel = 0; unsigned int sampleRate = 44100; unsigned int bufferFrames = 256; try { adc_.openStream(&output, &input, RTAUDIO_SINT16, sampleRate, &bufferFrames, &record, static_cast<void*>(&type), NULL, &ErrorCallback); adc_.startStream(); } catch (RtAudioError& e) { e.printMessage(); exit(0); } while (flag); try { adc_.stopStream(); } catch (RtAudioError& e) { e.printMessage(); } if (adc_.isStreamOpen()) adc_.closeStream(); }

使用,為了節省篇幅,只寫1個函數:
type=0 左聲道
type=1 右聲道
type=2 雙聲道

void Recording::onLeftSoundButtonClicked() { if (thread_record.isRunning()) thread_record.exit(0); thread_record.flag = true; thread_record.type = 0; thread_record.start(); }

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美一区二区三区视频在线观看 | 午夜特黄 | 一区二区日韩精品 | 亚洲国产精品一区 | 国产欧美久久久久久 | 成人在线精品 | 亚洲成av人片在线观看香蕉 | 国产成人精品白浆久久69 | 国产在线一区二区三区视频 | 青青草福利视频 | 一区久久久 | 久久99精品久久久久久园产越南 | 免费在线成人av | 亚洲一区二区国产 | 人人综合 | 伊人久久视频 | 国产精品区一区二区三区 | 三级网站视频 | 美女又黄又免费的视频 | 最新亚洲| 国产亚州av | 欧美日韩不卡在线 | 综合网视频 | 欧美理论片在线 | 欧美日韩国产在线 | 国产精一区 | 日本欧美国产在线观看 | 亚洲欧美电影 | 国产精品一区久久久 | 亚洲欧洲成人 | 精品一区二区三区久久 | 国产精品成人一区二区网站软件 | 精品视频一二三区 | 国产精品1区2区3区 在线一级黄色片 | 欧美福利一区二区三区 | 亚洲午夜久久久久久久久久久 | 国产精品一区二区久久 | 国产福利免费在线观看 | 美女黄色免费网站 | 在线播放日韩 | 懂色av成人一区二区三区 |