1
C++에서 OpenAL을 사용하여 클릭 이벤트에서 재생 사운드 메서드를 실행하고 릴리스 메서드에서 stop 메서드가 호출되도록하려고합니다. 내 문제는 릴리스에서 재생 중지 할 수 없다는 것입니다. 다음과 같이 사운드를 재생하기 위해 내 소스 코드는 다음과 같습니다OpenAL에서 소리 재생을 멈추는 방법
bool SoundManager::play(QString fileName, float pitch, float gain)
{
static uint sourceIndex = 0;
ALint state;
// Get the corresponding buffer id set up in the init function.
ALuint bufferID = mSoundBuffers[fileName];
if (bufferID != 0) {
// Increment which source we are using, so that we play in a "free" source.
sourceIndex = (sourceIndex + 1) % SOUNDMANAGER_MAX_NBR_OF_SOURCES;
// Get the source in which the sound will be played.
ALuint source = mSoundSources[sourceIndex];
if (alIsSource (source) == AL_TRUE) {
// Attach the buffer to an available source.
alSourcei(source, AL_BUFFER, bufferID);
if (alGetError() != AL_NO_ERROR) {
reportOpenALError();
return false;
}
// Set the source pitch value.
alSourcef(source, AL_PITCH, pitch);
if (alGetError() != AL_NO_ERROR) {
reportOpenALError();
return false;
}
// Set the source gain value.
alSourcef(source, AL_GAIN, gain);
if (alGetError() != AL_NO_ERROR) {
reportOpenALError();
return false;
}
alGetSourcei(source, AL_SOURCE_STATE, &state);
if (state!=AL_PLAYING)
alSourcePlay(source);
else if(state==AL_PLAYING)
alSourceStop(source);
if (alGetError() != AL_NO_ERROR) {
reportOpenALError();
return false;
}
}
} else {
// The buffer was not found.
return false;
}`
나는 문제가 그것을 정지해야 두 번째로, 호출 될 때, 그것은 다른 소스 있다는 것을 생각하고, 그 이유는 상태가 재생되지 않습니다. 이것이 문제라면 동일한 소스에 어떻게 액세스 할 수 있습니까?
감사합니다. 예전에 alsourcestopv로 모든 소스를 중지하는 것은 물론 불변의 소스를 시도했지만 아무 것도 작동하지 않는 것 같았습니다. –