summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-05-29 17:37:57 -0400
committerGravatar Fernando Sahmkow2020-06-27 11:36:23 -0400
commite3d561fb842fa9ea986064a9a73001a5889f15d8 (patch)
treeeac6c57ab550d37d5b78a93431d34baa51950fb7 /src
parentCommon/Kernel: Corrections and small bug fixing. (diff)
downloadyuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.gz
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.tar.xz
yuzu-e3d561fb842fa9ea986064a9a73001a5889f15d8.zip
Audio: Correct buffer release for host timing.
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 {
66 return ns.count(); 66 return ns.count();
67} 67}
68 68
69s64 Stream::GetBufferReleaseNSHostTiming(const Buffer& buffer) const {
70 const std::size_t num_samples{buffer.GetSamples().size() / GetNumChannels()};
71 /// DSP signals before playing the last sample, in HLE we emulate this in this way
72 s64 base_samples = std::max<s64>(static_cast<s64>(num_samples) - 1, 0);
73 const auto ns =
74 std::chrono::nanoseconds((static_cast<u64>(base_samples) * 1000000000ULL) / sample_rate);
75 return ns.count();
76}
77
69static void VolumeAdjustSamples(std::vector<s16>& samples, float game_volume) { 78static void VolumeAdjustSamples(std::vector<s16>& samples, float game_volume) {
70 const float volume{std::clamp(Settings::Volume() - (1.0f - game_volume), 0.0f, 1.0f)}; 79 const float volume{std::clamp(Settings::Volume() - (1.0f - game_volume), 0.0f, 1.0f)};
71 80
@@ -105,7 +114,11 @@ void Stream::PlayNextBuffer() {
105 114
106 sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); 115 sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples());
107 116
108 core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer), release_event, {}); 117 if (core_timing.IsHostTiming()) {
118 core_timing.ScheduleEvent(GetBufferReleaseNSHostTiming(*active_buffer), release_event, {});
119 } else {
120 core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer), release_event, {});
121 }
109} 122}
110 123
111void Stream::ReleaseActiveBuffer() { 124void 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:
98 /// Gets the number of core cycles when the specified buffer will be released 98 /// Gets the number of core cycles when the specified buffer will be released
99 s64 GetBufferReleaseNS(const Buffer& buffer) const; 99 s64 GetBufferReleaseNS(const Buffer& buffer) const;
100 100
101 /// Gets the number of core cycles when the specified buffer will be released
102 s64 GetBufferReleaseNSHostTiming(const Buffer& buffer) const;
103
101 u32 sample_rate; ///< Sample rate of the stream 104 u32 sample_rate; ///< Sample rate of the stream
102 Format format; ///< Format of the stream 105 Format format; ///< Format of the stream
103 float game_volume = 1.0f; ///< The volume the game currently has set 106 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:
72 this->is_multicore = is_multicore; 72 this->is_multicore = is_multicore;
73 } 73 }
74 74
75 /// Check if it's using host timing.
76 bool IsHostTiming() const {
77 return is_multicore;
78 }
79
75 /// Pauses/Unpauses the execution of the timer thread. 80 /// Pauses/Unpauses the execution of the timer thread.
76 void Pause(bool is_paused); 81 void Pause(bool is_paused);
77 82