Fix looping .wav sounds with leadin, fixes #291

If the main sound in a shader was a .wav
(soundShader->entries[0]->hardwareBuffer == true), only that sound was
played (and looped with AL_LOOPING), even if a leadin was configured.
If the main sound was an .ogg it worked.
Not it should always work.
This commit is contained in:
Daniel Gibson 2020-05-23 22:58:01 +02:00
parent e24b62d3e0
commit 5919717d05

View file

@ -1780,7 +1780,10 @@ void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSo
alSource3f( chan->openalSource, AL_POSITION, -spatializedOriginInMeters.y, spatializedOriginInMeters.z, -spatializedOriginInMeters.x );
alSourcef( chan->openalSource, AL_GAIN, ( volume ) < ( 1.0f ) ? ( volume ) : ( 1.0f ) );
}
alSourcei( chan->openalSource, AL_LOOPING, ( looping && chan->soundShader->entries[0]->hardwareBuffer ) ? AL_TRUE : AL_FALSE );
// DG: looping sounds with a leadin can't just use a HW buffer and openal's AL_LOOPING
// because we need to switch from leadin to the looped sound.. see https://github.com/dhewm/dhewm3/issues/291
bool haveLeadin = chan->soundShader->numLeadins > 0;
alSourcei( chan->openalSource, AL_LOOPING, ( looping && chan->soundShader->entries[0]->hardwareBuffer && !haveLeadin ) ? AL_TRUE : AL_FALSE );
#if 1
alSourcef( chan->openalSource, AL_REFERENCE_DISTANCE, mind );
alSourcef( chan->openalSource, AL_MAX_DISTANCE, maxd );
@ -1797,8 +1800,11 @@ void idSoundWorldLocal::AddChannelContribution( idSoundEmitterLocal *sound, idSo
}
if ( ( !looping && chan->leadinSample->hardwareBuffer ) || ( looping && chan->soundShader->entries[0]->hardwareBuffer ) ) {
if ( ( !looping && chan->leadinSample->hardwareBuffer )
|| ( looping && !haveLeadin && chan->soundShader->entries[0]->hardwareBuffer ) ) {
// handle uncompressed (non streaming) single shot and looping sounds
// DG: ... that have no leadin (with leadin we still need to switch to another sound,
// just use streaming code for that) - see https://github.com/dhewm/dhewm3/issues/291
if ( chan->triggered ) {
alSourcei( chan->openalSource, AL_BUFFER, looping ? chan->soundShader->entries[0]->openalBuffer : chan->leadinSample->openalBuffer );
}