summaryrefslogtreecommitdiff
path: root/src/audio_core/sink
diff options
context:
space:
mode:
authorGravatar bunnei2022-09-15 13:50:13 -0700
committerGravatar GitHub2022-09-15 13:50:13 -0700
commite85bda5f31763359b69fbcad5c121995e1ad7074 (patch)
treecd9e85c7fabb334f2d19c20e3eb36c22e1883a21 /src/audio_core/sink
parentMerge pull request #8902 from Morph1984/new_sd_icons (diff)
parentRemove pause callbacks from coretiming (diff)
downloadyuzu-e85bda5f31763359b69fbcad5c121995e1ad7074.tar.gz
yuzu-e85bda5f31763359b69fbcad5c121995e1ad7074.tar.xz
yuzu-e85bda5f31763359b69fbcad5c121995e1ad7074.zip
Merge pull request #8878 from Kelebek1/remove_pause
Remove pause callbacks from coretiming
Diffstat (limited to 'src/audio_core/sink')
-rw-r--r--src/audio_core/sink/cubeb_sink.cpp34
-rw-r--r--src/audio_core/sink/cubeb_sink.h10
-rw-r--r--src/audio_core/sink/null_sink.h2
-rw-r--r--src/audio_core/sink/sdl2_sink.cpp27
-rw-r--r--src/audio_core/sink/sdl2_sink.h10
-rw-r--r--src/audio_core/sink/sink.h10
-rw-r--r--src/audio_core/sink/sink_stream.cpp16
-rw-r--r--src/audio_core/sink/sink_stream.h2
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
166private: 158private:
@@ -286,18 +278,6 @@ void CubebSink::CloseStreams() {
286 sink_streams.clear(); 278 sink_streams.clear();
287} 279}
288 280
289void CubebSink::PauseStreams() {
290 for (auto& stream : sink_streams) {
291 stream->Stop();
292 }
293}
294
295void CubebSink::UnpauseStreams() {
296 for (auto& stream : sink_streams) {
297 stream->Start(true);
298 }
299}
300
301f32 CubebSink::GetDeviceVolume() const { 281f32 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 a450a3343..4b0cb160d 100644
--- a/src/audio_core/sink/cubeb_sink.h
+++ b/src/audio_core/sink/cubeb_sink.h
@@ -53,16 +53,6 @@ public:
53 void CloseStreams() override; 53 void CloseStreams() override;
54 54
55 /** 55 /**
56 * Pause all streams.
57 */
58 void PauseStreams() override;
59
60 /**
61 * Unpause all streams.
62 */
63 void UnpauseStreams() override;
64
65 /**
66 * Get the device volume. Set from calls to the IAudioDevice service. 56 * Get the device volume. Set from calls to the IAudioDevice service.
67 * 57 *
68 * @return Volume of the device. 58 * @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
136private: 131private:
@@ -207,18 +202,6 @@ void SDLSink::CloseStreams() {
207 sink_streams.clear(); 202 sink_streams.clear();
208} 203}
209 204
210void SDLSink::PauseStreams() {
211 for (auto& stream : sink_streams) {
212 stream->Stop();
213 }
214}
215
216void SDLSink::UnpauseStreams() {
217 for (auto& stream : sink_streams) {
218 stream->Start();
219 }
220}
221
222f32 SDLSink::GetDeviceVolume() const { 205f32 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 b00f55849..f01eddc1b 100644
--- a/src/audio_core/sink/sdl2_sink.h
+++ b/src/audio_core/sink/sdl2_sink.h
@@ -51,16 +51,6 @@ public:
51 void CloseStreams() override; 51 void CloseStreams() override;
52 52
53 /** 53 /**
54 * Pause all streams.
55 */
56 void PauseStreams() override;
57
58 /**
59 * Unpause all streams.
60 */
61 void UnpauseStreams() override;
62
63 /**
64 * Get the device volume. Set from calls to the IAudioDevice service. 54 * Get the device volume. Set from calls to the IAudioDevice service.
65 * 55 *
66 * @return Volume of the device. 56 * @return Volume of the device.
diff --git a/src/audio_core/sink/sink.h b/src/audio_core/sink/sink.h
index b3f65792d..f28c6d126 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 68987eba6..37fe725e4 100644
--- a/src/audio_core/sink/sink_stream.cpp
+++ b/src/audio_core/sink/sink_stream.cpp
@@ -143,6 +143,12 @@ void SinkStream::ProcessAudioIn(std::span<const s16> input_buffer, std::size_t n
143 const std::size_t frame_size_bytes = frame_size * sizeof(s16); 143 const std::size_t frame_size_bytes = frame_size * sizeof(s16);
144 size_t frames_written{0}; 144 size_t frames_written{0};
145 145
146 // If we're paused or going to shut down, we don't want to consume buffers as coretiming is
147 // paused and we'll desync, so just return.
148 if (system.IsPaused() || system.IsShuttingDown()) {
149 return;
150 }
151
146 if (queued_buffers > max_queue_size) { 152 if (queued_buffers > max_queue_size) {
147 Stall(); 153 Stall();
148 } 154 }
@@ -193,6 +199,16 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
193 const std::size_t frame_size_bytes = frame_size * sizeof(s16); 199 const std::size_t frame_size_bytes = frame_size * sizeof(s16);
194 size_t frames_written{0}; 200 size_t frames_written{0};
195 201
202 // If we're paused or going to shut down, we don't want to consume buffers as coretiming is
203 // paused and we'll desync, so just play silence.
204 if (system.IsPaused() || system.IsShuttingDown()) {
205 constexpr std::array<s16, 6> silence{};
206 for (size_t i = frames_written; i < num_frames; i++) {
207 std::memcpy(&output_buffer[i * frame_size], &silence[0], frame_size_bytes);
208 }
209 return;
210 }
211
196 // Due to many frames being queued up with nvdec (5 frames or so?), a lot of buffers also get 212 // Due to many frames being queued up with nvdec (5 frames or so?), a lot of buffers also get
197 // queued up (30+) but not all at once, which causes constant stalling here, so just let the 213 // queued up (30+) but not all at once, which causes constant stalling here, so just let the
198 // video play out without attempting to stall. 214 // 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 5e9a86a10..9366ebbd3 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