mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-15 06:17:00 +02:00
[audio] replace ReaderWriterQueue with the generic SPSC queue (#2745)
A bit overkill for something that is only used once in the source code - should rather pertain to the generic SPSC queue just to avoid redundant code. If anything should be vendored. Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2745 Reviewed-by: crueter <crueter@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
bb836ed6c2
commit
31463142e1
5 changed files with 13 additions and 948 deletions
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -12,7 +15,6 @@
|
|||
#include "audio_core/adsp/mailbox.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/reader_writer_queue.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
namespace Core {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace AudioCore::Sink {
|
|||
|
||||
void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
||||
SCOPE_EXIT {
|
||||
queue.enqueue(buffer);
|
||||
queue.EmplaceWait(buffer);
|
||||
++queued_buffers;
|
||||
};
|
||||
|
||||
|
|
@ -147,7 +147,8 @@ std::vector<s16> SinkStream::ReleaseBuffer(u64 num_samples) {
|
|||
|
||||
void SinkStream::ClearQueue() {
|
||||
samples_buffer.Pop();
|
||||
while (queue.pop()) {
|
||||
SinkBuffer tmp;
|
||||
while (queue.TryPop(tmp)) {
|
||||
}
|
||||
queued_buffers = 0;
|
||||
playing_buffer = {};
|
||||
|
|
@ -169,7 +170,7 @@ void SinkStream::ProcessAudioIn(std::span<const s16> input_buffer, std::size_t n
|
|||
while (frames_written < num_frames) {
|
||||
// If the playing buffer has been consumed or has no frames, we need a new one
|
||||
if (playing_buffer.consumed || playing_buffer.frames == 0) {
|
||||
if (!queue.try_dequeue(playing_buffer)) {
|
||||
if (!queue.TryPop(playing_buffer)) {
|
||||
// If no buffer was available we've underrun, just push the samples and
|
||||
// continue.
|
||||
samples_buffer.Push(&input_buffer[frames_written * frame_size],
|
||||
|
|
@ -230,7 +231,7 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
|
|||
while (frames_written < num_frames) {
|
||||
// If the playing buffer has been consumed or has no frames, we need a new one
|
||||
if (playing_buffer.consumed || playing_buffer.frames == 0) {
|
||||
if (!queue.try_dequeue(playing_buffer)) {
|
||||
if (!queue.TryPop(playing_buffer)) {
|
||||
// If no buffer was available we've underrun, fill the remaining buffer with
|
||||
// the last written frame and continue.
|
||||
for (size_t i = frames_written; i < num_frames; i++) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
|
|
@ -14,8 +17,8 @@
|
|||
#include "audio_core/common/common.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/reader_writer_queue.h"
|
||||
#include "common/ring_buffer.h"
|
||||
#include "common/bounded_threadsafe_queue.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
namespace Core {
|
||||
|
|
@ -237,7 +240,7 @@ private:
|
|||
/// Ring buffer of the samples waiting to be played or consumed
|
||||
Common::RingBuffer<s16, 0x10000> samples_buffer;
|
||||
/// Audio buffers queued and waiting to play
|
||||
Common::ReaderWriterQueue<SinkBuffer> queue;
|
||||
Common::SPSCQueue<SinkBuffer, 0x10000> queue;
|
||||
/// The currently-playing audio buffer
|
||||
SinkBuffer playing_buffer{};
|
||||
/// The last played (or received) frame of audio, used when the callback underruns
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue