core_timing: Make TimedCallback take std::chrono::nanoseconds
Enforces our desired time units directly with a concrete type.
This commit is contained in:
parent
9e113a2b67
commit
56054fe86d
16 changed files with 62 additions and 58 deletions
|
@ -38,7 +38,7 @@ Stream::Stream(Core::Timing::CoreTiming& core_timing, u32 sample_rate, Format fo
|
|||
sink_stream{sink_stream}, core_timing{core_timing}, name{std::move(name_)} {
|
||||
|
||||
release_event = Core::Timing::CreateEvent(
|
||||
name, [this](u64 userdata, s64 cycles_late) { ReleaseActiveBuffer(cycles_late); });
|
||||
name, [this](u64, std::chrono::nanoseconds ns_late) { ReleaseActiveBuffer(ns_late); });
|
||||
}
|
||||
|
||||
void Stream::Play() {
|
||||
|
@ -78,7 +78,7 @@ static void VolumeAdjustSamples(std::vector<s16>& samples, float game_volume) {
|
|||
}
|
||||
}
|
||||
|
||||
void Stream::PlayNextBuffer(s64 cycles_late) {
|
||||
void Stream::PlayNextBuffer(std::chrono::nanoseconds ns_late) {
|
||||
if (!IsPlaying()) {
|
||||
// Ensure we are in playing state before playing the next buffer
|
||||
sink_stream.Flush();
|
||||
|
@ -103,17 +103,18 @@ void Stream::PlayNextBuffer(s64 cycles_late) {
|
|||
|
||||
sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples());
|
||||
|
||||
const auto time_stretch_delta = std::chrono::nanoseconds{
|
||||
Settings::values.enable_audio_stretching.GetValue() ? 0 : cycles_late};
|
||||
const auto time_stretch_delta = Settings::values.enable_audio_stretching.GetValue()
|
||||
? std::chrono::nanoseconds::zero()
|
||||
: ns_late;
|
||||
const auto future_time = GetBufferReleaseNS(*active_buffer) - time_stretch_delta;
|
||||
core_timing.ScheduleEvent(future_time, release_event, {});
|
||||
}
|
||||
|
||||
void Stream::ReleaseActiveBuffer(s64 cycles_late) {
|
||||
void Stream::ReleaseActiveBuffer(std::chrono::nanoseconds ns_late) {
|
||||
ASSERT(active_buffer);
|
||||
released_buffers.push(std::move(active_buffer));
|
||||
release_callback();
|
||||
PlayNextBuffer(cycles_late);
|
||||
PlayNextBuffer(ns_late);
|
||||
}
|
||||
|
||||
bool Stream::QueueBuffer(BufferPtr&& buffer) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue