Add possibility to disable audio output

This commit is contained in:
Dima 2022-11-16 23:12:17 +03:00 committed by Niccolò Betto
parent 70109f8fbd
commit e8e1b910c3
9 changed files with 42 additions and 6 deletions

View File

@ -5,6 +5,8 @@
namespace skyline::audio {
Audio::Audio(const DeviceState &state) : oboe::AudioStreamCallback() {
settings = std::shared_ptr<Settings>{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<i16, i32>(static_cast<u32>(*destination) + static_cast<u32>(*source));
}, static_cast<ssize_t>(writtenSamples))};
if (!*settings->isAudioOutputDisabled) {
auto trackSamples{track->samples.Read(span(destBuffer, streamSamples), [](i16 *source, i16 *destination) {
*destination = Saturate<i16, i32>(static_cast<u32>(*destination) + static_cast<u32>(*source));
}, static_cast<ssize_t>(writtenSamples))};
writtenSamples = std::max(trackSamples, writtenSamples);
writtenSamples = std::max(trackSamples, writtenSamples);
track->sampleCounter += trackSamples;
track->sampleCounter += trackSamples;
} else {
track->sampleCounter += streamSamples;
}
track->CheckReleasedBuffers();
}
}

View File

@ -3,6 +3,7 @@
#pragma once
#include <common/settings.h>
#include <audio/track.h>
namespace skyline::audio {
@ -15,6 +16,7 @@ namespace skyline::audio {
oboe::ManagedStream outputStream;
std::vector<std::shared_ptr<AudioTrack>> audioTracks;
std::mutex trackLock; //!< Synchronizes modifications to the audio tracks
std::shared_ptr<Settings> settings;
public:
Audio(const DeviceState &state);

View File

@ -41,6 +41,7 @@ namespace skyline {
gpuDriverLibraryName = ktSettings.GetString("gpuDriverLibraryName");
executorSlotCount = ktSettings.GetInt<u32>("executorSlotCount");
enableTextureReadbackHack = ktSettings.GetBool("enableTextureReadbackHack");
isAudioOutputDisabled = ktSettings.GetBool("isAudioOutputDisabled");
validationLayer = ktSettings.GetBool("validationLayer");
};
};

View File

@ -74,6 +74,9 @@ namespace skyline {
Setting<u32> executorSlotCount; //!< Number of GPU executor slots that can be used concurrently
Setting<bool> enableTextureReadbackHack; //!< If the CPU texture readback skipping hack should be used
// Audio
Setting<bool> isAudioOutputDisabled; //!< Disables audio output
// Debug
Setting<bool> validationLayer; //!< If the vulkan validation layer is enabled

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
#include <common/settings.h>
#include <kernel/types/KProcess.h>
#include "IAudioRenderer.h"
@ -68,7 +69,8 @@ namespace skyline::service::audio::IAudioRenderer {
for (u32 i{}; i < effectsIn.size(); i++)
effects[i].ProcessInput(effectsIn[i]);
UpdateAudio();
if (!*state.settings->isAudioOutputDisabled)
UpdateAudio();
UpdateDataHeader outputHeader{
.revision = constant::RevMagic,

View File

@ -28,6 +28,9 @@ class NativeSettings(context : Context, pref : PreferenceSettings) {
var executorSlotCount : Int = pref.executorSlotCount
var enableTextureReadbackHack : Boolean = pref.enableTextureReadbackHack
// Audio
var isAudioOutputDisabled : Boolean = pref.isAudioOutputDisabled
// Debug
var validationLayer : Boolean = BuildConfig.BUILD_TYPE != "release" && pref.validationLayer

View File

@ -41,6 +41,9 @@ class PreferenceSettings @Inject constructor(@ApplicationContext private val con
var executorSlotCount by sharedPreferences(context, 6)
var enableTextureReadbackHack by sharedPreferences(context, false)
// Audio
var isAudioOutputDisabled by sharedPreferences(context, false)
// Debug
var validationLayer by sharedPreferences(context, false)

View File

@ -78,6 +78,11 @@
<string name="enable_texture_readback_hack">Enable Texture Readback Hack</string>
<string name="enable_texture_readback_hack_enabled">Texture readback hack is enabled (Will break some games but others will have higher performance)</string>
<string name="enable_texture_readback_hack_disabled">Texture readback hack is disabled (Ensures highest accuracy)</string>
<!-- Settings - Audio -->
<string name="audio">Audio</string>
<string name="disable_audio_output">Disable Audio Output</string>
<string name="disable_audio_output_enabled">Audio output is disabled</string>
<string name="disable_audio_output_disabled">Audio output is enabled</string>
<!-- Settings - Debug -->
<string name="debug">Debug</string>
<string name="validation_layer">Enable validation layer</string>

View File

@ -142,6 +142,17 @@
app:key="enable_texture_readback_hack"
app:title="@string/enable_texture_readback_hack" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_audio"
android:title="@string/audio"
app:isPreferenceVisible="true">
<CheckBoxPreference
android:defaultValue="false"
android:summaryOff="@string/disable_audio_output_disabled"
android:summaryOn="@string/disable_audio_output_enabled"
app:key="is_audio_output_disabled"
app:title="@string/disable_audio_output" />
</PreferenceCategory>
<PreferenceCategory
android:key="category_debug"
android:title="@string/debug"