summaryrefslogtreecommitdiff
path: root/src/wx/audio_backend.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-07-25 14:46:44 +0200
committerCarl Hetherington <cth@carlh.net>2024-07-26 11:39:59 +0200
commit051bac905d3ab8776c804e0e21fecd4c49927549 (patch)
tree07fef88f1fa0c53fca71098b63caec8589b0c9cb /src/wx/audio_backend.cc
parentc7d5e56219f39a6304be9644cc577d89be16b7de (diff)
Stop instantiating RtAudio all over the place
and instead just have a singleton. On Windows I saw a situation where the first instantiation would use ASIO and the second WASAPI, causing all kinds of confusion.
Diffstat (limited to 'src/wx/audio_backend.cc')
-rw-r--r--src/wx/audio_backend.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/wx/audio_backend.cc b/src/wx/audio_backend.cc
new file mode 100644
index 000000000..b77d2cdcd
--- /dev/null
+++ b/src/wx/audio_backend.cc
@@ -0,0 +1,77 @@
+/*
+ Copyright (C) 2024 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "audio_backend.h"
+
+
+AudioBackend* AudioBackend::_instance = nullptr;
+
+
+#ifdef DCPOMATIC_LINUX
+auto constexpr api = RtAudio::LINUX_PULSE;
+#endif
+#ifdef DCPOMATIC_WINDOWS
+auto constexpr api = RtAudio::UNSPECIFIED;
+#endif
+#ifdef DCPOMATIC_OSX
+auto constexpr api = RtAudio::MACOSX_CORE;
+#endif
+
+
+AudioBackend::AudioBackend()
+#if (RTAUDIO_VERSION_MAJOR >= 6)
+ : _rtaudio(api, boost::bind(&AudioBackend::rtaudio_error_callback, this, _2))
+#else
+ : _rtaudio(api)
+#endif
+{
+
+}
+
+
+#if (RTAUDIO_VERSION_MAJOR >= 6)
+void
+AudioBackend::rtaudio_error_callback(string const& error)
+{
+ boost::mutex::scoped_lock lm(_last_rtaudio_error_mutex);
+ _last_rtaudio_error = error;
+}
+
+string
+AudioBackend::last_rtaudio_error() const
+{
+ boost::mutex::scoped_lock lm(_last_rtaudio_error_mutex);
+ return _last_rtaudio_error;
+}
+#endif
+
+
+AudioBackend*
+AudioBackend::instance()
+{
+ if (!_instance) {
+ _instance = new AudioBackend();
+ }
+
+ return _instance;
+}
+
+