From 80471025429d7a349ff94f5fd09253f4aa61398c Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Thu, 2 Jul 2020 15:19:01 +0200
Subject: [PATCH] output/osx: don't restart AudioUnit at the end of Cancel()

We shouldn't restart the AudioUnit while the ring buffer is empty, or
else our render callback may emit noise.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/771
---
 NEWS                                   | 1 +
 src/output/plugins/OSXOutputPlugin.cxx | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index cfab38190..bdc81cb38 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ ver 0.21.25 (not yet released)
   - opus: fix memory leak
 * output
   - osx: improve sample rate selection
+  - osx: fix noise while stopping
 * Windows/Android:
   - fix Boost detection after breaking change in Meson 0.54
 
diff --git a/src/output/plugins/OSXOutputPlugin.cxx b/src/output/plugins/OSXOutputPlugin.cxx
index 6d5bb3a23..bcd1008cf 100644
--- a/src/output/plugins/OSXOutputPlugin.cxx
+++ b/src/output/plugins/OSXOutputPlugin.cxx
@@ -831,7 +831,8 @@ OSXOutput::Cancel() noexcept
 #ifdef ENABLE_DSD
 	pcm_export->Reset();
 #endif
-	AudioOutputUnitStart(au);
+
+	/* the AudioUnit will be restarted by the next Play() call */
 }
 
 int