summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-07-09 04:07:17 +0200
committerGitHub <noreply@github.com>2020-07-09 04:07:17 +0200
commit77bdd09aa204e1e424d9b6b4d846301ab8dc892e (patch)
tree8ae7b6a56f38824bc3713cd81608499628a7d79c
parentMerge pull request #4266 from jbeich/freebsd (diff)
parentDon't handle cycles late if stretcher is active (diff)
downloadyuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.tar
yuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.tar.gz
yuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.tar.bz2
yuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.tar.lz
yuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.tar.xz
yuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.tar.zst
yuzu-77bdd09aa204e1e424d9b6b4d846301ab8dc892e.zip
-rw-r--r--src/audio_core/stream.cpp25
-rw-r--r--src/audio_core/stream.h4
2 files changed, 9 insertions, 20 deletions
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp
index dfc4805d9..22e8df373 100644
--- a/src/audio_core/stream.cpp
+++ b/src/audio_core/stream.cpp
@@ -38,7 +38,7 @@ Stream::Stream(Core::Timing::CoreTiming& core_timing, u32 sample_rate, Format fo
sink_stream{sink_stream}, core_timing{core_timing}, name{std::move(name_)} {
release_event = Core::Timing::CreateEvent(
- name, [this](u64 userdata, s64 cycles_late) { ReleaseActiveBuffer(); });
+ name, [this](u64 userdata, s64 cycles_late) { ReleaseActiveBuffer(cycles_late); });
}
void Stream::Play() {
@@ -66,15 +66,6 @@ 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)};
@@ -89,7 +80,7 @@ static void VolumeAdjustSamples(std::vector<s16>& samples, float game_volume) {
}
}
-void Stream::PlayNextBuffer() {
+void Stream::PlayNextBuffer(s64 cycles_late) {
if (!IsPlaying()) {
// Ensure we are in playing state before playing the next buffer
sink_stream.Flush();
@@ -114,18 +105,16 @@ void Stream::PlayNextBuffer() {
sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples());
- if (core_timing.IsHostTiming()) {
- core_timing.ScheduleEvent(GetBufferReleaseNSHostTiming(*active_buffer), release_event, {});
- } else {
- core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer), release_event, {});
- }
+ core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer) -
+ (Settings::values.enable_audio_stretching ? 0 : cycles_late),
+ release_event, {});
}
-void Stream::ReleaseActiveBuffer() {
+void Stream::ReleaseActiveBuffer(s64 cycles_late) {
ASSERT(active_buffer);
released_buffers.push(std::move(active_buffer));
release_callback();
- PlayNextBuffer();
+ PlayNextBuffer(cycles_late);
}
bool Stream::QueueBuffer(BufferPtr&& buffer) {
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h
index e309d60fe..524376257 100644
--- a/src/audio_core/stream.h
+++ b/src/audio_core/stream.h
@@ -90,10 +90,10 @@ public:
private:
/// Plays the next queued buffer in the audio stream, starting playback if necessary
- void PlayNextBuffer();
+ void PlayNextBuffer(s64 cycles_late = 0);
/// Releases the actively playing buffer, signalling that it has been completed
- void ReleaseActiveBuffer();
+ void ReleaseActiveBuffer(s64 cycles_late = 0);
/// Gets the number of core cycles when the specified buffer will be released
s64 GetBufferReleaseNS(const Buffer& buffer) const;