diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio_core/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/audio_core/null_sink.h | 27 | ||||
| -rw-r--r-- | src/audio_core/sink.h | 29 | ||||
| -rw-r--r-- | src/audio_core/sink_details.cpp | 38 | ||||
| -rw-r--r-- | src/audio_core/sink_details.h | 32 | ||||
| -rw-r--r-- | src/audio_core/sink_stream.h | 32 |
6 files changed, 163 insertions, 0 deletions
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index f00a55994..6bc8f586a 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt | |||
| @@ -2,8 +2,13 @@ add_library(audio_core STATIC | |||
| 2 | audio_out.cpp | 2 | audio_out.cpp |
| 3 | audio_out.h | 3 | audio_out.h |
| 4 | buffer.h | 4 | buffer.h |
| 5 | null_sink.h | ||
| 5 | stream.cpp | 6 | stream.cpp |
| 6 | stream.h | 7 | stream.h |
| 8 | sink.h | ||
| 9 | sink_details.cpp | ||
| 10 | sink_details.h | ||
| 11 | sink_stream.h | ||
| 7 | ) | 12 | ) |
| 8 | 13 | ||
| 9 | create_target_directory_groups(audio_core) | 14 | create_target_directory_groups(audio_core) |
diff --git a/src/audio_core/null_sink.h b/src/audio_core/null_sink.h new file mode 100644 index 000000000..2e04438f7 --- /dev/null +++ b/src/audio_core/null_sink.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "audio_core/sink.h" | ||
| 8 | |||
| 9 | namespace AudioCore { | ||
| 10 | |||
| 11 | class NullSink final : public Sink { | ||
| 12 | public: | ||
| 13 | explicit NullSink(std::string){}; | ||
| 14 | ~NullSink() override = default; | ||
| 15 | |||
| 16 | SinkStream& AcquireSinkStream(u32 /*sample_rate*/, u32 /*num_channels*/) override { | ||
| 17 | return null_sink_stream; | ||
| 18 | } | ||
| 19 | |||
| 20 | private: | ||
| 21 | struct NullSinkStreamImpl final : SinkStream { | ||
| 22 | void EnqueueSamples(u32 /*num_channels*/, const s16* /*samples*/, | ||
| 23 | size_t /*sample_count*/) override {} | ||
| 24 | } null_sink_stream; | ||
| 25 | }; | ||
| 26 | |||
| 27 | } // namespace AudioCore | ||
diff --git a/src/audio_core/sink.h b/src/audio_core/sink.h new file mode 100644 index 000000000..d1bb98c3d --- /dev/null +++ b/src/audio_core/sink.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | #include "audio_core/sink_stream.h" | ||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace AudioCore { | ||
| 13 | |||
| 14 | constexpr char auto_device_name[] = "auto"; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * This class is an interface for an audio sink. An audio sink accepts samples in stereo signed | ||
| 18 | * PCM16 format to be output. Sinks *do not* handle resampling and expect the correct sample rate. | ||
| 19 | * They are dumb outputs. | ||
| 20 | */ | ||
| 21 | class Sink { | ||
| 22 | public: | ||
| 23 | virtual ~Sink() = default; | ||
| 24 | virtual SinkStream& AcquireSinkStream(u32 sample_rate, u32 num_channels) = 0; | ||
| 25 | }; | ||
| 26 | |||
| 27 | using SinkPtr = std::unique_ptr<Sink>; | ||
| 28 | |||
| 29 | } // namespace AudioCore | ||
diff --git a/src/audio_core/sink_details.cpp b/src/audio_core/sink_details.cpp new file mode 100644 index 000000000..6396d8065 --- /dev/null +++ b/src/audio_core/sink_details.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <memory> | ||
| 7 | #include <string> | ||
| 8 | #include <vector> | ||
| 9 | #include "audio_core/null_sink.h" | ||
| 10 | #include "audio_core/sink_details.h" | ||
| 11 | #include "common/logging/log.h" | ||
| 12 | |||
| 13 | namespace AudioCore { | ||
| 14 | |||
| 15 | // g_sink_details is ordered in terms of desirability, with the best choice at the top. | ||
| 16 | const std::vector<SinkDetails> g_sink_details = { | ||
| 17 | SinkDetails{"null", &std::make_unique<NullSink, std::string>, | ||
| 18 | [] { return std::vector<std::string>{"null"}; }}, | ||
| 19 | }; | ||
| 20 | |||
| 21 | const SinkDetails& GetSinkDetails(std::string sink_id) { | ||
| 22 | auto iter = | ||
| 23 | std::find_if(g_sink_details.begin(), g_sink_details.end(), | ||
| 24 | [sink_id](const auto& sink_detail) { return sink_detail.id == sink_id; }); | ||
| 25 | |||
| 26 | if (sink_id == "auto" || iter == g_sink_details.end()) { | ||
| 27 | if (sink_id != "auto") { | ||
| 28 | LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id {}", sink_id); | ||
| 29 | } | ||
| 30 | // Auto-select. | ||
| 31 | // g_sink_details is ordered in terms of desirability, with the best choice at the front. | ||
| 32 | iter = g_sink_details.begin(); | ||
| 33 | } | ||
| 34 | |||
| 35 | return *iter; | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace AudioCore | ||
diff --git a/src/audio_core/sink_details.h b/src/audio_core/sink_details.h new file mode 100644 index 000000000..aa8aae1a9 --- /dev/null +++ b/src/audio_core/sink_details.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | namespace AudioCore { | ||
| 12 | |||
| 13 | class Sink; | ||
| 14 | |||
| 15 | struct SinkDetails { | ||
| 16 | SinkDetails(const char* id_, std::function<std::unique_ptr<Sink>(std::string)> factory_, | ||
| 17 | std::function<std::vector<std::string>()> list_devices_) | ||
| 18 | : id(id_), factory(factory_), list_devices(list_devices_) {} | ||
| 19 | |||
| 20 | /// Name for this sink. | ||
| 21 | const char* id; | ||
| 22 | /// A method to call to construct an instance of this type of sink. | ||
| 23 | std::function<std::unique_ptr<Sink>(std::string device_id)> factory; | ||
| 24 | /// A method to call to list available devices. | ||
| 25 | std::function<std::vector<std::string>()> list_devices; | ||
| 26 | }; | ||
| 27 | |||
| 28 | extern const std::vector<SinkDetails> g_sink_details; | ||
| 29 | |||
| 30 | const SinkDetails& GetSinkDetails(std::string sink_id); | ||
| 31 | |||
| 32 | } // namespace AudioCore | ||
diff --git a/src/audio_core/sink_stream.h b/src/audio_core/sink_stream.h new file mode 100644 index 000000000..e7a3f01b0 --- /dev/null +++ b/src/audio_core/sink_stream.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 11 | namespace AudioCore { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Accepts samples in stereo signed PCM16 format to be output. Sinks *do not* handle resampling and | ||
| 15 | * expect the correct sample rate. They are dumb outputs. | ||
| 16 | */ | ||
| 17 | class SinkStream { | ||
| 18 | public: | ||
| 19 | virtual ~SinkStream() = default; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Feed stereo samples to sink. | ||
| 23 | * @param num_channels Number of channels used. | ||
| 24 | * @param samples Samples in interleaved stereo PCM16 format. | ||
| 25 | * @param sample_count Number of samples. | ||
| 26 | */ | ||
| 27 | virtual void EnqueueSamples(u32 num_channels, const s16* samples, size_t sample_count) = 0; | ||
| 28 | }; | ||
| 29 | |||
| 30 | using SinkStreamPtr = std::unique_ptr<SinkStream>; | ||
| 31 | |||
| 32 | } // namespace AudioCore | ||