audio_core\hle\source.cpp: Improve accuracy of SourceStatus (#7432)

This commit is contained in:
SachinVin 2024-02-17 06:42:54 +05:30 committed by GitHub
parent 7638f87f74
commit bb003c2bd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 14 deletions

View file

@ -298,9 +298,9 @@ void Source::ParseConfig(SourceConfiguration::Configuration& config,
b.buffer_id, b.buffer_id,
state.mono_or_stereo, state.mono_or_stereo,
state.format, state.format,
true, true, // from_queue
{}, // 0 in u32_dsp 0, // play_position
false, false, // has_played
}); });
} }
LOG_TRACE(Audio_DSP, "enqueuing queued {} addr={:#010x} len={} id={}", i, LOG_TRACE(Audio_DSP, "enqueuing queued {} addr={:#010x} len={} id={}", i,
@ -321,7 +321,11 @@ void Source::ParseConfig(SourceConfiguration::Configuration& config,
void Source::GenerateFrame() { void Source::GenerateFrame() {
current_frame.fill({}); current_frame.fill({});
if (state.current_buffer.empty() && !DequeueBuffer()) { if (state.current_buffer.empty()) {
// TODO(SachinV): Should dequeue happen at the end of the frame generation?
if (DequeueBuffer()) {
return;
}
state.enabled = false; state.enabled = false;
state.buffer_update = true; state.buffer_update = true;
state.last_buffer_id = state.current_buffer_id; state.last_buffer_id = state.current_buffer_id;
@ -330,8 +334,6 @@ void Source::GenerateFrame() {
} }
std::size_t frame_position = 0; std::size_t frame_position = 0;
state.current_sample_number = state.next_sample_number;
while (frame_position < current_frame.size()) { while (frame_position < current_frame.size()) {
if (state.current_buffer.empty() && !DequeueBuffer()) { if (state.current_buffer.empty() && !DequeueBuffer()) {
break; break;
@ -358,7 +360,7 @@ void Source::GenerateFrame() {
} }
// TODO(jroweboy): Keep track of frame_position independently so that it doesn't lose precision // TODO(jroweboy): Keep track of frame_position independently so that it doesn't lose precision
// over time // over time
state.next_sample_number += static_cast<u32>(frame_position * state.rate_multiplier); state.current_sample_number += static_cast<u32>(frame_position * state.rate_multiplier);
state.filters.ProcessFrame(current_frame); state.filters.ProcessFrame(current_frame);
} }
@ -409,7 +411,6 @@ bool Source::DequeueBuffer() {
// the first playthrough starts at play_position, loops start at the beginning of the buffer // the first playthrough starts at play_position, loops start at the beginning of the buffer
state.current_sample_number = (!buf.has_played) ? buf.play_position : 0; state.current_sample_number = (!buf.has_played) ? buf.play_position : 0;
state.next_sample_number = state.current_sample_number;
state.current_buffer_physical_address = buf.physical_address; state.current_buffer_physical_address = buf.physical_address;
state.current_buffer_id = buf.buffer_id; state.current_buffer_id = buf.buffer_id;
state.last_buffer_id = 0; state.last_buffer_id = 0;
@ -420,8 +421,17 @@ bool Source::DequeueBuffer() {
state.input_queue.push(buf); state.input_queue.push(buf);
} }
LOG_TRACE(Audio_DSP, "source_id={} buffer_id={} from_queue={} current_buffer.size()={}", // Because our interpolation consumes samples instead of using an index,
source_id, buf.buffer_id, buf.from_queue, state.current_buffer.size()); // let's just consume the samples up to the current sample number.
state.current_buffer.erase(
state.current_buffer.begin(),
std::next(state.current_buffer.begin(), state.current_sample_number));
LOG_TRACE(Audio_DSP,
"source_id={} buffer_id={} from_queue={} current_buffer.size()={}, "
"buf.has_played={}, buf.play_position={}",
source_id, buf.buffer_id, buf.from_queue, state.current_buffer.size(), buf.has_played,
buf.play_position);
return true; return true;
} }

View file

@ -87,8 +87,8 @@ private:
Format format; Format format;
bool from_queue; bool from_queue;
u32_dsp play_position; // = 0; u32 play_position; // = 0;
bool has_played; // = false; bool has_played; // = false;
private: private:
template <class Archive> template <class Archive>
@ -136,7 +136,6 @@ private:
// Current buffer // Current buffer
u32 current_sample_number = 0; u32 current_sample_number = 0;
u32 next_sample_number = 0;
PAddr current_buffer_physical_address = 0; PAddr current_buffer_physical_address = 0;
AudioInterp::StereoBuffer16 current_buffer = {}; AudioInterp::StereoBuffer16 current_buffer = {};
@ -171,7 +170,6 @@ private:
ar& mono_or_stereo; ar& mono_or_stereo;
ar& format; ar& format;
ar& current_sample_number; ar& current_sample_number;
ar& next_sample_number;
ar& current_buffer_physical_address; ar& current_buffer_physical_address;
ar& current_buffer; ar& current_buffer;
ar& buffer_update; ar& buffer_update;