OpenAL:如何创建简单的“麦克风回声”程序?

所以我想知道什么是最短的(在有效线路方面)打开AL代码从默认麦克风读取数据并输出到默认扬声器?

我正在Visual Studio 2008下的Windows 7上进行开发

一个古老的问题,但这是一个答案。 如果我们真的想要简洁,它肯定可以修剪,但这有点不到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;iiCAP_SIZE) { // Grab the sound alcCaptureSamples(inputDevice,buffer,CAP_SIZE); //***** Process/filter captured data here *****// //for (int ii=0;ii