日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言调用话筒的程序,c – OpenAL:如何创建简单的“麦克风回声”程序?

發布時間:2023/12/2 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言调用话筒的程序,c – OpenAL:如何创建简单的“麦克风回声”程序? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一個古老的問題,但這是一個答案.如果我們真的想要簡潔,它肯定可以修剪,但這有點不到100條有效線:

#include // OpenAL header files

#include

#include

using std::list;

#define FREQ 22050 // Sample rate

#define CAP_SIZE 2048 // How much to capture at a time (affects latency)

int main(int argC,char* argV[])

{

list bufferQueue; // A quick and dirty queue of buffer objects

ALenum errorCode=0;

ALuint helloBuffer[16], helloSource[1];

ALCdevice* audioDevice = alcOpenDevice(NULL); // Request default audio device

errorCode = alcGetError(audioDevice);

ALCcontext* audioContext = alcCreateContext(audioDevice,NULL); // Create the audio context

alcMakeContextCurrent(audioContext);

errorCode = alcGetError(audioDevice);

// Request the default capture device with a half-second buffer

ALCdevice* inputDevice = alcCaptureOpenDevice(NULL,FREQ,AL_FORMAT_MONO16,FREQ/2);

errorCode = alcGetError(inputDevice);

alcCaptureStart(inputDevice); // Begin capturing

errorCode = alcGetError(inputDevice);

alGenBuffers(16,&helloBuffer[0]); // Create some buffer-objects

errorCode = alGetError();

// Queue our buffers onto an STL list

for (int ii=0;ii<16;++ii) {

bufferQueue.push_back(helloBuffer[ii]);

}

alGenSources (1, &helloSource[0]); // Create a sound source

errorCode = alGetError();

short buffer[FREQ*2]; // A buffer to hold captured audio

ALCint samplesIn=0; // How many samples are captured

ALint availBuffers=0; // Buffers to be recovered

ALuint myBuff; // The buffer we're using

ALuint buffHolder[16]; // An array to hold catch the unqueued buffers

bool done = false;

while (!done) { // Main loop

// Poll for recoverable buffers

alGetSourcei(helloSource[0],AL_BUFFERS_PROCESSED,&availBuffers);

if (availBuffers>0) {

alSourceUnqueueBuffers(helloSource[0],availBuffers,buffHolder);

for (int ii=0;ii

// Push the recovered buffers back on the queue

bufferQueue.push_back(buffHolder[ii]);

}

}

// Poll for captured audio

alcGetIntegerv(inputDevice,ALC_CAPTURE_SAMPLES,1,&samplesIn);

if (samplesIn>CAP_SIZE) {

// Grab the sound

alcCaptureSamples(inputDevice,buffer,CAP_SIZE);

//***** Process/filter captured data here *****//

//for (int ii=0;ii

// buffer[ii]*=0.1; // Make it quieter

//}

// Stuff the captured data in a buffer-object

if (!bufferQueue.empty()) { // We just drop the data if no buffers are available

myBuff = bufferQueue.front(); bufferQueue.pop_front();

alBufferData(myBuff,AL_FORMAT_MONO16,buffer,CAP_SIZE*sizeof(short),FREQ);

// Queue the buffer

alSourceQueueBuffers(helloSource[0],1,&myBuff);

// Restart the source if needed

// (if we take too long and the queue dries up,

// the source stops playing).

ALint sState=0;

alGetSourcei(helloSource[0],AL_SOURCE_STATE,&sState);

if (sState!=AL_PLAYING) {

alSourcePlay(helloSource[0]);

}

}

}

}

// Stop capture

alcCaptureStop(inputDevice);

alcCaptureCloseDevice(inputDevice);

// Stop the sources

alSourceStopv(1,&helloSource[0]);

for (int ii=0;ii<1;++ii) {

alSourcei(helloSource[ii],AL_BUFFER,0);

}

// Clean-up

alDeleteSources(1,&helloSource[0]);

alDeleteBuffers(16,&helloBuffer[0]);

errorCode = alGetError();

alcMakeContextCurrent(NULL);

errorCode = alGetError();

alcDestroyContext(audioContext);

alcCloseDevice(audioDevice);

return 0;

}

總結

以上是生活随笔為你收集整理的c语言调用话筒的程序,c – OpenAL:如何创建简单的“麦克风回声”程序?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。