aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryuzubot <yuzu@yuzu-emu.org>2022-03-26 19:52:50 +0000
committeryuzubot <yuzu@yuzu-emu.org>2022-03-26 19:52:50 +0000
commit6dc2058c64fe38cf2ba799fd5ca0eab61738e420 (patch)
tree9dd33d9fae7e41184fe4adbfea8ebe976ecbb945 /src
parent887358c096d80a818017274c9d62b87aa2428ece (diff)
"Merge Tagged PR 7346"
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/stream.cpp9
-rw-r--r--src/audio_core/stream.h15
2 files changed, 17 insertions, 7 deletions
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp
index 0abc989b2f..ca034568d4 100644
--- a/src/audio_core/stream.cpp
+++ b/src/audio_core/stream.cpp
@@ -87,6 +87,14 @@ static void VolumeAdjustSamples(std::vector<s16>& samples, float game_volume) {
}
void Stream::PlayNextBuffer(std::chrono::nanoseconds ns_late) {
+ auto now = std::chrono::steady_clock::now();
+ auto duration = now.time_since_epoch();
+ auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
+
+ if (nanoseconds > expected_cb_time) {
+ ns_late = nanoseconds - expected_cb_time;
+ }
+
if (!IsPlaying()) {
// Ensure we are in playing state before playing the next buffer
sink_stream.Flush();
@@ -121,6 +129,7 @@ void Stream::PlayNextBuffer(std::chrono::nanoseconds ns_late) {
ns_late = {};
}
+ expected_cb_time = nanoseconds + (buffer_release_ns - ns_late);
core_timing.ScheduleEvent(buffer_release_ns - ns_late, release_event, {});
}
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h
index dbd97ec9c3..111404e76f 100644
--- a/src/audio_core/stream.h
+++ b/src/audio_core/stream.h
@@ -117,13 +117,14 @@ private:
ReleaseCallback release_callback; ///< Buffer release callback for the stream
State state{State::Stopped}; ///< Playback state of the stream
std::shared_ptr<Core::Timing::EventType>
- release_event; ///< Core timing release event for the stream
- BufferPtr active_buffer; ///< Actively playing buffer in the stream
- std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream
- std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream
- SinkStream& sink_stream; ///< Output sink for the stream
- Core::Timing::CoreTiming& core_timing; ///< Core timing instance.
- std::string name; ///< Name of the stream, must be unique
+ release_event; ///< Core timing release event for the stream
+ BufferPtr active_buffer; ///< Actively playing buffer in the stream
+ std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream
+ std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream
+ SinkStream& sink_stream; ///< Output sink for the stream
+ Core::Timing::CoreTiming& core_timing; ///< Core timing instance.
+ std::string name; ///< Name of the stream, must be unique
+ std::chrono::nanoseconds expected_cb_time = {}; ///< Estimated time of next callback
};
using StreamPtr = std::shared_ptr<Stream>;