一个古老的问题,但这是一个答案.如果我们真的想要简洁,它肯定可以修剪,但这有点不到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:如何创建简单的“麦克风回声”程序?相关推荐

  1. mysql怎么创建窗口应用程序,使用 MySQL 数据库创建简单的 Web 应用程序

    index.jsp 要在 index.jsp 中动态显示窗体的内容,您需要从 Subject 数据库表访问所有 name. 将鼠标悬停在 "Palette"(组件面板)中的 &qu ...

  2. 使用 Amazon Amplify快速创建简单的 Android 应用程序

    背景: 亚马逊云科技提供了100余种产品免费套餐.其中,计算资源Amazon EC2首年12个月免费,750小时/月:存储资源 Amazon S3 首年12个月免费,5GB标准存储容量. 大家好,我是 ...

  3. 使用Visual Studio 2010 创建简单的Silverlight应用程序

    使用Visual Studio 2010 创建简单的Silverlight应用程序 Silverlight是创建动态的引人的RIAs(Rich Internet Application)的新方法.这里 ...

  4. jsp创建mysql数据库_使用 MySQL 数据库创建简单的 JSP 应用程序(1)

    使用 MySQL 数据库创建简单的 Web 应用程序 编写人:Troy Giunipero 本文档描述了如何创建用于连接 MySQL 数据库服务器的简单 Web 应用程序.还讲述了 Web 开发中的一 ...

  5. zblog小程序导航主题模板,简单好用小程序商城主题设置方法

    小程序现在非常的火爆,大家的手游内存是有限的,无需下载的小程序就能为大家提供和app相同的服务,非常的受欢迎.不过由于小程序数量太多,怎么才能顺利找到想要找到的小程序呢?小程序导航站就应运而生,如何做 ...

  6. 小程序公共封装ajax,超简单 Promise封装小程序ajax 超好用 以及封装登录

    //网络类 //封装网络请求 const ajax = (ajaxData, method) => { wx.showLoading({ title: '加载中', mask: true }); ...

  7. 创建简单的APAP/4程序

    1.命名程序: 要创建ABAP/4程序,步骤如下: 在"SAP R/3"初始屏幕上选择"工具->ABAP/4工作台".出现"ABAP/4开发工作 ...

  8. c语言调用话筒的程序,如何在ubuntu中用c语言打开麦克风

    满意答案 jqyong007 2016.08.26 采纳率:53%    等级:9 已帮助:418人 1234567891011121314151617181920212223242526272829 ...

  9. C语言调用函数一次就自动结束了 不执行下面的程序 帮忙看看把

    我自己定义了一个打印print函数 ,在主程序中如果把这个print函数放在其他函数前执行了 程序直接就运行结束了 不执行在他后面的程序 .有人能看看这是什么原因吗?

最新文章

  1. Java EE---使用Spring框架创建Market小项目
  2. mcs 4微型计算机,MCS-II高性能自主品牌的微机测速仪
  3. CDQZ集训DAY8 日记
  4. python中的format什么意思中文-Python中format的用法
  5. jvm类加载、初始化
  6. 【windows】CMake安装小结
  7. make、make是什么??
  8. [实战演练]2014年人人公司应届生校招技术笔试题
  9. 如何将网站升级为HTTPS协议(整理)
  10. 勒索软件再次降临 教育网为什么成为重灾区
  11. json string 格式_Retrofit同时解析JSON和XML数据格式
  12. 无人机底层开发-MPU6050+磁力计的四元数解算姿态
  13. Windows驱动开发WDM
  14. “衣带渐宽终不悔,为伊消得人憔悴”的赏析
  15. 【AiLearning】test3:搭建Deep Netural Network
  16. 基于MATLAB的分子动力学自编程序—300K下Ar的分子运动
  17. 若依框架(Ruoyi-vue)上传视频且回显
  18. 基于 TCP协议和sqlite3数据库的网络电子词典(个人项目)
  19. 《阁夜》杜甫:岁暮阴阳催短景,天涯霜雪霁寒宵。
  20. 模块化-CMJESM

热门文章

  1. 电源模块的6个优势及其作用
  2. linux查看用户的操作记录,Linux下查看用户登陆后的操作记录
  3. mysql group原理_MySQL Group By 实现原理分析
  4. matlab simulink_MATLAB之Simulink(二)利用switch模块将正弦信号变为方波信号
  5. 2018安徽省计算机一级试题答案,2018年计算机等一级考试试题100题及参考答案.docx...
  6. 关于数据可视化页面制作
  7. element table 组件内容换行方案
  8. 初进JAVA职场面试小技巧:一个老学长的吐血之作!
  9. DHCP服务(dhcpd)
  10. Java bean 是个什么概念?