From 509423a43a5e3b1eb1a5069825532280bb8118ad Mon Sep 17 00:00:00 2001 From: clangen Date: Fri, 10 Jun 2016 00:29:45 -0700 Subject: [PATCH] Properly close the ALSA output device when stopped. Fixes a high CPU usage bug in Linux. --- src/contrib/alsaout/AlsaOut.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/contrib/alsaout/AlsaOut.cpp b/src/contrib/alsaout/AlsaOut.cpp index b079cecde..7cc021e2f 100755 --- a/src/contrib/alsaout/AlsaOut.cpp +++ b/src/contrib/alsaout/AlsaOut.cpp @@ -47,7 +47,6 @@ #define CHECK_QUIT() if (this->quit) { return; } #define PRINT_ERROR(x) std::cerr << "AlsaOut: error! " << snd_strerror(x) << std::endl; - #define WRITE_BUFFER(handle, context, samples) \ err = snd_pcm_writei(handle, context->buffer->BufferPointer(), samples); \ if (err < 0) { PRINT_ERROR(err); } @@ -165,7 +164,11 @@ void AlsaOut::Stop() { if (this->pcmHandle) { snd_pcm_drop(this->pcmHandle); - snd_pcm_prepare(this->pcmHandle); + + if (this->pcmHandle) { + snd_pcm_close(this->pcmHandle); + this->pcmHandle = NULL; + } } }