Skip to content

Commit 961edc3

Browse files
SiegeLordExSiegeLord
authored andcommitted
Send PulseAudio silence if the attached mixer is stopped.
Fixes #1445
1 parent 88ba729 commit 961edc3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

addons/audio/pulseaudio.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ static void *pulseaudio_update(ALLEGRO_THREAD *self, void *data)
190190
PULSEAUDIO_VOICE *pv = voice->extra;
191191
(void)self;
192192

193+
void* silence = al_malloc(pv->buffer_size_in_frames * pv->frame_size_in_bytes);
194+
al_fill_silence(silence, pv->buffer_size_in_frames, voice->depth, voice->chan_conf);
195+
193196
for (;;) {
194197
enum PULSEAUDIO_VOICE_STATUS status;
195198

@@ -208,10 +211,12 @@ static void *pulseaudio_update(ALLEGRO_THREAD *self, void *data)
208211
if (voice->is_streaming) {
209212
// streaming audio
210213
const void *data = _al_voice_update(voice, voice->mutex, &frames);
211-
if (data) {
212-
pa_simple_write(pv->s, data,
213-
frames * pv->frame_size_in_bytes, NULL);
214+
if (!data) {
215+
data = silence;
216+
frames = pv->buffer_size_in_frames;
214217
}
218+
pa_simple_write(pv->s, data,
219+
frames * pv->frame_size_in_bytes, NULL);
215220
}
216221
else {
217222
// direct buffer audio
@@ -246,6 +251,7 @@ static void *pulseaudio_update(ALLEGRO_THREAD *self, void *data)
246251
al_unlock_mutex(voice->mutex);
247252
}
248253
}
254+
al_free(silence);
249255

250256
return NULL;
251257
}

0 commit comments

Comments
 (0)