summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-07-28 13:35:22 -0400
committerGravatar bunnei2018-07-30 18:58:40 -0400
commit0e8a2c7222b978507f62d7e0b83187b16532eae8 (patch)
treebfcc69cc41fc9cf9fe9a80c321f27ba50d17065f /src
parentaudio_core: Move to audout_u impl. (diff)
downloadyuzu-0e8a2c7222b978507f62d7e0b83187b16532eae8.tar.gz
yuzu-0e8a2c7222b978507f62d7e0b83187b16532eae8.tar.xz
yuzu-0e8a2c7222b978507f62d7e0b83187b16532eae8.zip
audio_core: Misc. improvements to stream/buffer/audio_out.
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/audio_out.cpp4
-rw-r--r--src/audio_core/audio_out.h6
-rw-r--r--src/audio_core/buffer.h3
-rw-r--r--src/audio_core/stream.cpp24
-rw-r--r--src/audio_core/stream.h15
5 files changed, 32 insertions, 20 deletions
diff --git a/src/audio_core/audio_out.cpp b/src/audio_core/audio_out.cpp
index 6d418a05b..43414f197 100644
--- a/src/audio_core/audio_out.cpp
+++ b/src/audio_core/audio_out.cpp
@@ -9,7 +9,7 @@
9namespace AudioCore { 9namespace AudioCore {
10 10
11/// Returns the stream format from the specified number of channels 11/// Returns the stream format from the specified number of channels
12static Stream::Format ChannelsToStreamFormat(int num_channels) { 12static Stream::Format ChannelsToStreamFormat(u32 num_channels) {
13 switch (num_channels) { 13 switch (num_channels) {
14 case 1: 14 case 1:
15 return Stream::Format::Mono16; 15 return Stream::Format::Mono16;
@@ -24,7 +24,7 @@ static Stream::Format ChannelsToStreamFormat(int num_channels) {
24 return {}; 24 return {};
25} 25}
26 26
27StreamPtr AudioOut::OpenStream(int sample_rate, int num_channels, 27StreamPtr AudioOut::OpenStream(u32 sample_rate, u32 num_channels,
28 Stream::ReleaseCallback&& release_callback) { 28 Stream::ReleaseCallback&& release_callback) {
29 streams.push_back(std::make_shared<Stream>(sample_rate, ChannelsToStreamFormat(num_channels), 29 streams.push_back(std::make_shared<Stream>(sample_rate, ChannelsToStreamFormat(num_channels),
30 std::move(release_callback))); 30 std::move(release_callback)));
diff --git a/src/audio_core/audio_out.h b/src/audio_core/audio_out.h
index a86499d10..962360d09 100644
--- a/src/audio_core/audio_out.h
+++ b/src/audio_core/audio_out.h
@@ -13,15 +13,13 @@
13 13
14namespace AudioCore { 14namespace AudioCore {
15 15
16using StreamPtr = std::shared_ptr<Stream>;
17
18/** 16/**
19 * Represents an audio playback interface, used to open and play audio streams 17 * Represents an audio playback interface, used to open and play audio streams
20 */ 18 */
21class AudioOut { 19class AudioOut {
22public: 20public:
23 /// Opens a new audio stream 21 /// Opens a new audio stream
24 StreamPtr OpenStream(int sample_rate, int num_channels, 22 StreamPtr OpenStream(u32 sample_rate, u32 num_channels,
25 Stream::ReleaseCallback&& release_callback); 23 Stream::ReleaseCallback&& release_callback);
26 24
27 /// Returns a vector of recently released buffers specified by tag for the specified stream 25 /// Returns a vector of recently released buffers specified by tag for the specified stream
@@ -37,7 +35,7 @@ public:
37 bool QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<u8>&& data); 35 bool QueueBuffer(StreamPtr stream, Buffer::Tag tag, std::vector<u8>&& data);
38 36
39private: 37private:
40 /// Active audio streams on the interface 38 SinkPtr sink;
41 std::vector<StreamPtr> streams; 39 std::vector<StreamPtr> streams;
42}; 40};
43 41
diff --git a/src/audio_core/buffer.h b/src/audio_core/buffer.h
index 874ec787e..4bf5fd58a 100644
--- a/src/audio_core/buffer.h
+++ b/src/audio_core/buffer.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <memory>
7#include <vector> 8#include <vector>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
@@ -34,4 +35,6 @@ private:
34 std::vector<u8> data; 35 std::vector<u8> data;
35}; 36};
36 37
38using BufferPtr = std::shared_ptr<Buffer>;
39
37} // namespace AudioCore 40} // namespace AudioCore
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp
index 82bff4b9e..63edc6c8d 100644
--- a/src/audio_core/stream.cpp
+++ b/src/audio_core/stream.cpp
@@ -13,24 +13,24 @@ namespace AudioCore {
13 13
14constexpr size_t MaxAudioBufferCount{32}; 14constexpr size_t MaxAudioBufferCount{32};
15 15
16/// Returns the sample size for the specified audio stream format 16u32 Stream::GetNumChannels() const {
17static size_t SampleSizeFromFormat(Stream::Format format) {
18 switch (format) { 17 switch (format) {
19 case Stream::Format::Mono16: 18 case Format::Mono16:
19 return 1;
20 case Format::Stereo16:
20 return 2; 21 return 2;
21 case Stream::Format::Stereo16: 22 case Format::Multi51Channel16:
22 return 4; 23 return 6;
23 case Stream::Format::Multi51Channel16: 24 }
24 return 12;
25 };
26
27 LOG_CRITICAL(Audio, "Unimplemented format={}", static_cast<u32>(format)); 25 LOG_CRITICAL(Audio, "Unimplemented format={}", static_cast<u32>(format));
28 UNREACHABLE(); 26 UNREACHABLE();
29 return {}; 27 return {};
30} 28}
31 29
32Stream::Stream(int sample_rate, Format format, ReleaseCallback&& release_callback) 30u32 Stream::GetSampleSize() const {
33 : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)} { 31 return GetNumChannels() * 2;
32}
33
34 release_event = CoreTiming::RegisterEvent( 34 release_event = CoreTiming::RegisterEvent(
35 "Stream::Release", [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); }); 35 "Stream::Release", [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); });
36} 36}
@@ -45,7 +45,7 @@ void Stream::Stop() {
45} 45}
46 46
47s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { 47s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const {
48 const size_t num_samples{buffer.GetData().size() / SampleSizeFromFormat(format)}; 48 const size_t num_samples{buffer.GetData().size() / GetSampleSize()};
49 return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); 49 return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate);
50} 50}
51 51
diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h
index 5f43b0798..5c1005899 100644
--- a/src/audio_core/stream.h
+++ b/src/audio_core/stream.h
@@ -16,8 +16,6 @@
16 16
17namespace AudioCore { 17namespace AudioCore {
18 18
19using BufferPtr = std::shared_ptr<Buffer>;
20
21/** 19/**
22 * Represents an audio stream, which is a sequence of queued buffers, to be outputed by AudioOut 20 * Represents an audio stream, which is a sequence of queued buffers, to be outputed by AudioOut
23 */ 21 */
@@ -60,6 +58,17 @@ public:
60 return queued_buffers.size(); 58 return queued_buffers.size();
61 } 59 }
62 60
61 /// Gets the sample rate
62 u32 GetSampleRate() const {
63 return sample_rate;
64 }
65
66 /// Gets the number of channels
67 u32 GetNumChannels() const;
68
69 /// Gets the sample size in bytes
70 u32 GetSampleSize() const;
71
63private: 72private:
64 /// Current state of the stream 73 /// Current state of the stream
65 enum class State { 74 enum class State {
@@ -86,4 +95,6 @@ private:
86 std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream 95 std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream
87}; 96};
88 97
98using StreamPtr = std::shared_ptr<Stream>;
99
89} // namespace AudioCore 100} // namespace AudioCore