Skip to content

Commit

Permalink
Fix looping sounds sync with OpenAL.
Browse files Browse the repository at this point in the history
Not a perfect solution since it depends on a race condition. But happens
to work well with OpenAL Soft.

Fixes NVIDIA#86.
  • Loading branch information
skullernet committed Dec 1, 2014
1 parent 90a60c2 commit 50cfea8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/client/sound/al.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static channel_t *AL_FindLoopingSound(int entnum, sfx_t *sfx)
continue;
if (!ch->autosound)
continue;
if (ch->entnum != entnum)
if (entnum && ch->entnum != entnum)
continue;
if (ch->sfx != sfx)
continue;
Expand All @@ -257,7 +257,7 @@ static void AL_AddLoopSounds(void)
{
int i;
int sounds[MAX_EDICTS];
channel_t *ch;
channel_t *ch, *ch2;
sfx_t *sfx;
sfxcache_t *sc;
int num;
Expand Down Expand Up @@ -295,6 +295,8 @@ static void AL_AddLoopSounds(void)
if (!ch)
continue;

ch2 = AL_FindLoopingSound(0, sfx);

ch->autosound = qtrue; // remove next frame
ch->autoframe = s_framecount;
ch->sfx = sfx;
Expand All @@ -304,6 +306,14 @@ static void AL_AddLoopSounds(void)
ch->end = paintedtime + sc->length;

AL_PlayChannel(ch);

// attempt to synchronize with existing sounds of the same type
if (ch2) {
ALint offset;

qalGetSourcei(ch2->srcnum, AL_SAMPLE_OFFSET, &offset);
qalSourcei(ch->srcnum, AL_SAMPLE_OFFSET, offset);
}
}
}

Expand Down

0 comments on commit 50cfea8

Please sign in to comment.