我有' ding.wav'来自Windows系统文件夹的文件,我正在尝试使用C ++和OpenAL来播放它。我的问题是以下代码只能通过一个耳机/扬声器播放。任何人都可以发现问题吗?当我把它放在一个新项目中时,代码工作正常,但我无法理解为什么。
alDevice = alcOpenDevice(alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER));
alContext = alcCreateContext(alDevice, NULL);
alcMakeContextCurrent(alContext);
alListener3f(AL_POSITION, 0.0f, 0, 1.0f);
alListener3f(AL_VELOCITY, 0, 0, 0);
ALfloat listenerOri[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };
alListenerfv(AL_ORIENTATION,listenerOri);
alGenSources((ALuint)1, &alSource);
alSourcef(alSource, AL_PITCH, 1);
alSourcef(alSource, AL_GAIN, 1);
alSource3f(alSource, AL_POSITION, 0, 0, 0);
alSource3f(alSource, AL_VELOCITY, 0, 0, 0);
alSourcei(alSource, AL_LOOPING, AL_FALSE);
alGenBuffers(1, &alBuffer);
alutLoadWAVFile("C:/ding.wav", &format, &data, &size, &freq, &loop);
alBufferData(alBuffer, format, data, size, freq);
alSourcei(alSource, AL_BUFFER, alBuffer);
alSourcePlay(alSource);
alGetSourcei(alSource, AL_SOURCE_STATE, &source_state);
while (source_state == AL_PLAYING) {
alGetSourcei(alSource, AL_SOURCE_STATE, &source_state);
}