C ++で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;
}`
問題は、2回目に呼び出されたときに停止する必要があるときに、別のソースであり、その状態が再生されていないことだと思います。これが問題である場合、どうすれば同じソースにアクセスできますか?