Skip to content

Commit

Permalink
faudio: Fix XNA_GetSongEnded false positives
Browse files Browse the repository at this point in the history
Now that we release buffer lock before executing callbacks, some code
from another thread can get scheduled between mutex unlock and callback
call and observe empty buffer queue right before callback puts a new
buffer there. XNA_Song determines the end of the song by simply checking
if the queue is empty, which may lead to random playback breaks.

Not sure how to properly check for the song end but the buffer decoding
function also zeroes out total samples counter when it finishes a
EOS-flagged buffer so checking if that counter is zero should cut it...
probably?
  • Loading branch information
anonymous authored and flibitijibibo committed May 11, 2024
1 parent c2ef8d3 commit f68e150
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/FAudio_platform_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ FAUDIOAPI uint32_t XNA_GetSongEnded()
return 1;
}
FAudioSourceVoice_GetState(songVoice, &state, 0);
return state.BuffersQueued == 0;
return state.BuffersQueued == 0 && state.SamplesPlayed == 0;
}

FAUDIOAPI void XNA_EnableVisualization(uint32_t enable)
Expand Down
2 changes: 1 addition & 1 deletion src/XNA_Song.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ FAUDIOAPI uint32_t XNA_GetSongEnded()
return 1;
}
FAudioSourceVoice_GetState(songVoice, &state, 0);
return state.BuffersQueued == 0;
return state.BuffersQueued == 0 && state.SamplesPlayed == 0;
}

FAUDIOAPI void XNA_EnableVisualization(uint32_t enable)
Expand Down

0 comments on commit f68e150

Please sign in to comment.