Rework audio output, connecting AudioOut into coretiming to fix desync during heavy loads.

This commit is contained in:
Kelebek1
2022-08-01 02:58:13 +01:00
parent a83a5d2e4c
commit ea9ff71725
23 changed files with 550 additions and 841 deletions

View File

@ -3,6 +3,9 @@
#pragma once
#include <chrono>
#include <memory>
#include <optional>
#include <span>
#include "audio_core/common/common.h"
@ -11,9 +14,13 @@
namespace Core {
class System;
}
namespace Timing {
struct EventType;
} // namespace Timing
} // namespace Core
namespace AudioCore {
namespace Sink {
class SinkStream;
struct SinkBuffer;
@ -70,7 +77,7 @@ public:
* @param tag - Unqiue tag of the buffer to check.
* @return true if the buffer has been consumed, otherwise false.
*/
bool IsBufferConsumed(u64 tag) const;
bool IsBufferConsumed(AudioBuffer& buffer) const;
/**
* Start this device session, starting the backend stream.
@ -96,6 +103,16 @@ public:
*/
u64 GetPlayedSampleCount() const;
/*
* CoreTiming callback to increment played_sample_count over time.
*/
std::optional<std::chrono::nanoseconds> ThreadFunc();
/*
* Set the size of the ring buffer.
*/
void SetRingSize(u32 ring_size);
private:
/// System
Core::System& system;
@ -118,9 +135,13 @@ private:
/// Applet resource user id of this device session
u64 applet_resource_user_id{};
/// Total number of samples played by this device session
u64 played_sample_count{};
std::atomic<u64> played_sample_count{};
/// Event increasing the played sample count every 5ms
std::shared_ptr<Core::Timing::EventType> thread_event;
/// Is this session initialised?
bool initialized{};
/// Buffer queue
std::vector<AudioBuffer> buffer_queue{};
};
} // namespace AudioCore