summaryrefslogtreecommitdiff
path: root/src/audio_core/stream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio_core/stream.h')
-rw-r--r--src/audio_core/stream.h130
1 files changed, 0 insertions, 130 deletions
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h
deleted file mode 100644
index f5de70396..000000000
--- a/src/audio_core/stream.h
+++ /dev/null
@@ -1,130 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <chrono>
7#include <functional>
8#include <memory>
9#include <string>
10#include <vector>
11#include <queue>
12
13#include "audio_core/buffer.h"
14#include "common/common_types.h"
15
16namespace Core::Timing {
17class CoreTiming;
18struct EventType;
19} // namespace Core::Timing
20
21namespace AudioCore {
22
23class SinkStream;
24
25/**
26 * Represents an audio stream, which is a sequence of queued buffers, to be outputed by AudioOut
27 */
28class Stream {
29public:
30 /// Audio format of the stream
31 enum class Format {
32 Mono16,
33 Stereo16,
34 Multi51Channel16,
35 };
36
37 /// Current state of the stream
38 enum class State {
39 Stopped,
40 Playing,
41 };
42
43 /// Callback function type, used to change guest state on a buffer being released
44 using ReleaseCallback = std::function<void()>;
45
46 Stream(Core::Timing::CoreTiming& core_timing_, u32 sample_rate_, Format format_,
47 ReleaseCallback&& release_callback_, SinkStream& sink_stream_, std::string&& name_);
48
49 /// Plays the audio stream
50 void Play();
51
52 /// Stops the audio stream
53 void Stop();
54
55 /// Queues a buffer into the audio stream, returns true on success
56 bool QueueBuffer(BufferPtr&& buffer);
57
58 /// Flush audio buffers
59 bool Flush();
60
61 /// Returns true if the audio stream contains a buffer with the specified tag
62 [[nodiscard]] bool ContainsBuffer(Buffer::Tag tag) const;
63
64 /// Returns a vector of recently released buffers specified by tag
65 [[nodiscard]] std::vector<Buffer::Tag> GetTagsAndReleaseBuffers(std::size_t max_count);
66
67 /// Returns a vector of all recently released buffers specified by tag
68 [[nodiscard]] std::vector<Buffer::Tag> GetTagsAndReleaseBuffers();
69
70 void SetVolume(float volume);
71
72 [[nodiscard]] float GetVolume() const {
73 return game_volume;
74 }
75
76 /// Returns true if the stream is currently playing
77 [[nodiscard]] bool IsPlaying() const {
78 return state == State::Playing;
79 }
80
81 /// Returns the number of queued buffers
82 [[nodiscard]] std::size_t GetQueueSize() const {
83 return queued_buffers.size();
84 }
85
86 /// Gets the sample rate
87 [[nodiscard]] u32 GetSampleRate() const {
88 return sample_rate;
89 }
90
91 /// Gets the number of samples played so far
92 [[nodiscard]] u64 GetPlayedSampleCount() const {
93 return played_samples;
94 }
95
96 /// Gets the number of channels
97 [[nodiscard]] u32 GetNumChannels() const;
98
99 /// Get the state
100 [[nodiscard]] State GetState() const;
101
102private:
103 /// Plays the next queued buffer in the audio stream, starting playback if necessary
104 void PlayNextBuffer(std::chrono::nanoseconds ns_late = {});
105
106 /// Releases the actively playing buffer, signalling that it has been completed
107 void ReleaseActiveBuffer(std::chrono::nanoseconds ns_late = {});
108
109 /// Gets the number of core cycles when the specified buffer will be released
110 [[nodiscard]] std::chrono::nanoseconds GetBufferReleaseNS(const Buffer& buffer) const;
111
112 u32 sample_rate; ///< Sample rate of the stream
113 u64 played_samples{}; ///< The current played sample count
114 Format format; ///< Format of the stream
115 float game_volume = 1.0f; ///< The volume the game currently has set
116 ReleaseCallback release_callback; ///< Buffer release callback for the stream
117 State state{State::Stopped}; ///< Playback state of the stream
118 std::shared_ptr<Core::Timing::EventType>
119 release_event; ///< Core timing release event for the stream
120 BufferPtr active_buffer; ///< Actively playing buffer in the stream
121 std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream
122 std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream
123 SinkStream& sink_stream; ///< Output sink for the stream
124 Core::Timing::CoreTiming& core_timing; ///< Core timing instance.
125 std::string name; ///< Name of the stream, must be unique
126};
127
128using StreamPtr = std::shared_ptr<Stream>;
129
130} // namespace AudioCore