summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2020-05-29 23:37:57 +0200
committerFernando Sahmkow <fsahmkow27@gmail.com>2020-06-27 17:36:23 +0200
commite3d561fb842fa9ea986064a9a73001a5889f15d8 (patch)
treeeac6c57ab550d37d5b78a93431d34baa51950fb7 /src
parentCommon/Kernel: Corrections and small bug fixing. (diff)
downloadyuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.gz
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.bz2
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.lz
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.xz
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.zst
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.zip
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/stream.cpp15
-rw-r--r--src/audio_core/stream.h3
-rw-r--r--src/core/core_timing.h5
3 files changed, 22 insertions, 1 deletions
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp
index 6d5539b6b..dfc4805d9 100644
--- a/src/audio_core/stream.cpp
+++ b/src/audio_core/stream.cpp
@@ -66,6 +66,15 @@ s64 Stream::GetBufferReleaseNS(const Buffer& buffer) const {
return ns.count();
}
+s64 Stream::GetBufferReleaseNSHostTiming(const Buffer& buffer) const {
+ const std::size_t num_samples{buffer.GetSamples().size() / GetNumChannels()};
+ /// DSP signals before playing the last sample, in HLE we emulate this in this way
+ s64 base_samples = std::max<s64>(static_cast<s64>(num_samples) - 1, 0);
+ const auto ns =
+ std::chrono::nanoseconds((static_cast<u64>(base_samples) * 1000000000ULL) / sample_rate);
+ return ns.count();
+}
+
static void VolumeAdjustSamples(std::vector<s16>& samples, float game_volume) {
const float volume{std::clamp(Settings::Volume() - (1.0f - game_volume), 0.0f, 1.0f)};
@@ -105,7 +114,11 @@ void Stream::PlayNextBuffer() {
sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples());
- core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer), release_event, {});
+ if (core_timing.IsHostTiming()) {
+ core_timing.ScheduleEvent(GetBufferReleaseNSHostTiming(*active_buffer), release_event, {});
+ } else {
+ core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer), release_event, {});
+ }
}
void Stream::ReleaseActiveBuffer() {
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h
index 0663ce435..e309d60fe 100644
--- a/src/audio_core/stream.h
+++ b/src/audio_core/stream.h
@@ -98,6 +98,9 @@ private:
/// Gets the number of core cycles when the specified buffer will be released
s64 GetBufferReleaseNS(const Buffer& buffer) const;
+ /// Gets the number of core cycles when the specified buffer will be released
+ s64 GetBufferReleaseNSHostTiming(const Buffer& buffer) const;
+
u32 sample_rate; ///< Sample rate of the stream
Format format; ///< Format of the stream
float game_volume = 1.0f; ///< The volume the game currently has set
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index ed5de9b97..72faaab64 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -72,6 +72,11 @@ public:
this->is_multicore = is_multicore;
}
+ /// Check if it's using host timing.
+ bool IsHostTiming() const {
+ return is_multicore;
+ }
+
/// Pauses/Unpauses the execution of the timer thread.
void Pause(bool is_paused);