mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	audio_core: Only perform audio stretching if below full speed. (#7201)
This commit is contained in:
		
							parent
							
								
									c0ecdb689d
								
							
						
					
					
						commit
						670e9936a4
					
				
					 13 changed files with 83 additions and 52 deletions
				
			
		|  | @ -354,6 +354,10 @@ PerfStats::Results System::GetAndResetPerfStats() { | |||
|                                   : PerfStats::Results{}; | ||||
| } | ||||
| 
 | ||||
| PerfStats::Results System::GetLastPerfStats() { | ||||
|     return perf_stats ? perf_stats->GetLastStats() : PerfStats::Results{}; | ||||
| } | ||||
| 
 | ||||
| void System::Reschedule() { | ||||
|     if (!reschedule_pending) { | ||||
|         return; | ||||
|  | @ -408,10 +412,10 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, | |||
| 
 | ||||
|     const auto audio_emulation = Settings::values.audio_emulation.GetValue(); | ||||
|     if (audio_emulation == Settings::AudioEmulation::HLE) { | ||||
|         dsp_core = std::make_unique<AudioCore::DspHle>(*memory, *timing); | ||||
|         dsp_core = std::make_unique<AudioCore::DspHle>(*this); | ||||
|     } else { | ||||
|         const bool multithread = audio_emulation == Settings::AudioEmulation::LLEMultithreaded; | ||||
|         dsp_core = std::make_unique<AudioCore::DspLle>(*memory, *timing, multithread); | ||||
|         dsp_core = std::make_unique<AudioCore::DspLle>(*this, multithread); | ||||
|     } | ||||
| 
 | ||||
|     memory->SetDSP(*dsp_core); | ||||
|  |  | |||
|  | @ -174,6 +174,8 @@ public: | |||
| 
 | ||||
|     [[nodiscard]] PerfStats::Results GetAndResetPerfStats(); | ||||
| 
 | ||||
|     [[nodiscard]] PerfStats::Results GetLastPerfStats(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Gets a reference to the emulated CPU. | ||||
|      * @returns A reference to the emulated CPU. | ||||
|  |  | |||
|  | @ -47,13 +47,13 @@ PerfStats::~PerfStats() { | |||
| } | ||||
| 
 | ||||
| void PerfStats::BeginSystemFrame() { | ||||
|     std::lock_guard lock{object_mutex}; | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     frame_begin = Clock::now(); | ||||
| } | ||||
| 
 | ||||
| void PerfStats::EndSystemFrame() { | ||||
|     std::lock_guard lock{object_mutex}; | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     auto frame_end = Clock::now(); | ||||
|     const auto frame_time = frame_end - frame_begin; | ||||
|  | @ -69,13 +69,13 @@ void PerfStats::EndSystemFrame() { | |||
| } | ||||
| 
 | ||||
| void PerfStats::EndGameFrame() { | ||||
|     std::lock_guard lock{object_mutex}; | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     game_frames += 1; | ||||
| } | ||||
| 
 | ||||
| double PerfStats::GetMeanFrametime() const { | ||||
|     std::lock_guard lock{object_mutex}; | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     if (current_index <= IgnoreFrames) { | ||||
|         return 0; | ||||
|  | @ -87,7 +87,7 @@ double PerfStats::GetMeanFrametime() const { | |||
| } | ||||
| 
 | ||||
| PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_us) { | ||||
|     std::lock_guard lock(object_mutex); | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     const auto now = Clock::now(); | ||||
|     // Walltime elapsed since stats were reset
 | ||||
|  | @ -95,12 +95,11 @@ PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_ | |||
| 
 | ||||
|     const auto system_us_per_second = (current_system_time_us - reset_point_system_us) / interval; | ||||
| 
 | ||||
|     Results results{}; | ||||
|     results.system_fps = static_cast<double>(system_frames) / interval; | ||||
|     results.game_fps = static_cast<double>(game_frames) / interval; | ||||
|     results.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / | ||||
|                         static_cast<double>(system_frames); | ||||
|     results.emulation_speed = system_us_per_second.count() / 1'000'000.0; | ||||
|     last_stats.system_fps = static_cast<double>(system_frames) / interval; | ||||
|     last_stats.game_fps = static_cast<double>(game_frames) / interval; | ||||
|     last_stats.frametime = duration_cast<DoubleSecs>(accumulated_frametime).count() / | ||||
|                            static_cast<double>(system_frames); | ||||
|     last_stats.emulation_speed = system_us_per_second.count() / 1'000'000.0; | ||||
| 
 | ||||
|     // Reset counters
 | ||||
|     reset_point = now; | ||||
|  | @ -109,11 +108,17 @@ PerfStats::Results PerfStats::GetAndResetStats(microseconds current_system_time_ | |||
|     system_frames = 0; | ||||
|     game_frames = 0; | ||||
| 
 | ||||
|     return results; | ||||
|     return last_stats; | ||||
| } | ||||
| 
 | ||||
| PerfStats::Results PerfStats::GetLastStats() { | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     return last_stats; | ||||
| } | ||||
| 
 | ||||
| double PerfStats::GetLastFrameTimeScale() const { | ||||
|     std::lock_guard lock{object_mutex}; | ||||
|     std::scoped_lock lock{object_mutex}; | ||||
| 
 | ||||
|     constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; | ||||
|     return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; | ||||
|  |  | |||
|  | @ -42,6 +42,8 @@ public: | |||
| 
 | ||||
|     Results GetAndResetStats(std::chrono::microseconds current_system_time_us); | ||||
| 
 | ||||
|     Results GetLastStats(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Returns the arithmetic mean of all frametime values stored in the performance history. | ||||
|      */ | ||||
|  | @ -82,6 +84,9 @@ private: | |||
|     Clock::time_point frame_begin = reset_point; | ||||
|     /// Total visible duration (including frame-limiting, etc.) of the previous system frame
 | ||||
|     Clock::duration previous_frame_length = Clock::duration::zero(); | ||||
| 
 | ||||
|     /// Last recorded performance statistics.
 | ||||
|     Results last_stats; | ||||
| }; | ||||
| 
 | ||||
| class FrameLimiter { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue