大佬教程收集整理的这篇文章主要介绍了音频 – C特定声音输出?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用C播放特定频率的声音?
可能?
您需要生成一个包含代表所需输出的PCM编码数据的数组,然后使用所需的采样频率和格式调用阵列上的alBufferData().有关alBufferData()函数所需的格式,请参见OpenAL Programmers Guide的第21页.
例如,以下@L_675_12@播放100hz音调.
#include <iostream> #include <cmath> #include <al.h> #include <alc.h> #include <AL/alut.h> #pragma comment(lib,"OpenAL32.lib") #pragma comment(lib,"alut.lib") int main(int argc,char** argv) { aluTinit(&argc,argv); alGetError(); ALuint buffer; alGenBuffers(1,&buffer); { // CreaTing a buffer that hold about 1.5 seconds of audio data. char data[32 * 1024]; for (int i = 0; i < 32 * 1024; ++i) { // get a value in thE interval [0,1) over the length of a second float intervalPerSecond = static_cast<float>(i % 22050) / 22050.0f; // increase the frequency to 100hz float intervalPerHundreth = fmod(intervalPerSecond * 100.0f,1.0f); // translate to thE interval [0,2PI) float x = intervalPerHundreth * 2 * 3.14159f; // and then convert BACk to thE interval [0,255] for our amplitude data. data[i] = static_cast<char>((sin(X) + 1.0f) / 2.0f * 255.0f); } alBufferData(buffer,AL_FORMAT_MONO8,data,32 * 1024,22050); } ALuint source; alGensources(1,&sourcE); alsourcei(source,AL_BUFFER,buffer); alsourcePlay(sourcE); system("pause"); alsourceStop(sourcE); aldeletesources(1,&sourcE); aldeleteBuffers(1,&buffer); alutExit(); return 0; }
以上是大佬教程为你收集整理的音频 – C特定声音输出?全部内容,希望文章能够帮你解决音频 – C特定声音输出?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。