diff options
| author | 2022-09-10 21:14:03 +0100 | |
|---|---|---|
| committer | 2022-09-13 13:20:35 +0100 | |
| commit | e93e898df528d013e2e0cfeba22e2b6d76bf99b6 (patch) | |
| tree | ab921a035ce71311c126a1af7cb2bbcbfef6d024 /src/audio_core/sink | |
| parent | Merge pull request #8842 from Kelebek1/AudOut (diff) | |
| download | yuzu-e93e898df528d013e2e0cfeba22e2b6d76bf99b6.tar.gz yuzu-e93e898df528d013e2e0cfeba22e2b6d76bf99b6.tar.xz yuzu-e93e898df528d013e2e0cfeba22e2b6d76bf99b6.zip | |
Remove pause callbacks from coretiming
Diffstat (limited to 'src/audio_core/sink')
| -rw-r--r-- | src/audio_core/sink/cubeb_sink.cpp | 34 | ||||
| -rw-r--r-- | src/audio_core/sink/cubeb_sink.h | 10 | ||||
| -rw-r--r-- | src/audio_core/sink/null_sink.h | 2 | ||||
| -rw-r--r-- | src/audio_core/sink/sdl2_sink.cpp | 27 | ||||
| -rw-r--r-- | src/audio_core/sink/sdl2_sink.h | 10 | ||||
| -rw-r--r-- | src/audio_core/sink/sink.h | 10 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_stream.cpp | 16 | ||||
| -rw-r--r-- | src/audio_core/sink/sink_stream.h | 2 |
8 files changed, 28 insertions, 83 deletions
diff --git a/src/audio_core/sink/cubeb_sink.cpp b/src/audio_core/sink/cubeb_sink.cpp index 9ae043611..36b115ad6 100644 --- a/src/audio_core/sink/cubeb_sink.cpp +++ b/src/audio_core/sink/cubeb_sink.cpp | |||
| @@ -129,20 +129,13 @@ public: | |||
| 129 | * Default false. | 129 | * Default false. |
| 130 | */ | 130 | */ |
| 131 | void Start(bool resume = false) override { | 131 | void Start(bool resume = false) override { |
| 132 | if (!ctx) { | 132 | if (!ctx || !paused) { |
| 133 | return; | 133 | return; |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | if (resume && was_playing) { | 136 | paused = false; |
| 137 | if (cubeb_stream_start(stream_backend) != CUBEB_OK) { | 137 | if (cubeb_stream_start(stream_backend) != CUBEB_OK) { |
| 138 | LOG_CRITICAL(Audio_Sink, "Error starting cubeb stream"); | 138 | LOG_CRITICAL(Audio_Sink, "Error starting cubeb stream"); |
| 139 | } | ||
| 140 | paused = false; | ||
| 141 | } else if (!resume) { | ||
| 142 | if (cubeb_stream_start(stream_backend) != CUBEB_OK) { | ||
| 143 | LOG_CRITICAL(Audio_Sink, "Error starting cubeb stream"); | ||
| 144 | } | ||
| 145 | paused = false; | ||
| 146 | } | 139 | } |
| 147 | } | 140 | } |
| 148 | 141 | ||
| @@ -151,16 +144,15 @@ public: | |||
| 151 | */ | 144 | */ |
| 152 | void Stop() override { | 145 | void Stop() override { |
| 153 | Unstall(); | 146 | Unstall(); |
| 154 | if (!ctx) { | 147 | |
| 148 | if (!ctx || paused) { | ||
| 155 | return; | 149 | return; |
| 156 | } | 150 | } |
| 157 | 151 | ||
| 152 | paused = true; | ||
| 158 | if (cubeb_stream_stop(stream_backend) != CUBEB_OK) { | 153 | if (cubeb_stream_stop(stream_backend) != CUBEB_OK) { |
| 159 | LOG_CRITICAL(Audio_Sink, "Error stopping cubeb stream"); | 154 | LOG_CRITICAL(Audio_Sink, "Error stopping cubeb stream"); |
| 160 | } | 155 | } |
| 161 | |||
| 162 | was_playing.store(!paused); | ||
| 163 | paused = true; | ||
| 164 | } | 156 | } |
| 165 | 157 | ||
| 166 | private: | 158 | private: |
| @@ -286,18 +278,6 @@ void CubebSink::CloseStreams() { | |||
| 286 | sink_streams.clear(); | 278 | sink_streams.clear(); |
| 287 | } | 279 | } |
| 288 | 280 | ||
| 289 | void CubebSink::PauseStreams() { | ||
| 290 | for (auto& stream : sink_streams) { | ||
| 291 | stream->Stop(); | ||
| 292 | } | ||
| 293 | } | ||
| 294 | |||
| 295 | void CubebSink::UnpauseStreams() { | ||
| 296 | for (auto& stream : sink_streams) { | ||
| 297 | stream->Start(true); | ||
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 301 | f32 CubebSink::GetDeviceVolume() const { | 281 | f32 CubebSink::GetDeviceVolume() const { |
| 302 | if (sink_streams.empty()) { | 282 | if (sink_streams.empty()) { |
| 303 | return 1.0f; | 283 | return 1.0f; |
diff --git a/src/audio_core/sink/cubeb_sink.h b/src/audio_core/sink/cubeb_sink.h index 91a6480fa..d98fc0866 100644 --- a/src/audio_core/sink/cubeb_sink.h +++ b/src/audio_core/sink/cubeb_sink.h | |||
| @@ -54,16 +54,6 @@ public: | |||
| 54 | void CloseStreams() override; | 54 | void CloseStreams() override; |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| 57 | * Pause all streams. | ||
| 58 | */ | ||
| 59 | void PauseStreams() override; | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Unpause all streams. | ||
| 63 | */ | ||
| 64 | void UnpauseStreams() override; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Get the device volume. Set from calls to the IAudioDevice service. | 57 | * Get the device volume. Set from calls to the IAudioDevice service. |
| 68 | * | 58 | * |
| 69 | * @return Volume of the device. | 59 | * @return Volume of the device. |
diff --git a/src/audio_core/sink/null_sink.h b/src/audio_core/sink/null_sink.h index eab9c3a0c..1215d3cd2 100644 --- a/src/audio_core/sink/null_sink.h +++ b/src/audio_core/sink/null_sink.h | |||
| @@ -44,8 +44,6 @@ public: | |||
| 44 | 44 | ||
| 45 | void CloseStream(SinkStream*) override {} | 45 | void CloseStream(SinkStream*) override {} |
| 46 | void CloseStreams() override {} | 46 | void CloseStreams() override {} |
| 47 | void PauseStreams() override {} | ||
| 48 | void UnpauseStreams() override {} | ||
| 49 | f32 GetDeviceVolume() const override { | 47 | f32 GetDeviceVolume() const override { |
| 50 | return 1.0f; | 48 | return 1.0f; |
| 51 | } | 49 | } |
diff --git a/src/audio_core/sink/sdl2_sink.cpp b/src/audio_core/sink/sdl2_sink.cpp index 7ee1dd7cd..1bd001b94 100644 --- a/src/audio_core/sink/sdl2_sink.cpp +++ b/src/audio_core/sink/sdl2_sink.cpp | |||
| @@ -108,17 +108,12 @@ public: | |||
| 108 | * Default false. | 108 | * Default false. |
| 109 | */ | 109 | */ |
| 110 | void Start(bool resume = false) override { | 110 | void Start(bool resume = false) override { |
| 111 | if (device == 0) { | 111 | if (device == 0 || !paused) { |
| 112 | return; | 112 | return; |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | if (resume && was_playing) { | 115 | paused = false; |
| 116 | SDL_PauseAudioDevice(device, 0); | 116 | SDL_PauseAudioDevice(device, 0); |
| 117 | paused = false; | ||
| 118 | } else if (!resume) { | ||
| 119 | SDL_PauseAudioDevice(device, 0); | ||
| 120 | paused = false; | ||
| 121 | } | ||
| 122 | } | 117 | } |
| 123 | 118 | ||
| 124 | /** | 119 | /** |
| @@ -126,11 +121,11 @@ public: | |||
| 126 | */ | 121 | */ |
| 127 | void Stop() override { | 122 | void Stop() override { |
| 128 | Unstall(); | 123 | Unstall(); |
| 129 | if (device == 0) { | 124 | if (device == 0 || paused) { |
| 130 | return; | 125 | return; |
| 131 | } | 126 | } |
| 132 | SDL_PauseAudioDevice(device, 1); | ||
| 133 | paused = true; | 127 | paused = true; |
| 128 | SDL_PauseAudioDevice(device, 1); | ||
| 134 | } | 129 | } |
| 135 | 130 | ||
| 136 | private: | 131 | private: |
| @@ -207,18 +202,6 @@ void SDLSink::CloseStreams() { | |||
| 207 | sink_streams.clear(); | 202 | sink_streams.clear(); |
| 208 | } | 203 | } |
| 209 | 204 | ||
| 210 | void SDLSink::PauseStreams() { | ||
| 211 | for (auto& stream : sink_streams) { | ||
| 212 | stream->Stop(); | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | void SDLSink::UnpauseStreams() { | ||
| 217 | for (auto& stream : sink_streams) { | ||
| 218 | stream->Start(); | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 222 | f32 SDLSink::GetDeviceVolume() const { | 205 | f32 SDLSink::GetDeviceVolume() const { |
| 223 | if (sink_streams.empty()) { | 206 | if (sink_streams.empty()) { |
| 224 | return 1.0f; | 207 | return 1.0f; |
diff --git a/src/audio_core/sink/sdl2_sink.h b/src/audio_core/sink/sdl2_sink.h index 57de9b6c2..9e76dde4f 100644 --- a/src/audio_core/sink/sdl2_sink.h +++ b/src/audio_core/sink/sdl2_sink.h | |||
| @@ -52,16 +52,6 @@ public: | |||
| 52 | void CloseStreams() override; | 52 | void CloseStreams() override; |
| 53 | 53 | ||
| 54 | /** | 54 | /** |
| 55 | * Pause all streams. | ||
| 56 | */ | ||
| 57 | void PauseStreams() override; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Unpause all streams. | ||
| 61 | */ | ||
| 62 | void UnpauseStreams() override; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Get the device volume. Set from calls to the IAudioDevice service. | 55 | * Get the device volume. Set from calls to the IAudioDevice service. |
| 66 | * | 56 | * |
| 67 | * @return Volume of the device. | 57 | * @return Volume of the device. |
diff --git a/src/audio_core/sink/sink.h b/src/audio_core/sink/sink.h index 43d99b62e..61e3d80cc 100644 --- a/src/audio_core/sink/sink.h +++ b/src/audio_core/sink/sink.h | |||
| @@ -40,16 +40,6 @@ public: | |||
| 40 | virtual void CloseStreams() = 0; | 40 | virtual void CloseStreams() = 0; |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * Pause all streams. | ||
| 44 | */ | ||
| 45 | virtual void PauseStreams() = 0; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Unpause all streams. | ||
| 49 | */ | ||
| 50 | virtual void UnpauseStreams() = 0; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Create a new sink stream, kept within this sink, with a pointer returned for use. | 43 | * Create a new sink stream, kept within this sink, with a pointer returned for use. |
| 54 | * Do not free the returned pointer. When done with the stream, call CloseStream on the sink. | 44 | * Do not free the returned pointer. When done with the stream, call CloseStream on the sink. |
| 55 | * | 45 | * |
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index 24636e512..59a8d69f0 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp | |||
| @@ -145,6 +145,12 @@ void SinkStream::ProcessAudioIn(std::span<const s16> input_buffer, std::size_t n | |||
| 145 | const std::size_t frame_size_bytes = frame_size * sizeof(s16); | 145 | const std::size_t frame_size_bytes = frame_size * sizeof(s16); |
| 146 | size_t frames_written{0}; | 146 | size_t frames_written{0}; |
| 147 | 147 | ||
| 148 | // If we're paused or going to shut down, we don't want to consume buffers as coretiming is | ||
| 149 | // paused and we'll desync, so just return. | ||
| 150 | if (system.IsPaused() || system.IsShuttingDown()) { | ||
| 151 | return; | ||
| 152 | } | ||
| 153 | |||
| 148 | if (queued_buffers > max_queue_size) { | 154 | if (queued_buffers > max_queue_size) { |
| 149 | Stall(); | 155 | Stall(); |
| 150 | } | 156 | } |
| @@ -195,6 +201,16 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz | |||
| 195 | const std::size_t frame_size_bytes = frame_size * sizeof(s16); | 201 | const std::size_t frame_size_bytes = frame_size * sizeof(s16); |
| 196 | size_t frames_written{0}; | 202 | size_t frames_written{0}; |
| 197 | 203 | ||
| 204 | // If we're paused or going to shut down, we don't want to consume buffers as coretiming is | ||
| 205 | // paused and we'll desync, so just play silence. | ||
| 206 | if (system.IsPaused() || system.IsShuttingDown()) { | ||
| 207 | constexpr std::array<s16, 6> silence{}; | ||
| 208 | for (size_t i = frames_written; i < num_frames; i++) { | ||
| 209 | std::memcpy(&output_buffer[i * frame_size], &silence[0], frame_size_bytes); | ||
| 210 | } | ||
| 211 | return; | ||
| 212 | } | ||
| 213 | |||
| 198 | // Due to many frames being queued up with nvdec (5 frames or so?), a lot of buffers also get | 214 | // Due to many frames being queued up with nvdec (5 frames or so?), a lot of buffers also get |
| 199 | // queued up (30+) but not all at once, which causes constant stalling here, so just let the | 215 | // queued up (30+) but not all at once, which causes constant stalling here, so just let the |
| 200 | // video play out without attempting to stall. | 216 | // video play out without attempting to stall. |
diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index db7cff45e..9aada54f1 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h | |||
| @@ -220,8 +220,6 @@ protected: | |||
| 220 | u32 device_channels{2}; | 220 | u32 device_channels{2}; |
| 221 | /// Is this stream currently paused? | 221 | /// Is this stream currently paused? |
| 222 | std::atomic<bool> paused{true}; | 222 | std::atomic<bool> paused{true}; |
| 223 | /// Was this stream previously playing? | ||
| 224 | std::atomic<bool> was_playing{false}; | ||
| 225 | /// Name of this stream | 223 | /// Name of this stream |
| 226 | std::string name{}; | 224 | std::string name{}; |
| 227 | 225 | ||