Add AudioBackend::abort_stream_if_running().
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2024 14:25:52 +0000 (16:25 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 26 Jul 2024 09:39:59 +0000 (11:39 +0200)
src/wx/audio_backend.cc
src/wx/audio_backend.h
src/wx/film_viewer.cc

index b77d2cdcd278612e52862be4055bbde64a5ea5c5..ae37ab8519ac00e4d3837f70609e14486f18fc0f 100644 (file)
@@ -75,3 +75,12 @@ AudioBackend::instance()
 }
 
 
+void
+AudioBackend::abort_stream_if_running()
+{
+       if (_rtaudio.isStreamRunning()) {
+               _rtaudio.abortStream();
+       }
+}
+
+
index cf1bbad05386e58de908ed508c01ff9b5342555f..10646ebae8591c9c58ce1584740c8103f1e95165 100644 (file)
@@ -38,6 +38,7 @@ public:
                return _rtaudio;
        }
 
+       void abort_stream_if_running();
 #if (RTAUDIO_VERSION_MAJOR >= 6)
        std::string last_rtaudio_error() const;
 #endif
index f83e83c68b1feef06ab229290f32662fcaf48bb8..65e2afb56adc509f1e63bb4984e9a74c342b66b1 100644 (file)
@@ -342,11 +342,7 @@ void
 FilmViewer::suspend ()
 {
        ++_suspended;
-
-       auto& audio = AudioBackend::instance()->rtaudio();
-       if (audio.isStreamRunning()) {
-               audio.abortStream();
-       }
+       AudioBackend::instance()->abort_stream_if_running();
 }
 
 
@@ -430,12 +426,7 @@ FilmViewer::start ()
 bool
 FilmViewer::stop ()
 {
-       auto& audio = AudioBackend::instance()->rtaudio();
-
-       if (audio.isStreamRunning()) {
-               /* stop stream and discard any remaining queued samples */
-               audio.abortStream();
-       }
+       AudioBackend::instance()->abort_stream_if_running();
 
        if (!_playing) {
                return false;