Skip to content

Commit

Permalink
-Fix: remove clicking in SDL audio
Browse files Browse the repository at this point in the history
Instead of playing silence after a sound/voice,
the end of the sample was looping forever until another sound was played.
  • Loading branch information
miniupnp committed Feb 8, 2016
1 parent 759826c commit b93e725
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/audio/dsp_sdl.c
Expand Up @@ -20,15 +20,22 @@ static void DSP_Callback(void *userdata, Uint8 *stream, int len)
{
VARIABLE_NOT_USED(userdata);

if (s_status == 0 || s_bufferLen == 0 || s_buffer == NULL) return;
if (s_status == 0 || s_bufferLen == 0 || s_buffer == NULL) {
/* no more sample to play : */
memset(stream, 0x80, len); /* fill buffer with silence */
SDL_PauseAudio(1); /* stop playback */
return;
}

if (len <= (int)s_bufferLen) {
memcpy(stream, s_buffer, len);
s_bufferLen -= len;
s_buffer += len;
} else {
memcpy(stream, s_buffer, s_bufferLen);
memset(stream + s_bufferLen, 0x80, len - s_bufferLen); /* fill buffer end with silence */
s_bufferLen = 0;
s_buffer = NULL;
s_status = 0;
}
}
Expand Down

0 comments on commit b93e725

Please sign in to comment.