diff options
34 files changed, 659 insertions, 172 deletions
diff --git a/.gitmodules b/.gitmodules index 4f4e8690b..e73ca99e3 100644 --- a/.gitmodules +++ b/.gitmodules | |||
| @@ -31,3 +31,6 @@ | |||
| 31 | [submodule "opus"] | 31 | [submodule "opus"] |
| 32 | path = externals/opus | 32 | path = externals/opus |
| 33 | url = https://github.com/ogniK5377/opus.git | 33 | url = https://github.com/ogniK5377/opus.git |
| 34 | [submodule "soundtouch"] | ||
| 35 | path = externals/soundtouch | ||
| 36 | url = https://github.com/citra-emu/ext-soundtouch.git | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f32ecfba..500d099fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -431,6 +431,9 @@ enable_testing() | |||
| 431 | add_subdirectory(externals) | 431 | add_subdirectory(externals) |
| 432 | add_subdirectory(src) | 432 | add_subdirectory(src) |
| 433 | 433 | ||
| 434 | # Set yuzu project as default StartUp Project in Visual Studio | ||
| 435 | set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT yuzu) | ||
| 436 | |||
| 434 | 437 | ||
| 435 | # Installation instructions | 438 | # Installation instructions |
| 436 | # ========================= | 439 | # ========================= |
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 3d8e10c2b..53dcf1f1a 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt | |||
| @@ -50,6 +50,9 @@ add_subdirectory(open_source_archives EXCLUDE_FROM_ALL) | |||
| 50 | add_library(unicorn-headers INTERFACE) | 50 | add_library(unicorn-headers INTERFACE) |
| 51 | target_include_directories(unicorn-headers INTERFACE ./unicorn/include) | 51 | target_include_directories(unicorn-headers INTERFACE ./unicorn/include) |
| 52 | 52 | ||
| 53 | # SoundTouch | ||
| 54 | add_subdirectory(soundtouch) | ||
| 55 | |||
| 53 | # Xbyak | 56 | # Xbyak |
| 54 | if (ARCHITECTURE_x86_64) | 57 | if (ARCHITECTURE_x86_64) |
| 55 | # Defined before "dynarmic" above | 58 | # Defined before "dynarmic" above |
diff --git a/externals/soundtouch b/externals/soundtouch new file mode 160000 | |||
| Subproject 060181eaf273180d3a7e87349895bd0cb6ccbf4 | |||
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 82e4850f7..c381dbe1d 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt | |||
| @@ -17,6 +17,8 @@ add_library(audio_core STATIC | |||
| 17 | sink_stream.h | 17 | sink_stream.h |
| 18 | stream.cpp | 18 | stream.cpp |
| 19 | stream.h | 19 | stream.h |
| 20 | time_stretch.cpp | ||
| 21 | time_stretch.h | ||
| 20 | 22 | ||
| 21 | $<$<BOOL:${ENABLE_CUBEB}>:cubeb_sink.cpp cubeb_sink.h> | 23 | $<$<BOOL:${ENABLE_CUBEB}>:cubeb_sink.cpp cubeb_sink.h> |
| 22 | ) | 24 | ) |
| @@ -24,6 +26,7 @@ add_library(audio_core STATIC | |||
| 24 | create_target_directory_groups(audio_core) | 26 | create_target_directory_groups(audio_core) |
| 25 | 27 | ||
| 26 | target_link_libraries(audio_core PUBLIC common core) | 28 | target_link_libraries(audio_core PUBLIC common core) |
| 29 | target_link_libraries(audio_core PRIVATE SoundTouch) | ||
| 27 | 30 | ||
| 28 | if(ENABLE_CUBEB) | 31 | if(ENABLE_CUBEB) |
| 29 | target_link_libraries(audio_core PRIVATE cubeb) | 32 | target_link_libraries(audio_core PRIVATE cubeb) |
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 5a1177d0c..79155a7a0 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp | |||
| @@ -3,27 +3,23 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <atomic> | ||
| 6 | #include <cstring> | 7 | #include <cstring> |
| 7 | #include <mutex> | ||
| 8 | |||
| 9 | #include "audio_core/cubeb_sink.h" | 8 | #include "audio_core/cubeb_sink.h" |
| 10 | #include "audio_core/stream.h" | 9 | #include "audio_core/stream.h" |
| 10 | #include "audio_core/time_stretch.h" | ||
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "common/ring_buffer.h" | ||
| 13 | #include "core/settings.h" | ||
| 12 | 14 | ||
| 13 | namespace AudioCore { | 15 | namespace AudioCore { |
| 14 | 16 | ||
| 15 | class SinkStreamImpl final : public SinkStream { | 17 | class CubebSinkStream final : public SinkStream { |
| 16 | public: | 18 | public: |
| 17 | SinkStreamImpl(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, | 19 | CubebSinkStream(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, |
| 18 | const std::string& name) | 20 | const std::string& name) |
| 19 | : ctx{ctx}, num_channels{num_channels_} { | 21 | : ctx{ctx}, num_channels{std::min(num_channels_, 2u)}, time_stretch{sample_rate, |
| 20 | 22 | num_channels} { | |
| 21 | if (num_channels == 6) { | ||
| 22 | // 6-channel audio does not seem to work with cubeb + SDL, so we downsample this to 2 | ||
| 23 | // channel for now | ||
| 24 | is_6_channel = true; | ||
| 25 | num_channels = 2; | ||
| 26 | } | ||
| 27 | 23 | ||
| 28 | cubeb_stream_params params{}; | 24 | cubeb_stream_params params{}; |
| 29 | params.rate = sample_rate; | 25 | params.rate = sample_rate; |
| @@ -38,7 +34,7 @@ public: | |||
| 38 | 34 | ||
| 39 | if (cubeb_stream_init(ctx, &stream_backend, name.c_str(), nullptr, nullptr, output_device, | 35 | if (cubeb_stream_init(ctx, &stream_backend, name.c_str(), nullptr, nullptr, output_device, |
| 40 | ¶ms, std::max(512u, minimum_latency), | 36 | ¶ms, std::max(512u, minimum_latency), |
| 41 | &SinkStreamImpl::DataCallback, &SinkStreamImpl::StateCallback, | 37 | &CubebSinkStream::DataCallback, &CubebSinkStream::StateCallback, |
| 42 | this) != CUBEB_OK) { | 38 | this) != CUBEB_OK) { |
| 43 | LOG_CRITICAL(Audio_Sink, "Error initializing cubeb stream"); | 39 | LOG_CRITICAL(Audio_Sink, "Error initializing cubeb stream"); |
| 44 | return; | 40 | return; |
| @@ -50,7 +46,7 @@ public: | |||
| 50 | } | 46 | } |
| 51 | } | 47 | } |
| 52 | 48 | ||
| 53 | ~SinkStreamImpl() { | 49 | ~CubebSinkStream() { |
| 54 | if (!ctx) { | 50 | if (!ctx) { |
| 55 | return; | 51 | return; |
| 56 | } | 52 | } |
| @@ -62,27 +58,32 @@ public: | |||
| 62 | cubeb_stream_destroy(stream_backend); | 58 | cubeb_stream_destroy(stream_backend); |
| 63 | } | 59 | } |
| 64 | 60 | ||
| 65 | void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) override { | 61 | void EnqueueSamples(u32 source_num_channels, const std::vector<s16>& samples) override { |
| 66 | if (!ctx) { | 62 | if (source_num_channels > num_channels) { |
| 63 | // Downsample 6 channels to 2 | ||
| 64 | std::vector<s16> buf; | ||
| 65 | buf.reserve(samples.size() * num_channels / source_num_channels); | ||
| 66 | for (size_t i = 0; i < samples.size(); i += source_num_channels) { | ||
| 67 | for (size_t ch = 0; ch < num_channels; ch++) { | ||
| 68 | buf.push_back(samples[i + ch]); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | queue.Push(buf); | ||
| 67 | return; | 72 | return; |
| 68 | } | 73 | } |
| 69 | 74 | ||
| 70 | std::lock_guard lock{queue_mutex}; | 75 | queue.Push(samples); |
| 76 | } | ||
| 71 | 77 | ||
| 72 | queue.reserve(queue.size() + samples.size() * GetNumChannels()); | 78 | size_t SamplesInQueue(u32 num_channels) const override { |
| 79 | if (!ctx) | ||
| 80 | return 0; | ||
| 73 | 81 | ||
| 74 | if (is_6_channel) { | 82 | return queue.Size() / num_channels; |
| 75 | // Downsample 6 channels to 2 | 83 | } |
| 76 | const size_t sample_count_copy_size = samples.size() * 2; | 84 | |
| 77 | queue.reserve(sample_count_copy_size); | 85 | void Flush() override { |
| 78 | for (size_t i = 0; i < samples.size(); i += num_channels) { | 86 | should_flush = true; |
| 79 | queue.push_back(samples[i]); | ||
| 80 | queue.push_back(samples[i + 1]); | ||
| 81 | } | ||
| 82 | } else { | ||
| 83 | // Copy as-is | ||
| 84 | std::copy(samples.begin(), samples.end(), std::back_inserter(queue)); | ||
| 85 | } | ||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | u32 GetNumChannels() const { | 89 | u32 GetNumChannels() const { |
| @@ -95,10 +96,11 @@ private: | |||
| 95 | cubeb* ctx{}; | 96 | cubeb* ctx{}; |
| 96 | cubeb_stream* stream_backend{}; | 97 | cubeb_stream* stream_backend{}; |
| 97 | u32 num_channels{}; | 98 | u32 num_channels{}; |
| 98 | bool is_6_channel{}; | ||
| 99 | 99 | ||
| 100 | std::mutex queue_mutex; | 100 | Common::RingBuffer<s16, 0x10000> queue; |
| 101 | std::vector<s16> queue; | 101 | std::array<s16, 2> last_frame; |
| 102 | std::atomic<bool> should_flush{}; | ||
| 103 | TimeStretcher time_stretch; | ||
| 102 | 104 | ||
| 103 | static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, | 105 | static long DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, |
| 104 | void* output_buffer, long num_frames); | 106 | void* output_buffer, long num_frames); |
| @@ -144,38 +146,52 @@ CubebSink::~CubebSink() { | |||
| 144 | SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, | 146 | SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels, |
| 145 | const std::string& name) { | 147 | const std::string& name) { |
| 146 | sink_streams.push_back( | 148 | sink_streams.push_back( |
| 147 | std::make_unique<SinkStreamImpl>(ctx, sample_rate, num_channels, output_device, name)); | 149 | std::make_unique<CubebSinkStream>(ctx, sample_rate, num_channels, output_device, name)); |
| 148 | return *sink_streams.back(); | 150 | return *sink_streams.back(); |
| 149 | } | 151 | } |
| 150 | 152 | ||
| 151 | long SinkStreamImpl::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, | 153 | long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const void* input_buffer, |
| 152 | void* output_buffer, long num_frames) { | 154 | void* output_buffer, long num_frames) { |
| 153 | SinkStreamImpl* impl = static_cast<SinkStreamImpl*>(user_data); | 155 | CubebSinkStream* impl = static_cast<CubebSinkStream*>(user_data); |
| 154 | u8* buffer = reinterpret_cast<u8*>(output_buffer); | 156 | u8* buffer = reinterpret_cast<u8*>(output_buffer); |
| 155 | 157 | ||
| 156 | if (!impl) { | 158 | if (!impl) { |
| 157 | return {}; | 159 | return {}; |
| 158 | } | 160 | } |
| 159 | 161 | ||
| 160 | std::lock_guard lock{impl->queue_mutex}; | 162 | const size_t num_channels = impl->GetNumChannels(); |
| 163 | const size_t samples_to_write = num_channels * num_frames; | ||
| 164 | size_t samples_written; | ||
| 165 | |||
| 166 | if (Settings::values.enable_audio_stretching) { | ||
| 167 | const std::vector<s16> in{impl->queue.Pop()}; | ||
| 168 | const size_t num_in{in.size() / num_channels}; | ||
| 169 | s16* const out{reinterpret_cast<s16*>(buffer)}; | ||
| 170 | const size_t out_frames = impl->time_stretch.Process(in.data(), num_in, out, num_frames); | ||
| 171 | samples_written = out_frames * num_channels; | ||
| 161 | 172 | ||
| 162 | const size_t frames_to_write{ | 173 | if (impl->should_flush) { |
| 163 | std::min(impl->queue.size() / impl->GetNumChannels(), static_cast<size_t>(num_frames))}; | 174 | impl->time_stretch.Flush(); |
| 175 | impl->should_flush = false; | ||
| 176 | } | ||
| 177 | } else { | ||
| 178 | samples_written = impl->queue.Pop(buffer, samples_to_write); | ||
| 179 | } | ||
| 164 | 180 | ||
| 165 | memcpy(buffer, impl->queue.data(), frames_to_write * sizeof(s16) * impl->GetNumChannels()); | 181 | if (samples_written >= num_channels) { |
| 166 | impl->queue.erase(impl->queue.begin(), | 182 | std::memcpy(&impl->last_frame[0], buffer + (samples_written - num_channels) * sizeof(s16), |
| 167 | impl->queue.begin() + frames_to_write * impl->GetNumChannels()); | 183 | num_channels * sizeof(s16)); |
| 184 | } | ||
| 168 | 185 | ||
| 169 | if (frames_to_write < num_frames) { | 186 | // Fill the rest of the frames with last_frame |
| 170 | // Fill the rest of the frames with silence | 187 | for (size_t i = samples_written; i < samples_to_write; i += num_channels) { |
| 171 | memset(buffer + frames_to_write * sizeof(s16) * impl->GetNumChannels(), 0, | 188 | std::memcpy(buffer + i * sizeof(s16), &impl->last_frame[0], num_channels * sizeof(s16)); |
| 172 | (num_frames - frames_to_write) * sizeof(s16) * impl->GetNumChannels()); | ||
| 173 | } | 189 | } |
| 174 | 190 | ||
| 175 | return num_frames; | 191 | return num_frames; |
| 176 | } | 192 | } |
| 177 | 193 | ||
| 178 | void SinkStreamImpl::StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state) {} | 194 | void CubebSinkStream::StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state) {} |
| 179 | 195 | ||
| 180 | std::vector<std::string> ListCubebSinkDevices() { | 196 | std::vector<std::string> ListCubebSinkDevices() { |
| 181 | std::vector<std::string> device_list; | 197 | std::vector<std::string> device_list; |
diff --git a/src/audio_core/null_sink.h b/src/audio_core/null_sink.h index f235d93e5..2ed0c83b6 100644 --- a/src/audio_core/null_sink.h +++ b/src/audio_core/null_sink.h | |||
| @@ -21,6 +21,12 @@ public: | |||
| 21 | private: | 21 | private: |
| 22 | struct NullSinkStreamImpl final : SinkStream { | 22 | struct NullSinkStreamImpl final : SinkStream { |
| 23 | void EnqueueSamples(u32 /*num_channels*/, const std::vector<s16>& /*samples*/) override {} | 23 | void EnqueueSamples(u32 /*num_channels*/, const std::vector<s16>& /*samples*/) override {} |
| 24 | |||
| 25 | size_t SamplesInQueue(u32 /*num_channels*/) const override { | ||
| 26 | return 0; | ||
| 27 | } | ||
| 28 | |||
| 29 | void Flush() override {} | ||
| 24 | } null_sink_stream; | 30 | } null_sink_stream; |
| 25 | }; | 31 | }; |
| 26 | 32 | ||
diff --git a/src/audio_core/sink_stream.h b/src/audio_core/sink_stream.h index 41b6736d8..4309ad094 100644 --- a/src/audio_core/sink_stream.h +++ b/src/audio_core/sink_stream.h | |||
| @@ -25,6 +25,10 @@ public: | |||
| 25 | * @param samples Samples in interleaved stereo PCM16 format. | 25 | * @param samples Samples in interleaved stereo PCM16 format. |
| 26 | */ | 26 | */ |
| 27 | virtual void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) = 0; | 27 | virtual void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) = 0; |
| 28 | |||
| 29 | virtual std::size_t SamplesInQueue(u32 num_channels) const = 0; | ||
| 30 | |||
| 31 | virtual void Flush() = 0; | ||
| 28 | }; | 32 | }; |
| 29 | 33 | ||
| 30 | using SinkStreamPtr = std::unique_ptr<SinkStream>; | 34 | using SinkStreamPtr = std::unique_ptr<SinkStream>; |
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index dbae75d8c..84dcdd98d 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp | |||
| @@ -73,6 +73,7 @@ static void VolumeAdjustSamples(std::vector<s16>& samples) { | |||
| 73 | void Stream::PlayNextBuffer() { | 73 | void Stream::PlayNextBuffer() { |
| 74 | if (!IsPlaying()) { | 74 | if (!IsPlaying()) { |
| 75 | // Ensure we are in playing state before playing the next buffer | 75 | // Ensure we are in playing state before playing the next buffer |
| 76 | sink_stream.Flush(); | ||
| 76 | return; | 77 | return; |
| 77 | } | 78 | } |
| 78 | 79 | ||
| @@ -83,6 +84,7 @@ void Stream::PlayNextBuffer() { | |||
| 83 | 84 | ||
| 84 | if (queued_buffers.empty()) { | 85 | if (queued_buffers.empty()) { |
| 85 | // No queued buffers - we are effectively paused | 86 | // No queued buffers - we are effectively paused |
| 87 | sink_stream.Flush(); | ||
| 86 | return; | 88 | return; |
| 87 | } | 89 | } |
| 88 | 90 | ||
| @@ -90,6 +92,7 @@ void Stream::PlayNextBuffer() { | |||
| 90 | queued_buffers.pop(); | 92 | queued_buffers.pop(); |
| 91 | 93 | ||
| 92 | VolumeAdjustSamples(active_buffer->Samples()); | 94 | VolumeAdjustSamples(active_buffer->Samples()); |
| 95 | |||
| 93 | sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); | 96 | sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); |
| 94 | 97 | ||
| 95 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); | 98 | CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); |
diff --git a/src/audio_core/time_stretch.cpp b/src/audio_core/time_stretch.cpp new file mode 100644 index 000000000..da094c46b --- /dev/null +++ b/src/audio_core/time_stretch.cpp | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include <cstddef> | ||
| 8 | #include "audio_core/time_stretch.h" | ||
| 9 | #include "common/logging/log.h" | ||
| 10 | |||
| 11 | namespace AudioCore { | ||
| 12 | |||
| 13 | TimeStretcher::TimeStretcher(u32 sample_rate, u32 channel_count) | ||
| 14 | : m_sample_rate(sample_rate), m_channel_count(channel_count) { | ||
| 15 | m_sound_touch.setChannels(channel_count); | ||
| 16 | m_sound_touch.setSampleRate(sample_rate); | ||
| 17 | m_sound_touch.setPitch(1.0); | ||
| 18 | m_sound_touch.setTempo(1.0); | ||
| 19 | } | ||
| 20 | |||
| 21 | void TimeStretcher::Clear() { | ||
| 22 | m_sound_touch.clear(); | ||
| 23 | } | ||
| 24 | |||
| 25 | void TimeStretcher::Flush() { | ||
| 26 | m_sound_touch.flush(); | ||
| 27 | } | ||
| 28 | |||
| 29 | size_t TimeStretcher::Process(const s16* in, size_t num_in, s16* out, size_t num_out) { | ||
| 30 | const double time_delta = static_cast<double>(num_out) / m_sample_rate; // seconds | ||
| 31 | |||
| 32 | // We were given actual_samples number of samples, and num_samples were requested from us. | ||
| 33 | double current_ratio = static_cast<double>(num_in) / static_cast<double>(num_out); | ||
| 34 | |||
| 35 | const double max_latency = 1.0; // seconds | ||
| 36 | const double max_backlog = m_sample_rate * max_latency; | ||
| 37 | const double backlog_fullness = m_sound_touch.numSamples() / max_backlog; | ||
| 38 | if (backlog_fullness > 5.0) { | ||
| 39 | // Too many samples in backlog: Don't push anymore on | ||
| 40 | num_in = 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | // We ideally want the backlog to be about 50% full. | ||
| 44 | // This gives some headroom both ways to prevent underflow and overflow. | ||
| 45 | // We tweak current_ratio to encourage this. | ||
| 46 | constexpr double tweak_time_scale = 0.05; // seconds | ||
| 47 | const double tweak_correction = (backlog_fullness - 0.5) * (time_delta / tweak_time_scale); | ||
| 48 | current_ratio *= std::pow(1.0 + 2.0 * tweak_correction, tweak_correction < 0 ? 3.0 : 1.0); | ||
| 49 | |||
| 50 | // This low-pass filter smoothes out variance in the calculated stretch ratio. | ||
| 51 | // The time-scale determines how responsive this filter is. | ||
| 52 | constexpr double lpf_time_scale = 2.0; // seconds | ||
| 53 | const double lpf_gain = 1.0 - std::exp(-time_delta / lpf_time_scale); | ||
| 54 | m_stretch_ratio += lpf_gain * (current_ratio - m_stretch_ratio); | ||
| 55 | |||
| 56 | // Place a lower limit of 5% speed. When a game boots up, there will be | ||
| 57 | // many silence samples. These do not need to be timestretched. | ||
| 58 | m_stretch_ratio = std::max(m_stretch_ratio, 0.05); | ||
| 59 | m_sound_touch.setTempo(m_stretch_ratio); | ||
| 60 | |||
| 61 | LOG_DEBUG(Audio, "{:5}/{:5} ratio:{:0.6f} backlog:{:0.6f}", num_in, num_out, m_stretch_ratio, | ||
| 62 | backlog_fullness); | ||
| 63 | |||
| 64 | m_sound_touch.putSamples(in, num_in); | ||
| 65 | return m_sound_touch.receiveSamples(out, num_out); | ||
| 66 | } | ||
| 67 | |||
| 68 | } // namespace AudioCore | ||
diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h new file mode 100644 index 000000000..7e39e695e --- /dev/null +++ b/src/audio_core/time_stretch.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <cstddef> | ||
| 9 | #include <SoundTouch.h> | ||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace AudioCore { | ||
| 13 | |||
| 14 | class TimeStretcher { | ||
| 15 | public: | ||
| 16 | TimeStretcher(u32 sample_rate, u32 channel_count); | ||
| 17 | |||
| 18 | /// @param in Input sample buffer | ||
| 19 | /// @param num_in Number of input frames in `in` | ||
| 20 | /// @param out Output sample buffer | ||
| 21 | /// @param num_out Desired number of output frames in `out` | ||
| 22 | /// @returns Actual number of frames written to `out` | ||
| 23 | size_t Process(const s16* in, size_t num_in, s16* out, size_t num_out); | ||
| 24 | |||
| 25 | void Clear(); | ||
| 26 | |||
| 27 | void Flush(); | ||
| 28 | |||
| 29 | private: | ||
| 30 | u32 m_sample_rate; | ||
| 31 | u32 m_channel_count; | ||
| 32 | soundtouch::SoundTouch m_sound_touch; | ||
| 33 | double m_stretch_ratio = 1.0; | ||
| 34 | }; | ||
| 35 | |||
| 36 | } // namespace AudioCore | ||
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index f41946cc6..6a3f1fe08 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -71,6 +71,7 @@ add_library(common STATIC | |||
| 71 | param_package.cpp | 71 | param_package.cpp |
| 72 | param_package.h | 72 | param_package.h |
| 73 | quaternion.h | 73 | quaternion.h |
| 74 | ring_buffer.h | ||
| 74 | scm_rev.cpp | 75 | scm_rev.cpp |
| 75 | scm_rev.h | 76 | scm_rev.h |
| 76 | scope_exit.h | 77 | scope_exit.h |
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h new file mode 100644 index 000000000..30d934a38 --- /dev/null +++ b/src/common/ring_buffer.h | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <algorithm> | ||
| 8 | #include <array> | ||
| 9 | #include <atomic> | ||
| 10 | #include <cstddef> | ||
| 11 | #include <cstring> | ||
| 12 | #include <type_traits> | ||
| 13 | #include <vector> | ||
| 14 | #include "common/common_types.h" | ||
| 15 | |||
| 16 | namespace Common { | ||
| 17 | |||
| 18 | /// SPSC ring buffer | ||
| 19 | /// @tparam T Element type | ||
| 20 | /// @tparam capacity Number of slots in ring buffer | ||
| 21 | /// @tparam granularity Slot size in terms of number of elements | ||
| 22 | template <typename T, size_t capacity, size_t granularity = 1> | ||
| 23 | class RingBuffer { | ||
| 24 | /// A "slot" is made of `granularity` elements of `T`. | ||
| 25 | static constexpr size_t slot_size = granularity * sizeof(T); | ||
| 26 | // T must be safely memcpy-able and have a trivial default constructor. | ||
| 27 | static_assert(std::is_trivial_v<T>); | ||
| 28 | // Ensure capacity is sensible. | ||
| 29 | static_assert(capacity < std::numeric_limits<size_t>::max() / 2 / granularity); | ||
| 30 | static_assert((capacity & (capacity - 1)) == 0, "capacity must be a power of two"); | ||
| 31 | // Ensure lock-free. | ||
| 32 | static_assert(std::atomic<size_t>::is_always_lock_free); | ||
| 33 | |||
| 34 | public: | ||
| 35 | /// Pushes slots into the ring buffer | ||
| 36 | /// @param new_slots Pointer to the slots to push | ||
| 37 | /// @param slot_count Number of slots to push | ||
| 38 | /// @returns The number of slots actually pushed | ||
| 39 | size_t Push(const void* new_slots, size_t slot_count) { | ||
| 40 | const size_t write_index = m_write_index.load(); | ||
| 41 | const size_t slots_free = capacity + m_read_index.load() - write_index; | ||
| 42 | const size_t push_count = std::min(slot_count, slots_free); | ||
| 43 | |||
| 44 | const size_t pos = write_index % capacity; | ||
| 45 | const size_t first_copy = std::min(capacity - pos, push_count); | ||
| 46 | const size_t second_copy = push_count - first_copy; | ||
| 47 | |||
| 48 | const char* in = static_cast<const char*>(new_slots); | ||
| 49 | std::memcpy(m_data.data() + pos * granularity, in, first_copy * slot_size); | ||
| 50 | in += first_copy * slot_size; | ||
| 51 | std::memcpy(m_data.data(), in, second_copy * slot_size); | ||
| 52 | |||
| 53 | m_write_index.store(write_index + push_count); | ||
| 54 | |||
| 55 | return push_count; | ||
| 56 | } | ||
| 57 | |||
| 58 | size_t Push(const std::vector<T>& input) { | ||
| 59 | return Push(input.data(), input.size()); | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Pops slots from the ring buffer | ||
| 63 | /// @param output Where to store the popped slots | ||
| 64 | /// @param max_slots Maximum number of slots to pop | ||
| 65 | /// @returns The number of slots actually popped | ||
| 66 | size_t Pop(void* output, size_t max_slots = ~size_t(0)) { | ||
| 67 | const size_t read_index = m_read_index.load(); | ||
| 68 | const size_t slots_filled = m_write_index.load() - read_index; | ||
| 69 | const size_t pop_count = std::min(slots_filled, max_slots); | ||
| 70 | |||
| 71 | const size_t pos = read_index % capacity; | ||
| 72 | const size_t first_copy = std::min(capacity - pos, pop_count); | ||
| 73 | const size_t second_copy = pop_count - first_copy; | ||
| 74 | |||
| 75 | char* out = static_cast<char*>(output); | ||
| 76 | std::memcpy(out, m_data.data() + pos * granularity, first_copy * slot_size); | ||
| 77 | out += first_copy * slot_size; | ||
| 78 | std::memcpy(out, m_data.data(), second_copy * slot_size); | ||
| 79 | |||
| 80 | m_read_index.store(read_index + pop_count); | ||
| 81 | |||
| 82 | return pop_count; | ||
| 83 | } | ||
| 84 | |||
| 85 | std::vector<T> Pop(size_t max_slots = ~size_t(0)) { | ||
| 86 | std::vector<T> out(std::min(max_slots, capacity) * granularity); | ||
| 87 | const size_t count = Pop(out.data(), out.size() / granularity); | ||
| 88 | out.resize(count * granularity); | ||
| 89 | return out; | ||
| 90 | } | ||
| 91 | |||
| 92 | /// @returns Number of slots used | ||
| 93 | size_t Size() const { | ||
| 94 | return m_write_index.load() - m_read_index.load(); | ||
| 95 | } | ||
| 96 | |||
| 97 | /// @returns Maximum size of ring buffer | ||
| 98 | constexpr size_t Capacity() const { | ||
| 99 | return capacity; | ||
| 100 | } | ||
| 101 | |||
| 102 | private: | ||
| 103 | // It is important to align the below variables for performance reasons: | ||
| 104 | // Having them on the same cache-line would result in false-sharing between them. | ||
| 105 | alignas(128) std::atomic<size_t> m_read_index{0}; | ||
| 106 | alignas(128) std::atomic<size_t> m_write_index{0}; | ||
| 107 | |||
| 108 | std::array<T, granularity * capacity> m_data; | ||
| 109 | }; | ||
| 110 | |||
| 111 | } // namespace Common | ||
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h index 4054d5db6..ad39c8271 100644 --- a/src/core/hle/kernel/errors.h +++ b/src/core/hle/kernel/errors.h | |||
| @@ -21,6 +21,7 @@ enum { | |||
| 21 | HandleTableFull = 105, | 21 | HandleTableFull = 105, |
| 22 | InvalidMemoryState = 106, | 22 | InvalidMemoryState = 106, |
| 23 | InvalidMemoryPermissions = 108, | 23 | InvalidMemoryPermissions = 108, |
| 24 | InvalidThreadPriority = 112, | ||
| 24 | InvalidProcessorId = 113, | 25 | InvalidProcessorId = 113, |
| 25 | InvalidHandle = 114, | 26 | InvalidHandle = 114, |
| 26 | InvalidCombination = 116, | 27 | InvalidCombination = 116, |
| @@ -36,7 +37,7 @@ enum { | |||
| 36 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always | 37 | // WARNING: The kernel is quite inconsistent in it's usage of errors code. Make sure to always |
| 37 | // double check that the code matches before re-using the constant. | 38 | // double check that the code matches before re-using the constant. |
| 38 | 39 | ||
| 39 | // TODO(bunnei): Replace these with correct errors for Switch OS | 40 | // TODO(bunnei): Replace -1 with correct errors for Switch OS |
| 40 | constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); | 41 | constexpr ResultCode ERR_HANDLE_TABLE_FULL(ErrorModule::Kernel, ErrCodes::HandleTableFull); |
| 41 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); | 42 | constexpr ResultCode ERR_SESSION_CLOSED_BY_REMOTE(-1); |
| 42 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); | 43 | constexpr ResultCode ERR_PORT_NAME_TOO_LONG(ErrorModule::Kernel, ErrCodes::TooLarge); |
| @@ -53,15 +54,16 @@ constexpr ResultCode ERR_INVALID_ADDRESS_STATE(ErrorModule::Kernel, ErrCodes::In | |||
| 53 | constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, | 54 | constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel, |
| 54 | ErrCodes::InvalidMemoryPermissions); | 55 | ErrCodes::InvalidMemoryPermissions); |
| 55 | constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle); | 56 | constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle); |
| 57 | constexpr ResultCode ERR_INVALID_PROCESSOR_ID(ErrorModule::Kernel, ErrCodes::InvalidProcessorId); | ||
| 56 | constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); | 58 | constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); |
| 59 | constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, | ||
| 60 | ErrCodes::InvalidThreadPriority); | ||
| 57 | constexpr ResultCode ERR_INVALID_POINTER(-1); | 61 | constexpr ResultCode ERR_INVALID_POINTER(-1); |
| 58 | constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); | 62 | constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1); |
| 59 | constexpr ResultCode ERR_NOT_AUTHORIZED(-1); | 63 | constexpr ResultCode ERR_NOT_AUTHORIZED(-1); |
| 60 | /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. | 64 | /// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. |
| 61 | constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); | 65 | constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); |
| 62 | constexpr ResultCode ERR_NOT_FOUND(-1); | 66 | constexpr ResultCode ERR_NOT_FOUND(-1); |
| 63 | constexpr ResultCode ERR_OUT_OF_RANGE(-1); | ||
| 64 | constexpr ResultCode ERR_OUT_OF_RANGE_KERNEL(-1); | ||
| 65 | constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); | 67 | constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); |
| 66 | /// Returned when Accept() is called on a port with no sessions to be accepted. | 68 | /// Returned when Accept() is called on a port with no sessions to be accepted. |
| 67 | constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); | 69 | constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 1c9373ed8..f500fd2e7 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -273,7 +273,11 @@ static void Break(u64 reason, u64 info1, u64 info2) { | |||
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit | 275 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit |
| 276 | static void OutputDebugString(VAddr address, s32 len) { | 276 | static void OutputDebugString(VAddr address, u64 len) { |
| 277 | if (len == 0) { | ||
| 278 | return; | ||
| 279 | } | ||
| 280 | |||
| 277 | std::string str(len, '\0'); | 281 | std::string str(len, '\0'); |
| 278 | Memory::ReadBlock(address, str.data(), str.size()); | 282 | Memory::ReadBlock(address, str.data(), str.size()); |
| 279 | LOG_DEBUG(Debug_Emulated, "{}", str); | 283 | LOG_DEBUG(Debug_Emulated, "{}", str); |
| @@ -378,7 +382,7 @@ static ResultCode GetThreadPriority(u32* priority, Handle handle) { | |||
| 378 | /// Sets the priority for the specified thread | 382 | /// Sets the priority for the specified thread |
| 379 | static ResultCode SetThreadPriority(Handle handle, u32 priority) { | 383 | static ResultCode SetThreadPriority(Handle handle, u32 priority) { |
| 380 | if (priority > THREADPRIO_LOWEST) { | 384 | if (priority > THREADPRIO_LOWEST) { |
| 381 | return ERR_OUT_OF_RANGE; | 385 | return ERR_INVALID_THREAD_PRIORITY; |
| 382 | } | 386 | } |
| 383 | 387 | ||
| 384 | auto& kernel = Core::System::GetInstance().Kernel(); | 388 | auto& kernel = Core::System::GetInstance().Kernel(); |
| @@ -523,7 +527,7 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 523 | std::string name = fmt::format("unknown-{:X}", entry_point); | 527 | std::string name = fmt::format("unknown-{:X}", entry_point); |
| 524 | 528 | ||
| 525 | if (priority > THREADPRIO_LOWEST) { | 529 | if (priority > THREADPRIO_LOWEST) { |
| 526 | return ERR_OUT_OF_RANGE; | 530 | return ERR_INVALID_THREAD_PRIORITY; |
| 527 | } | 531 | } |
| 528 | 532 | ||
| 529 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; | 533 | SharedPtr<ResourceLimit>& resource_limit = Core::CurrentProcess()->resource_limit; |
| @@ -544,8 +548,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V | |||
| 544 | case THREADPROCESSORID_3: | 548 | case THREADPROCESSORID_3: |
| 545 | break; | 549 | break; |
| 546 | default: | 550 | default: |
| 547 | ASSERT_MSG(false, "Unsupported thread processor ID: {}", processor_id); | 551 | LOG_ERROR(Kernel_SVC, "Invalid thread processor ID: {}", processor_id); |
| 548 | break; | 552 | return ERR_INVALID_PROCESSOR_ID; |
| 549 | } | 553 | } |
| 550 | 554 | ||
| 551 | auto& kernel = Core::System::GetInstance().Kernel(); | 555 | auto& kernel = Core::System::GetInstance().Kernel(); |
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index 79c3fe31b..1eda5f879 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h | |||
| @@ -222,9 +222,9 @@ void SvcWrap() { | |||
| 222 | func((s64)PARAM(0)); | 222 | func((s64)PARAM(0)); |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | template <void func(u64, s32 len)> | 225 | template <void func(u64, u64 len)> |
| 226 | void SvcWrap() { | 226 | void SvcWrap() { |
| 227 | func(PARAM(0), (s32)(PARAM(1) & 0xFFFFFFFF)); | 227 | func(PARAM(0), PARAM(1)); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | template <void func(u64, u64, u64)> | 230 | template <void func(u64, u64, u64)> |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 3d10d9af2..3f12a84dc 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -227,12 +227,12 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name | |||
| 227 | // Check if priority is in ranged. Lowest priority -> highest priority id. | 227 | // Check if priority is in ranged. Lowest priority -> highest priority id. |
| 228 | if (priority > THREADPRIO_LOWEST) { | 228 | if (priority > THREADPRIO_LOWEST) { |
| 229 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); | 229 | LOG_ERROR(Kernel_SVC, "Invalid thread priority: {}", priority); |
| 230 | return ERR_OUT_OF_RANGE; | 230 | return ERR_INVALID_THREAD_PRIORITY; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | if (processor_id > THREADPROCESSORID_MAX) { | 233 | if (processor_id > THREADPROCESSORID_MAX) { |
| 234 | LOG_ERROR(Kernel_SVC, "Invalid processor id: {}", processor_id); | 234 | LOG_ERROR(Kernel_SVC, "Invalid processor id: {}", processor_id); |
| 235 | return ERR_OUT_OF_RANGE_KERNEL; | 235 | return ERR_INVALID_PROCESSOR_ID; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | // TODO(yuriks): Other checks, returning 0xD9001BEA | 238 | // TODO(yuriks): Other checks, returning 0xD9001BEA |
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index da1c46d59..ac0eaaa8f 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp | |||
| @@ -2,6 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <cstring> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 5 | #include <FontChineseSimplified.h> | 9 | #include <FontChineseSimplified.h> |
| 6 | #include <FontChineseTraditional.h> | 10 | #include <FontChineseTraditional.h> |
| 7 | #include <FontExtendedChineseSimplified.h> | 11 | #include <FontExtendedChineseSimplified.h> |
| @@ -9,14 +13,19 @@ | |||
| 9 | #include <FontNintendoExtended.h> | 13 | #include <FontNintendoExtended.h> |
| 10 | #include <FontStandard.h> | 14 | #include <FontStandard.h> |
| 11 | 15 | ||
| 16 | #include "common/assert.h" | ||
| 12 | #include "common/common_paths.h" | 17 | #include "common/common_paths.h" |
| 18 | #include "common/common_types.h" | ||
| 13 | #include "common/file_util.h" | 19 | #include "common/file_util.h" |
| 20 | #include "common/logging/log.h" | ||
| 21 | #include "common/swap.h" | ||
| 14 | #include "core/core.h" | 22 | #include "core/core.h" |
| 15 | #include "core/file_sys/content_archive.h" | 23 | #include "core/file_sys/content_archive.h" |
| 16 | #include "core/file_sys/nca_metadata.h" | 24 | #include "core/file_sys/nca_metadata.h" |
| 17 | #include "core/file_sys/registered_cache.h" | 25 | #include "core/file_sys/registered_cache.h" |
| 18 | #include "core/file_sys/romfs.h" | 26 | #include "core/file_sys/romfs.h" |
| 19 | #include "core/hle/ipc_helpers.h" | 27 | #include "core/hle/ipc_helpers.h" |
| 28 | #include "core/hle/kernel/shared_memory.h" | ||
| 20 | #include "core/hle/service/filesystem/filesystem.h" | 29 | #include "core/hle/service/filesystem/filesystem.h" |
| 21 | #include "core/hle/service/ns/pl_u.h" | 30 | #include "core/hle/service/ns/pl_u.h" |
| 22 | 31 | ||
| @@ -35,49 +44,41 @@ struct FontRegion { | |||
| 35 | u32 size; | 44 | u32 size; |
| 36 | }; | 45 | }; |
| 37 | 46 | ||
| 38 | static constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{ | 47 | constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{ |
| 39 | std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"), | 48 | std::make_pair(FontArchives::Standard, "nintendo_udsg-r_std_003.bfttf"), |
| 40 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"), | 49 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_org_zh-cn_003.bfttf"), |
| 41 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"), | 50 | std::make_pair(FontArchives::ChineseSimple, "nintendo_udsg-r_ext_zh-cn_003.bfttf"), |
| 42 | std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"), | 51 | std::make_pair(FontArchives::ChineseTraditional, "nintendo_udjxh-db_zh-tw_003.bfttf"), |
| 43 | std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"), | 52 | std::make_pair(FontArchives::Korean, "nintendo_udsg-r_ko_003.bfttf"), |
| 44 | std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), | 53 | std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), |
| 45 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf")}; | 54 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), |
| 55 | }; | ||
| 46 | 56 | ||
| 47 | static constexpr std::array<const char*, 7> SHARED_FONTS_TTF{"FontStandard.ttf", | 57 | constexpr std::array<const char*, 7> SHARED_FONTS_TTF{ |
| 48 | "FontChineseSimplified.ttf", | 58 | "FontStandard.ttf", |
| 49 | "FontExtendedChineseSimplified.ttf", | 59 | "FontChineseSimplified.ttf", |
| 50 | "FontChineseTraditional.ttf", | 60 | "FontExtendedChineseSimplified.ttf", |
| 51 | "FontKorean.ttf", | 61 | "FontChineseTraditional.ttf", |
| 52 | "FontNintendoExtended.ttf", | 62 | "FontKorean.ttf", |
| 53 | "FontNintendoExtended2.ttf"}; | 63 | "FontNintendoExtended.ttf", |
| 64 | "FontNintendoExtended2.ttf", | ||
| 65 | }; | ||
| 54 | 66 | ||
| 55 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 | 67 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 |
| 56 | // Virtual address and offsets/sizes likely will vary by dump | 68 | // Virtual address and offsets/sizes likely will vary by dump |
| 57 | static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; | 69 | constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; |
| 58 | static constexpr u32 EXPECTED_RESULT{ | 70 | constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be |
| 59 | 0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be | 71 | constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be |
| 60 | static constexpr u32 EXPECTED_MAGIC{ | 72 | constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; |
| 61 | 0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be | 73 | constexpr FontRegion EMPTY_REGION{0, 0}; |
| 62 | static constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; | ||
| 63 | static constexpr FontRegion EMPTY_REGION{0, 0}; | ||
| 64 | std::vector<FontRegion> | ||
| 65 | SHARED_FONT_REGIONS{}; // Automatically populated based on shared_fonts dump or system archives | ||
| 66 | |||
| 67 | const FontRegion& GetSharedFontRegion(size_t index) { | ||
| 68 | if (index >= SHARED_FONT_REGIONS.size() || SHARED_FONT_REGIONS.empty()) { | ||
| 69 | // No font fallback | ||
| 70 | return EMPTY_REGION; | ||
| 71 | } | ||
| 72 | return SHARED_FONT_REGIONS.at(index); | ||
| 73 | } | ||
| 74 | 74 | ||
| 75 | enum class LoadState : u32 { | 75 | enum class LoadState : u32 { |
| 76 | Loading = 0, | 76 | Loading = 0, |
| 77 | Done = 1, | 77 | Done = 1, |
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, size_t& offset) { | 80 | static void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, |
| 81 | size_t& offset) { | ||
| 81 | ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, | 82 | ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, |
| 82 | "Shared fonts exceeds 17mb!"); | 83 | "Shared fonts exceeds 17mb!"); |
| 83 | ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number"); | 84 | ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number"); |
| @@ -104,28 +105,52 @@ static void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& out | |||
| 104 | offset += input.size() + (sizeof(u32) * 2); | 105 | offset += input.size() + (sizeof(u32) * 2); |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 108 | // Helper function to make BuildSharedFontsRawRegions a bit nicer | ||
| 107 | static u32 GetU32Swapped(const u8* data) { | 109 | static u32 GetU32Swapped(const u8* data) { |
| 108 | u32 value; | 110 | u32 value; |
| 109 | std::memcpy(&value, data, sizeof(value)); | 111 | std::memcpy(&value, data, sizeof(value)); |
| 110 | return Common::swap32(value); // Helper function to make BuildSharedFontsRawRegions a bit nicer | 112 | return Common::swap32(value); |
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | void BuildSharedFontsRawRegions(const std::vector<u8>& input) { | 115 | struct PL_U::Impl { |
| 114 | unsigned cur_offset = 0; // As we can derive the xor key we can just populate the offsets based | 116 | const FontRegion& GetSharedFontRegion(size_t index) const { |
| 115 | // on the shared memory dump | 117 | if (index >= shared_font_regions.size() || shared_font_regions.empty()) { |
| 116 | for (size_t i = 0; i < SHARED_FONTS.size(); i++) { | 118 | // No font fallback |
| 117 | // Out of shared fonts/Invalid font | 119 | return EMPTY_REGION; |
| 118 | if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT) | 120 | } |
| 119 | break; | 121 | return shared_font_regions.at(index); |
| 120 | const u32 KEY = GetU32Swapped(input.data() + cur_offset) ^ | ||
| 121 | EXPECTED_MAGIC; // Derive key withing inverse xor | ||
| 122 | const u32 SIZE = GetU32Swapped(input.data() + cur_offset + 4) ^ KEY; | ||
| 123 | SHARED_FONT_REGIONS.push_back(FontRegion{cur_offset + 8, SIZE}); | ||
| 124 | cur_offset += SIZE + 8; | ||
| 125 | } | 122 | } |
| 126 | } | ||
| 127 | 123 | ||
| 128 | PL_U::PL_U() : ServiceFramework("pl:u") { | 124 | void BuildSharedFontsRawRegions(const std::vector<u8>& input) { |
| 125 | // As we can derive the xor key we can just populate the offsets | ||
| 126 | // based on the shared memory dump | ||
| 127 | unsigned cur_offset = 0; | ||
| 128 | |||
| 129 | for (size_t i = 0; i < SHARED_FONTS.size(); i++) { | ||
| 130 | // Out of shared fonts/invalid font | ||
| 131 | if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT) { | ||
| 132 | break; | ||
| 133 | } | ||
| 134 | |||
| 135 | // Derive key withing inverse xor | ||
| 136 | const u32 KEY = GetU32Swapped(input.data() + cur_offset) ^ EXPECTED_MAGIC; | ||
| 137 | const u32 SIZE = GetU32Swapped(input.data() + cur_offset + 4) ^ KEY; | ||
| 138 | shared_font_regions.push_back(FontRegion{cur_offset + 8, SIZE}); | ||
| 139 | cur_offset += SIZE + 8; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | /// Handle to shared memory region designated for a shared font | ||
| 144 | Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; | ||
| 145 | |||
| 146 | /// Backing memory for the shared font data | ||
| 147 | std::shared_ptr<std::vector<u8>> shared_font; | ||
| 148 | |||
| 149 | // Automatically populated based on shared_fonts dump or system archives. | ||
| 150 | std::vector<FontRegion> shared_font_regions; | ||
| 151 | }; | ||
| 152 | |||
| 153 | PL_U::PL_U() : ServiceFramework("pl:u"), impl{std::make_unique<Impl>()} { | ||
| 129 | static const FunctionInfo functions[] = { | 154 | static const FunctionInfo functions[] = { |
| 130 | {0, &PL_U::RequestLoad, "RequestLoad"}, | 155 | {0, &PL_U::RequestLoad, "RequestLoad"}, |
| 131 | {1, &PL_U::GetLoadState, "GetLoadState"}, | 156 | {1, &PL_U::GetLoadState, "GetLoadState"}, |
| @@ -141,7 +166,7 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 141 | // Rebuild shared fonts from data ncas | 166 | // Rebuild shared fonts from data ncas |
| 142 | if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), | 167 | if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), |
| 143 | FileSys::ContentRecordType::Data)) { | 168 | FileSys::ContentRecordType::Data)) { |
| 144 | shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); | 169 | impl->shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); |
| 145 | for (auto font : SHARED_FONTS) { | 170 | for (auto font : SHARED_FONTS) { |
| 146 | const auto nca = | 171 | const auto nca = |
| 147 | nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data); | 172 | nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data); |
| @@ -177,12 +202,12 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 177 | static_cast<u32>(offset + 8), | 202 | static_cast<u32>(offset + 8), |
| 178 | static_cast<u32>((font_data_u32.size() * sizeof(u32)) - | 203 | static_cast<u32>((font_data_u32.size() * sizeof(u32)) - |
| 179 | 8)}; // Font offset and size do not account for the header | 204 | 8)}; // Font offset and size do not account for the header |
| 180 | DecryptSharedFont(font_data_u32, *shared_font, offset); | 205 | DecryptSharedFont(font_data_u32, *impl->shared_font, offset); |
| 181 | SHARED_FONT_REGIONS.push_back(region); | 206 | impl->shared_font_regions.push_back(region); |
| 182 | } | 207 | } |
| 183 | 208 | ||
| 184 | } else { | 209 | } else { |
| 185 | shared_font = std::make_shared<std::vector<u8>>( | 210 | impl->shared_font = std::make_shared<std::vector<u8>>( |
| 186 | SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size | 211 | SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size |
| 187 | 212 | ||
| 188 | const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir); | 213 | const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir); |
| @@ -206,8 +231,8 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 206 | static_cast<u32>(offset + 8), | 231 | static_cast<u32>(offset + 8), |
| 207 | static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account | 232 | static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account |
| 208 | // for the header | 233 | // for the header |
| 209 | EncryptSharedFont(ttf_bytes, *shared_font, offset); | 234 | EncryptSharedFont(ttf_bytes, *impl->shared_font, offset); |
| 210 | SHARED_FONT_REGIONS.push_back(region); | 235 | impl->shared_font_regions.push_back(region); |
| 211 | } else { | 236 | } else { |
| 212 | LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf); | 237 | LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf); |
| 213 | } | 238 | } |
| @@ -222,8 +247,8 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 222 | if (file.IsOpen()) { | 247 | if (file.IsOpen()) { |
| 223 | // Read shared font data | 248 | // Read shared font data |
| 224 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); | 249 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); |
| 225 | file.ReadBytes(shared_font->data(), shared_font->size()); | 250 | file.ReadBytes(impl->shared_font->data(), impl->shared_font->size()); |
| 226 | BuildSharedFontsRawRegions(*shared_font); | 251 | impl->BuildSharedFontsRawRegions(*impl->shared_font); |
| 227 | } else { | 252 | } else { |
| 228 | LOG_WARNING(Service_NS, | 253 | LOG_WARNING(Service_NS, |
| 229 | "Shared Font file missing. Loading open source replacement from memory"); | 254 | "Shared Font file missing. Loading open source replacement from memory"); |
| @@ -240,8 +265,8 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 240 | for (const std::vector<u8>& font_ttf : open_source_shared_fonts_ttf) { | 265 | for (const std::vector<u8>& font_ttf : open_source_shared_fonts_ttf) { |
| 241 | const FontRegion region{static_cast<u32>(offset + 8), | 266 | const FontRegion region{static_cast<u32>(offset + 8), |
| 242 | static_cast<u32>(font_ttf.size())}; | 267 | static_cast<u32>(font_ttf.size())}; |
| 243 | EncryptSharedFont(font_ttf, *shared_font, offset); | 268 | EncryptSharedFont(font_ttf, *impl->shared_font, offset); |
| 244 | SHARED_FONT_REGIONS.push_back(region); | 269 | impl->shared_font_regions.push_back(region); |
| 245 | } | 270 | } |
| 246 | } | 271 | } |
| 247 | } | 272 | } |
| @@ -275,7 +300,7 @@ void PL_U::GetSize(Kernel::HLERequestContext& ctx) { | |||
| 275 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); | 300 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); |
| 276 | IPC::ResponseBuilder rb{ctx, 3}; | 301 | IPC::ResponseBuilder rb{ctx, 3}; |
| 277 | rb.Push(RESULT_SUCCESS); | 302 | rb.Push(RESULT_SUCCESS); |
| 278 | rb.Push<u32>(GetSharedFontRegion(font_id).size); | 303 | rb.Push<u32>(impl->GetSharedFontRegion(font_id).size); |
| 279 | } | 304 | } |
| 280 | 305 | ||
| 281 | void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { | 306 | void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { |
| @@ -285,17 +310,18 @@ void PL_U::GetSharedMemoryAddressOffset(Kernel::HLERequestContext& ctx) { | |||
| 285 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); | 310 | LOG_DEBUG(Service_NS, "called, font_id={}", font_id); |
| 286 | IPC::ResponseBuilder rb{ctx, 3}; | 311 | IPC::ResponseBuilder rb{ctx, 3}; |
| 287 | rb.Push(RESULT_SUCCESS); | 312 | rb.Push(RESULT_SUCCESS); |
| 288 | rb.Push<u32>(GetSharedFontRegion(font_id).offset); | 313 | rb.Push<u32>(impl->GetSharedFontRegion(font_id).offset); |
| 289 | } | 314 | } |
| 290 | 315 | ||
| 291 | void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { | 316 | void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { |
| 292 | // Map backing memory for the font data | 317 | // Map backing memory for the font data |
| 293 | Core::CurrentProcess()->vm_manager.MapMemoryBlock( | 318 | Core::CurrentProcess()->vm_manager.MapMemoryBlock(SHARED_FONT_MEM_VADDR, impl->shared_font, 0, |
| 294 | SHARED_FONT_MEM_VADDR, shared_font, 0, SHARED_FONT_MEM_SIZE, Kernel::MemoryState::Shared); | 319 | SHARED_FONT_MEM_SIZE, |
| 320 | Kernel::MemoryState::Shared); | ||
| 295 | 321 | ||
| 296 | // Create shared font memory object | 322 | // Create shared font memory object |
| 297 | auto& kernel = Core::System::GetInstance().Kernel(); | 323 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 298 | shared_font_mem = Kernel::SharedMemory::Create( | 324 | impl->shared_font_mem = Kernel::SharedMemory::Create( |
| 299 | kernel, Core::CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, | 325 | kernel, Core::CurrentProcess(), SHARED_FONT_MEM_SIZE, Kernel::MemoryPermission::ReadWrite, |
| 300 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, | 326 | Kernel::MemoryPermission::Read, SHARED_FONT_MEM_VADDR, Kernel::MemoryRegion::BASE, |
| 301 | "PL_U:shared_font_mem"); | 327 | "PL_U:shared_font_mem"); |
| @@ -303,7 +329,7 @@ void PL_U::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) { | |||
| 303 | LOG_DEBUG(Service_NS, "called"); | 329 | LOG_DEBUG(Service_NS, "called"); |
| 304 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 330 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 305 | rb.Push(RESULT_SUCCESS); | 331 | rb.Push(RESULT_SUCCESS); |
| 306 | rb.PushCopyObjects(shared_font_mem); | 332 | rb.PushCopyObjects(impl->shared_font_mem); |
| 307 | } | 333 | } |
| 308 | 334 | ||
| 309 | void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { | 335 | void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { |
| @@ -316,9 +342,9 @@ void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) { | |||
| 316 | std::vector<u32> font_sizes; | 342 | std::vector<u32> font_sizes; |
| 317 | 343 | ||
| 318 | // TODO(ogniK): Have actual priority order | 344 | // TODO(ogniK): Have actual priority order |
| 319 | for (size_t i = 0; i < SHARED_FONT_REGIONS.size(); i++) { | 345 | for (size_t i = 0; i < impl->shared_font_regions.size(); i++) { |
| 320 | font_codes.push_back(static_cast<u32>(i)); | 346 | font_codes.push_back(static_cast<u32>(i)); |
| 321 | auto region = GetSharedFontRegion(i); | 347 | auto region = impl->GetSharedFontRegion(i); |
| 322 | font_offsets.push_back(region.offset); | 348 | font_offsets.push_back(region.offset); |
| 323 | font_sizes.push_back(region.size); | 349 | font_sizes.push_back(region.size); |
| 324 | } | 350 | } |
diff --git a/src/core/hle/service/ns/pl_u.h b/src/core/hle/service/ns/pl_u.h index 296c3db05..253f26a2a 100644 --- a/src/core/hle/service/ns/pl_u.h +++ b/src/core/hle/service/ns/pl_u.h | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include "core/hle/kernel/shared_memory.h" | ||
| 9 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 10 | 9 | ||
| 11 | namespace Service::NS { | 10 | namespace Service::NS { |
| @@ -23,11 +22,8 @@ private: | |||
| 23 | void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); | 22 | void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx); |
| 24 | void GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx); | 23 | void GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx); |
| 25 | 24 | ||
| 26 | /// Handle to shared memory region designated for a shared font | 25 | struct Impl; |
| 27 | Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem; | 26 | std::unique_ptr<Impl> impl; |
| 28 | |||
| 29 | /// Backing memory for the shared font data | ||
| 30 | std::shared_ptr<std::vector<u8>> shared_font; | ||
| 31 | }; | 27 | }; |
| 32 | 28 | ||
| 33 | } // namespace Service::NS | 29 | } // namespace Service::NS |
diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index 3c43b8d8c..6a9eccfb5 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp | |||
| @@ -1,36 +1,47 @@ | |||
| 1 | #include <cinttypes> | 1 | // Copyright 2018 yuzu emulator team |
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 2 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 3 | #include "core/hle/ipc_helpers.h" | 6 | #include "core/hle/ipc_helpers.h" |
| 4 | #include "core/hle/kernel/event.h" | ||
| 5 | #include "core/hle/service/prepo/prepo.h" | 7 | #include "core/hle/service/prepo/prepo.h" |
| 8 | #include "core/hle/service/service.h" | ||
| 6 | 9 | ||
| 7 | namespace Service::PlayReport { | 10 | namespace Service::PlayReport { |
| 8 | PlayReport::PlayReport(const char* name) : ServiceFramework(name) { | ||
| 9 | static const FunctionInfo functions[] = { | ||
| 10 | {10100, nullptr, "SaveReport"}, | ||
| 11 | {10101, &PlayReport::SaveReportWithUser, "SaveReportWithUser"}, | ||
| 12 | {10200, nullptr, "RequestImmediateTransmission"}, | ||
| 13 | {10300, nullptr, "GetTransmissionStatus"}, | ||
| 14 | {20100, nullptr, "SaveSystemReport"}, | ||
| 15 | {20200, nullptr, "SetOperationMode"}, | ||
| 16 | {20101, nullptr, "SaveSystemReportWithUser"}, | ||
| 17 | {30100, nullptr, "ClearStorage"}, | ||
| 18 | {40100, nullptr, "IsUserAgreementCheckEnabled"}, | ||
| 19 | {40101, nullptr, "SetUserAgreementCheckEnabled"}, | ||
| 20 | {90100, nullptr, "GetStorageUsage"}, | ||
| 21 | {90200, nullptr, "GetStatistics"}, | ||
| 22 | {90201, nullptr, "GetThroughputHistory"}, | ||
| 23 | {90300, nullptr, "GetLastUploadError"}, | ||
| 24 | }; | ||
| 25 | RegisterHandlers(functions); | ||
| 26 | }; | ||
| 27 | 11 | ||
| 28 | void PlayReport::SaveReportWithUser(Kernel::HLERequestContext& ctx) { | 12 | class PlayReport final : public ServiceFramework<PlayReport> { |
| 29 | // TODO(ogniK): Do we want to add play report? | 13 | public: |
| 30 | LOG_WARNING(Service_PREPO, "(STUBBED) called"); | 14 | explicit PlayReport(const char* name) : ServiceFramework{name} { |
| 15 | // clang-format off | ||
| 16 | static const FunctionInfo functions[] = { | ||
| 17 | {10100, nullptr, "SaveReport"}, | ||
| 18 | {10101, &PlayReport::SaveReportWithUser, "SaveReportWithUser"}, | ||
| 19 | {10200, nullptr, "RequestImmediateTransmission"}, | ||
| 20 | {10300, nullptr, "GetTransmissionStatus"}, | ||
| 21 | {20100, nullptr, "SaveSystemReport"}, | ||
| 22 | {20200, nullptr, "SetOperationMode"}, | ||
| 23 | {20101, nullptr, "SaveSystemReportWithUser"}, | ||
| 24 | {30100, nullptr, "ClearStorage"}, | ||
| 25 | {40100, nullptr, "IsUserAgreementCheckEnabled"}, | ||
| 26 | {40101, nullptr, "SetUserAgreementCheckEnabled"}, | ||
| 27 | {90100, nullptr, "GetStorageUsage"}, | ||
| 28 | {90200, nullptr, "GetStatistics"}, | ||
| 29 | {90201, nullptr, "GetThroughputHistory"}, | ||
| 30 | {90300, nullptr, "GetLastUploadError"}, | ||
| 31 | }; | ||
| 32 | // clang-format on | ||
| 33 | |||
| 34 | RegisterHandlers(functions); | ||
| 35 | } | ||
| 36 | |||
| 37 | private: | ||
| 38 | void SaveReportWithUser(Kernel::HLERequestContext& ctx) { | ||
| 39 | // TODO(ogniK): Do we want to add play report? | ||
| 40 | LOG_WARNING(Service_PREPO, "(STUBBED) called"); | ||
| 31 | 41 | ||
| 32 | IPC::ResponseBuilder rb{ctx, 2}; | 42 | IPC::ResponseBuilder rb{ctx, 2}; |
| 33 | rb.Push(RESULT_SUCCESS); | 43 | rb.Push(RESULT_SUCCESS); |
| 44 | } | ||
| 34 | }; | 45 | }; |
| 35 | 46 | ||
| 36 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 47 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
diff --git a/src/core/hle/service/prepo/prepo.h b/src/core/hle/service/prepo/prepo.h index f5a6aba6d..0e7b01331 100644 --- a/src/core/hle/service/prepo/prepo.h +++ b/src/core/hle/service/prepo/prepo.h | |||
| @@ -4,22 +4,12 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <memory> | 7 | namespace Service::SM { |
| 8 | #include <string> | 8 | class ServiceManager; |
| 9 | #include "core/hle/kernel/event.h" | 9 | } |
| 10 | #include "core/hle/service/service.h" | ||
| 11 | 10 | ||
| 12 | namespace Service::PlayReport { | 11 | namespace Service::PlayReport { |
| 13 | 12 | ||
| 14 | class PlayReport final : public ServiceFramework<PlayReport> { | ||
| 15 | public: | ||
| 16 | explicit PlayReport(const char* name); | ||
| 17 | ~PlayReport() = default; | ||
| 18 | |||
| 19 | private: | ||
| 20 | void SaveReportWithUser(Kernel::HLERequestContext& ctx); | ||
| 21 | }; | ||
| 22 | |||
| 23 | void InstallInterfaces(SM::ServiceManager& service_manager); | 13 | void InstallInterfaces(SM::ServiceManager& service_manager); |
| 24 | 14 | ||
| 25 | } // namespace Service::PlayReport | 15 | } // namespace Service::PlayReport |
diff --git a/src/core/settings.h b/src/core/settings.h index 08a16ef2c..0318d019c 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -148,6 +148,7 @@ struct Values { | |||
| 148 | 148 | ||
| 149 | // Audio | 149 | // Audio |
| 150 | std::string sink_id; | 150 | std::string sink_id; |
| 151 | bool enable_audio_stretching; | ||
| 151 | std::string audio_device_id; | 152 | std::string audio_device_id; |
| 152 | float volume; | 153 | float volume; |
| 153 | 154 | ||
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 3730e85b8..b0df154ca 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -120,6 +120,9 @@ TelemetrySession::TelemetrySession() { | |||
| 120 | Telemetry::AppendOSInfo(field_collection); | 120 | Telemetry::AppendOSInfo(field_collection); |
| 121 | 121 | ||
| 122 | // Log user configuration information | 122 | // Log user configuration information |
| 123 | AddField(Telemetry::FieldType::UserConfig, "Audio_SinkId", Settings::values.sink_id); | ||
| 124 | AddField(Telemetry::FieldType::UserConfig, "Audio_EnableAudioStretching", | ||
| 125 | Settings::values.enable_audio_stretching); | ||
| 123 | AddField(Telemetry::FieldType::UserConfig, "Core_UseCpuJit", Settings::values.use_cpu_jit); | 126 | AddField(Telemetry::FieldType::UserConfig, "Core_UseCpuJit", Settings::values.use_cpu_jit); |
| 124 | AddField(Telemetry::FieldType::UserConfig, "Core_UseMultiCore", | 127 | AddField(Telemetry::FieldType::UserConfig, "Core_UseMultiCore", |
| 125 | Settings::values.use_multi_core); | 128 | Settings::values.use_multi_core); |
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 4d74bb395..4e75a72ec 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | add_executable(tests | 1 | add_executable(tests |
| 2 | common/param_package.cpp | 2 | common/param_package.cpp |
| 3 | common/ring_buffer.cpp | ||
| 3 | core/arm/arm_test_common.cpp | 4 | core/arm/arm_test_common.cpp |
| 4 | core/arm/arm_test_common.h | 5 | core/arm/arm_test_common.h |
| 5 | core/core_timing.cpp | 6 | core/core_timing.cpp |
diff --git a/src/tests/common/ring_buffer.cpp b/src/tests/common/ring_buffer.cpp new file mode 100644 index 000000000..f3fe57839 --- /dev/null +++ b/src/tests/common/ring_buffer.cpp | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <array> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <numeric> | ||
| 9 | #include <thread> | ||
| 10 | #include <vector> | ||
| 11 | #include <catch2/catch.hpp> | ||
| 12 | #include "common/ring_buffer.h" | ||
| 13 | |||
| 14 | namespace Common { | ||
| 15 | |||
| 16 | TEST_CASE("RingBuffer: Basic Tests", "[common]") { | ||
| 17 | RingBuffer<char, 4, 1> buf; | ||
| 18 | |||
| 19 | // Pushing values into a ring buffer with space should succeed. | ||
| 20 | for (size_t i = 0; i < 4; i++) { | ||
| 21 | const char elem = static_cast<char>(i); | ||
| 22 | const size_t count = buf.Push(&elem, 1); | ||
| 23 | REQUIRE(count == 1); | ||
| 24 | } | ||
| 25 | |||
| 26 | REQUIRE(buf.Size() == 4); | ||
| 27 | |||
| 28 | // Pushing values into a full ring buffer should fail. | ||
| 29 | { | ||
| 30 | const char elem = static_cast<char>(42); | ||
| 31 | const size_t count = buf.Push(&elem, 1); | ||
| 32 | REQUIRE(count == 0); | ||
| 33 | } | ||
| 34 | |||
| 35 | REQUIRE(buf.Size() == 4); | ||
| 36 | |||
| 37 | // Popping multiple values from a ring buffer with values should succeed. | ||
| 38 | { | ||
| 39 | const std::vector<char> popped = buf.Pop(2); | ||
| 40 | REQUIRE(popped.size() == 2); | ||
| 41 | REQUIRE(popped[0] == 0); | ||
| 42 | REQUIRE(popped[1] == 1); | ||
| 43 | } | ||
| 44 | |||
| 45 | REQUIRE(buf.Size() == 2); | ||
| 46 | |||
| 47 | // Popping a single value from a ring buffer with values should succeed. | ||
| 48 | { | ||
| 49 | const std::vector<char> popped = buf.Pop(1); | ||
| 50 | REQUIRE(popped.size() == 1); | ||
| 51 | REQUIRE(popped[0] == 2); | ||
| 52 | } | ||
| 53 | |||
| 54 | REQUIRE(buf.Size() == 1); | ||
| 55 | |||
| 56 | // Pushing more values than space available should partially suceed. | ||
| 57 | { | ||
| 58 | std::vector<char> to_push(6); | ||
| 59 | std::iota(to_push.begin(), to_push.end(), 88); | ||
| 60 | const size_t count = buf.Push(to_push); | ||
| 61 | REQUIRE(count == 3); | ||
| 62 | } | ||
| 63 | |||
| 64 | REQUIRE(buf.Size() == 4); | ||
| 65 | |||
| 66 | // Doing an unlimited pop should pop all values. | ||
| 67 | { | ||
| 68 | const std::vector<char> popped = buf.Pop(); | ||
| 69 | REQUIRE(popped.size() == 4); | ||
| 70 | REQUIRE(popped[0] == 3); | ||
| 71 | REQUIRE(popped[1] == 88); | ||
| 72 | REQUIRE(popped[2] == 89); | ||
| 73 | REQUIRE(popped[3] == 90); | ||
| 74 | } | ||
| 75 | |||
| 76 | REQUIRE(buf.Size() == 0); | ||
| 77 | } | ||
| 78 | |||
| 79 | TEST_CASE("RingBuffer: Threaded Test", "[common]") { | ||
| 80 | RingBuffer<char, 4, 2> buf; | ||
| 81 | const char seed = 42; | ||
| 82 | const size_t count = 1000000; | ||
| 83 | size_t full = 0; | ||
| 84 | size_t empty = 0; | ||
| 85 | |||
| 86 | const auto next_value = [](std::array<char, 2>& value) { | ||
| 87 | value[0] += 1; | ||
| 88 | value[1] += 2; | ||
| 89 | }; | ||
| 90 | |||
| 91 | std::thread producer{[&] { | ||
| 92 | std::array<char, 2> value = {seed, seed}; | ||
| 93 | size_t i = 0; | ||
| 94 | while (i < count) { | ||
| 95 | if (const size_t c = buf.Push(&value[0], 1); c > 0) { | ||
| 96 | REQUIRE(c == 1); | ||
| 97 | i++; | ||
| 98 | next_value(value); | ||
| 99 | } else { | ||
| 100 | full++; | ||
| 101 | std::this_thread::yield(); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | }}; | ||
| 105 | |||
| 106 | std::thread consumer{[&] { | ||
| 107 | std::array<char, 2> value = {seed, seed}; | ||
| 108 | size_t i = 0; | ||
| 109 | while (i < count) { | ||
| 110 | if (const std::vector<char> v = buf.Pop(1); v.size() > 0) { | ||
| 111 | REQUIRE(v.size() == 2); | ||
| 112 | REQUIRE(v[0] == value[0]); | ||
| 113 | REQUIRE(v[1] == value[1]); | ||
| 114 | i++; | ||
| 115 | next_value(value); | ||
| 116 | } else { | ||
| 117 | empty++; | ||
| 118 | std::this_thread::yield(); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | }}; | ||
| 122 | |||
| 123 | producer.join(); | ||
| 124 | consumer.join(); | ||
| 125 | |||
| 126 | REQUIRE(buf.Size() == 0); | ||
| 127 | printf("RingBuffer: Threaded Test: full: %zu, empty: %zu\n", full, empty); | ||
| 128 | } | ||
| 129 | |||
| 130 | } // namespace Common | ||
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 2db906ea5..58f2904ce 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h | |||
| @@ -254,6 +254,15 @@ enum class TextureQueryType : u64 { | |||
| 254 | BorderColor = 22, | 254 | BorderColor = 22, |
| 255 | }; | 255 | }; |
| 256 | 256 | ||
| 257 | enum class TextureProcessMode : u64 { | ||
| 258 | None = 0, | ||
| 259 | LZ = 1, // Unknown, appears to be the same as none. | ||
| 260 | LB = 2, // Load Bias. | ||
| 261 | LL = 3, // Load LOD (LevelOfDetail) | ||
| 262 | LBA = 6, // Load Bias. The A is unknown, does not appear to differ with LB | ||
| 263 | LLA = 7 // Load LOD. The A is unknown, does not appear to differ with LL | ||
| 264 | }; | ||
| 265 | |||
| 257 | enum class IpaInterpMode : u64 { Linear = 0, Perspective = 1, Flat = 2, Sc = 3 }; | 266 | enum class IpaInterpMode : u64 { Linear = 0, Perspective = 1, Flat = 2, Sc = 3 }; |
| 258 | enum class IpaSampleMode : u64 { Default = 0, Centroid = 1, Offset = 2 }; | 267 | enum class IpaSampleMode : u64 { Default = 0, Centroid = 1, Offset = 2 }; |
| 259 | 268 | ||
| @@ -573,6 +582,7 @@ union Instruction { | |||
| 573 | BitField<28, 1, u64> array; | 582 | BitField<28, 1, u64> array; |
| 574 | BitField<29, 2, TextureType> texture_type; | 583 | BitField<29, 2, TextureType> texture_type; |
| 575 | BitField<31, 4, u64> component_mask; | 584 | BitField<31, 4, u64> component_mask; |
| 585 | BitField<55, 3, TextureProcessMode> process_mode; | ||
| 576 | 586 | ||
| 577 | bool IsComponentEnabled(size_t component) const { | 587 | bool IsComponentEnabled(size_t component) const { |
| 578 | return ((1ull << component) & component_mask) != 0; | 588 | return ((1ull << component) & component_mask) != 0; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index fb56decc0..32001e44b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -116,7 +116,7 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form | |||
| 116 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8U | 116 | {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, ComponentType::UNorm, false}, // ABGR8U |
| 117 | {GL_RGBA8, GL_RGBA, GL_BYTE, ComponentType::SNorm, false}, // ABGR8S | 117 | {GL_RGBA8, GL_RGBA, GL_BYTE, ComponentType::SNorm, false}, // ABGR8S |
| 118 | {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, ComponentType::UInt, false}, // ABGR8UI | 118 | {GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, ComponentType::UInt, false}, // ABGR8UI |
| 119 | {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5U | 119 | {GL_RGB8, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, ComponentType::UNorm, false}, // B5G6R5U |
| 120 | {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, ComponentType::UNorm, | 120 | {GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, ComponentType::UNorm, |
| 121 | false}, // A2B10G10R10U | 121 | false}, // A2B10G10R10U |
| 122 | {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, ComponentType::UNorm, false}, // A1B5G5R5U | 122 | {GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, ComponentType::UNorm, false}, // A1B5G5R5U |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 582c811e0..2d56370c7 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -1853,15 +1853,47 @@ private: | |||
| 1853 | coord = "vec2 coords = vec2(" + x + ", " + y + ");"; | 1853 | coord = "vec2 coords = vec2(" + x + ", " + y + ");"; |
| 1854 | texture_type = Tegra::Shader::TextureType::Texture2D; | 1854 | texture_type = Tegra::Shader::TextureType::Texture2D; |
| 1855 | } | 1855 | } |
| 1856 | // TODO: make sure coordinates are always indexed to gpr8 and gpr20 is always bias | ||
| 1857 | // or lod. | ||
| 1858 | const std::string op_c = regs.GetRegisterAsFloat(instr.gpr20); | ||
| 1856 | 1859 | ||
| 1857 | const std::string sampler = GetSampler(instr.sampler, texture_type, false); | 1860 | const std::string sampler = GetSampler(instr.sampler, texture_type, false); |
| 1858 | // Add an extra scope and declare the texture coords inside to prevent | 1861 | // Add an extra scope and declare the texture coords inside to prevent |
| 1859 | // overwriting them in case they are used as outputs of the texs instruction. | 1862 | // overwriting them in case they are used as outputs of the texs instruction. |
| 1863 | |||
| 1860 | shader.AddLine("{"); | 1864 | shader.AddLine("{"); |
| 1861 | ++shader.scope; | 1865 | ++shader.scope; |
| 1862 | shader.AddLine(coord); | 1866 | shader.AddLine(coord); |
| 1863 | const std::string texture = "texture(" + sampler + ", coords)"; | 1867 | std::string texture; |
| 1864 | 1868 | ||
| 1869 | switch (instr.tex.process_mode) { | ||
| 1870 | case Tegra::Shader::TextureProcessMode::None: { | ||
| 1871 | texture = "texture(" + sampler + ", coords)"; | ||
| 1872 | break; | ||
| 1873 | } | ||
| 1874 | case Tegra::Shader::TextureProcessMode::LZ: { | ||
| 1875 | texture = "textureLod(" + sampler + ", coords, 0.0)"; | ||
| 1876 | break; | ||
| 1877 | } | ||
| 1878 | case Tegra::Shader::TextureProcessMode::LB: | ||
| 1879 | case Tegra::Shader::TextureProcessMode::LBA: { | ||
| 1880 | // TODO: Figure if A suffix changes the equation at all. | ||
| 1881 | texture = "texture(" + sampler + ", coords, " + op_c + ')'; | ||
| 1882 | break; | ||
| 1883 | } | ||
| 1884 | case Tegra::Shader::TextureProcessMode::LL: | ||
| 1885 | case Tegra::Shader::TextureProcessMode::LLA: { | ||
| 1886 | // TODO: Figure if A suffix changes the equation at all. | ||
| 1887 | texture = "textureLod(" + sampler + ", coords, " + op_c + ')'; | ||
| 1888 | break; | ||
| 1889 | } | ||
| 1890 | default: { | ||
| 1891 | texture = "texture(" + sampler + ", coords)"; | ||
| 1892 | LOG_CRITICAL(HW_GPU, "Unhandled texture process mode {}", | ||
| 1893 | static_cast<u32>(instr.tex.process_mode.Value())); | ||
| 1894 | UNREACHABLE(); | ||
| 1895 | } | ||
| 1896 | } | ||
| 1865 | size_t dest_elem{}; | 1897 | size_t dest_elem{}; |
| 1866 | for (size_t elem = 0; elem < 4; ++elem) { | 1898 | for (size_t elem = 0; elem < 4; ++elem) { |
| 1867 | if (!instr.tex.IsComponentEnabled(elem)) { | 1899 | if (!instr.tex.IsComponentEnabled(elem)) { |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index c43e79e78..d229225b4 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -95,6 +95,8 @@ void Config::ReadValues() { | |||
| 95 | 95 | ||
| 96 | qt_config->beginGroup("Audio"); | 96 | qt_config->beginGroup("Audio"); |
| 97 | Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); | 97 | Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); |
| 98 | Settings::values.enable_audio_stretching = | ||
| 99 | qt_config->value("enable_audio_stretching", true).toBool(); | ||
| 98 | Settings::values.audio_device_id = | 100 | Settings::values.audio_device_id = |
| 99 | qt_config->value("output_device", "auto").toString().toStdString(); | 101 | qt_config->value("output_device", "auto").toString().toStdString(); |
| 100 | Settings::values.volume = qt_config->value("volume", 1).toFloat(); | 102 | Settings::values.volume = qt_config->value("volume", 1).toFloat(); |
| @@ -230,6 +232,7 @@ void Config::SaveValues() { | |||
| 230 | 232 | ||
| 231 | qt_config->beginGroup("Audio"); | 233 | qt_config->beginGroup("Audio"); |
| 232 | qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); | 234 | qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); |
| 235 | qt_config->setValue("enable_audio_stretching", Settings::values.enable_audio_stretching); | ||
| 233 | qt_config->setValue("output_device", QString::fromStdString(Settings::values.audio_device_id)); | 236 | qt_config->setValue("output_device", QString::fromStdString(Settings::values.audio_device_id)); |
| 234 | qt_config->setValue("volume", Settings::values.volume); | 237 | qt_config->setValue("volume", Settings::values.volume); |
| 235 | qt_config->endGroup(); | 238 | qt_config->endGroup(); |
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index fbb813f6c..6ea59f2a3 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp | |||
| @@ -46,6 +46,8 @@ void ConfigureAudio::setConfiguration() { | |||
| 46 | } | 46 | } |
| 47 | ui->output_sink_combo_box->setCurrentIndex(new_sink_index); | 47 | ui->output_sink_combo_box->setCurrentIndex(new_sink_index); |
| 48 | 48 | ||
| 49 | ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching); | ||
| 50 | |||
| 49 | // The device list cannot be pre-populated (nor listed) until the output sink is known. | 51 | // The device list cannot be pre-populated (nor listed) until the output sink is known. |
| 50 | updateAudioDevices(new_sink_index); | 52 | updateAudioDevices(new_sink_index); |
| 51 | 53 | ||
| @@ -67,6 +69,7 @@ void ConfigureAudio::applyConfiguration() { | |||
| 67 | Settings::values.sink_id = | 69 | Settings::values.sink_id = |
| 68 | ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()) | 70 | ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()) |
| 69 | .toStdString(); | 71 | .toStdString(); |
| 72 | Settings::values.enable_audio_stretching = ui->toggle_audio_stretching->isChecked(); | ||
| 70 | Settings::values.audio_device_id = | 73 | Settings::values.audio_device_id = |
| 71 | ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) | 74 | ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) |
| 72 | .toStdString(); | 75 | .toStdString(); |
diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui index ef67890dc..a29a0e265 100644 --- a/src/yuzu/configuration/configure_audio.ui +++ b/src/yuzu/configuration/configure_audio.ui | |||
| @@ -31,6 +31,16 @@ | |||
| 31 | </item> | 31 | </item> |
| 32 | </layout> | 32 | </layout> |
| 33 | </item> | 33 | </item> |
| 34 | <item> | ||
| 35 | <widget class="QCheckBox" name="toggle_audio_stretching"> | ||
| 36 | <property name="toolTip"> | ||
| 37 | <string>This post-processing effect adjusts audio speed to match emulation speed and helps prevent audio stutter. This however increases audio latency.</string> | ||
| 38 | </property> | ||
| 39 | <property name="text"> | ||
| 40 | <string>Enable audio stretching</string> | ||
| 41 | </property> | ||
| 42 | </widget> | ||
| 43 | </item> | ||
| 34 | <item> | 44 | <item> |
| 35 | <layout class="QHBoxLayout"> | 45 | <layout class="QHBoxLayout"> |
| 36 | <item> | 46 | <item> |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 8c6e16d47..3b3b551bb 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -366,7 +366,7 @@ void GameList::LoadCompatibilityList() { | |||
| 366 | QJsonDocument json = QJsonDocument::fromJson(string_content.toUtf8()); | 366 | QJsonDocument json = QJsonDocument::fromJson(string_content.toUtf8()); |
| 367 | QJsonArray arr = json.array(); | 367 | QJsonArray arr = json.array(); |
| 368 | 368 | ||
| 369 | for (const QJsonValue& value : arr) { | 369 | for (const QJsonValueRef& value : arr) { |
| 370 | QJsonObject game = value.toObject(); | 370 | QJsonObject game = value.toObject(); |
| 371 | 371 | ||
| 372 | if (game.contains("compatibility") && game["compatibility"].isDouble()) { | 372 | if (game.contains("compatibility") && game["compatibility"].isDouble()) { |
| @@ -374,9 +374,9 @@ void GameList::LoadCompatibilityList() { | |||
| 374 | QString directory = game["directory"].toString(); | 374 | QString directory = game["directory"].toString(); |
| 375 | QJsonArray ids = game["releases"].toArray(); | 375 | QJsonArray ids = game["releases"].toArray(); |
| 376 | 376 | ||
| 377 | for (const QJsonValue& value : ids) { | 377 | for (const QJsonValueRef& id_ref : ids) { |
| 378 | QJsonObject object = value.toObject(); | 378 | QJsonObject id_object = id_ref.toObject(); |
| 379 | QString id = object["id"].toString(); | 379 | QString id = id_object["id"].toString(); |
| 380 | compatibility_list.emplace( | 380 | compatibility_list.emplace( |
| 381 | id.toUpper().toStdString(), | 381 | id.toUpper().toStdString(), |
| 382 | std::make_pair(QString::number(compatibility), directory)); | 382 | std::make_pair(QString::number(compatibility), directory)); |
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index f00b5a66b..991abda2e 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -108,6 +108,8 @@ void Config::ReadValues() { | |||
| 108 | 108 | ||
| 109 | // Audio | 109 | // Audio |
| 110 | Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto"); | 110 | Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto"); |
| 111 | Settings::values.enable_audio_stretching = | ||
| 112 | sdl2_config->GetBoolean("Audio", "enable_audio_stretching", true); | ||
| 111 | Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); | 113 | Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); |
| 112 | Settings::values.volume = sdl2_config->GetReal("Audio", "volume", 1); | 114 | Settings::values.volume = sdl2_config->GetReal("Audio", "volume", 1); |
| 113 | 115 | ||
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 6ed9e7962..002a4ec15 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h | |||
| @@ -150,6 +150,12 @@ swap_screen = | |||
| 150 | # auto (default): Auto-select, null: No audio output, cubeb: Cubeb audio engine (if available) | 150 | # auto (default): Auto-select, null: No audio output, cubeb: Cubeb audio engine (if available) |
| 151 | output_engine = | 151 | output_engine = |
| 152 | 152 | ||
| 153 | # Whether or not to enable the audio-stretching post-processing effect. | ||
| 154 | # This effect adjusts audio speed to match emulation speed and helps prevent audio stutter, | ||
| 155 | # at the cost of increasing audio latency. | ||
| 156 | # 0: No, 1 (default): Yes | ||
| 157 | enable_audio_stretching = | ||
| 158 | |||
| 153 | # Which audio device to use. | 159 | # Which audio device to use. |
| 154 | # auto (default): Auto-select | 160 | # auto (default): Auto-select |
| 155 | output_device = | 161 | output_device = |