From e8e1b910c32ef897fdf4b19dc03c758407ddaf29 Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 16 Nov 2022 23:12:17 +0300 Subject: [PATCH] Add possibility to disable audio output --- app/src/main/cpp/skyline/audio.cpp | 16 +++++++++++----- app/src/main/cpp/skyline/audio.h | 2 ++ .../main/cpp/skyline/common/android_settings.h | 1 + app/src/main/cpp/skyline/common/settings.h | 3 +++ .../audio/IAudioRenderer/IAudioRenderer.cpp | 4 +++- .../java/emu/skyline/utils/NativeSettings.kt | 3 +++ .../java/emu/skyline/utils/PreferenceSettings.kt | 3 +++ app/src/main/res/values/strings.xml | 5 +++++ app/src/main/res/xml/preferences.xml | 11 +++++++++++ 9 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/skyline/audio.cpp b/app/src/main/cpp/skyline/audio.cpp index c43034ef..b8549e00 100644 --- a/app/src/main/cpp/skyline/audio.cpp +++ b/app/src/main/cpp/skyline/audio.cpp @@ -5,6 +5,8 @@ namespace skyline::audio { Audio::Audio(const DeviceState &state) : oboe::AudioStreamCallback() { + settings = std::shared_ptr{state.settings}; + builder.setChannelCount(constant::StereoChannelCount); builder.setSampleRate(constant::SampleRate); builder.setFormat(constant::PcmFormat); @@ -50,13 +52,17 @@ namespace skyline::audio { std::scoped_lock bufferGuard{track->bufferLock}; - auto trackSamples{track->samples.Read(span(destBuffer, streamSamples), [](i16 *source, i16 *destination) { - *destination = Saturate(static_cast(*destination) + static_cast(*source)); - }, static_cast(writtenSamples))}; + if (!*settings->isAudioOutputDisabled) { + auto trackSamples{track->samples.Read(span(destBuffer, streamSamples), [](i16 *source, i16 *destination) { + *destination = Saturate(static_cast(*destination) + static_cast(*source)); + }, static_cast(writtenSamples))}; - writtenSamples = std::max(trackSamples, writtenSamples); + writtenSamples = std::max(trackSamples, writtenSamples); - track->sampleCounter += trackSamples; + track->sampleCounter += trackSamples; + } else { + track->sampleCounter += streamSamples; + } track->CheckReleasedBuffers(); } } diff --git a/app/src/main/cpp/skyline/audio.h b/app/src/main/cpp/skyline/audio.h index 47ddda13..f2685743 100644 --- a/app/src/main/cpp/skyline/audio.h +++ b/app/src/main/cpp/skyline/audio.h @@ -3,6 +3,7 @@ #pragma once +#include #include