summaryrefslogtreecommitdiff
path: root/src/wx/audio_backend.h
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.h
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.h')
-rw-r--r--src/wx/audio_backend.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/wx/audio_backend.h b/src/wx/audio_backend.h
new file mode 100644
index 000000000..cf1bbad05
--- /dev/null
+++ b/src/wx/audio_backend.h
@@ -0,0 +1,58 @@
+/*
+ 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 <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
+#include <RtAudio.h>
+LIBDCP_ENABLE_WARNINGS
+
+
+
+class AudioBackend
+{
+public:
+ AudioBackend();
+
+ AudioBackend(AudioBackend const&) = delete;
+ AudioBackend& operator=(AudioBackend const&) = delete;
+
+ RtAudio& rtaudio() {
+ return _rtaudio;
+ }
+
+#if (RTAUDIO_VERSION_MAJOR >= 6)
+ std::string last_rtaudio_error() const;
+#endif
+
+ static AudioBackend* instance();
+
+private:
+ static AudioBackend* _instance;
+
+ RtAudio _rtaudio;
+
+#if (RTAUDIO_VERSION_MAJOR >= 6)
+ void rtaudio_error_callback(std::string const& error);
+ mutable boost::mutex _last_rtaudio_error_mutex;
+ std::string _last_rtaudio_error;
+#endif
+};
+