我使用以下命令成功安装了 OpenAL:
yum install freealut freealut-devel
但是在此之后的问题我添加了一些 c++ 代码来使用这个库,如下所示:
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
void init_al()
{
ALCdevice *dev = NULL;
ALCcontext *ctx = NULL;
const char *defname = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
std::cout << "Default device: " << defname << std::endl;
dev = alcOpenDevice(defname);
ctx = alcCreateContext(dev, NULL);
alcMakeContextCurrent(ctx);
alGenBuffers(1, &buf);
/* Fill buffer with Sine-Wave */
freq = 1440.f;
seconds = 0.2;
sample_rate = 22050;
buf_size = 6000;
samples = new short[buf_size];
for(int i=0; i<buf_size; ++i) {
samples[i] = 32760 * sin( (2.f*float(M_PI)*freq)/sample_rate * i );
}
/* Download buffer to OpenAL */
alBufferData(buf, AL_FORMAT_MONO16, samples, buf_size, sample_rate);
/* Set-up sound source and play buffer */
src = 0;
alGenSources(1, &src);
alSourcei(src, AL_BUFFER, buf);
alGenBuffers(1, &buf);
/* Fill buffer with Sine-Wave */
freq = 1000.f;
seconds = 0.2;
sample_rate = 22050;
buf_size = 12000;
samples = new short[buf_size];
float add=1;
for(int i=0; i<buf_size; ++i) {
samples[i] = 32760 * sin( (2.f*float(M_PI)*freq)/sample_rate * i );
}
/* Download buffer to OpenAL */
alBufferData(buf, AL_FORMAT_MONO16, samples, buf_size, sample_rate);
/* Set-up sound source and play buffer */
src2 = 0;
alGenSources(1, &src2);
alSourcei(src2, AL_BUFFER, buf);
}
我认为我的问题出在可以添加到 Eclipse 项目属性中的链接器上,我包含了一个链接器alut,但它也表明存在错误。什么可能是我的问题?