diff options
Diffstat (limited to 'src/audio_core/sink/sink.h')
| -rw-r--r-- | src/audio_core/sink/sink.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/audio_core/sink/sink.h b/src/audio_core/sink/sink.h new file mode 100644 index 000000000..91fe455e4 --- /dev/null +++ b/src/audio_core/sink/sink.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <memory> | ||
| 7 | #include <string> | ||
| 8 | |||
| 9 | #include "audio_core/sink/sink_stream.h" | ||
| 10 | #include "common/common_types.h" | ||
| 11 | |||
| 12 | namespace Common { | ||
| 13 | class Event; | ||
| 14 | } | ||
| 15 | namespace Core { | ||
| 16 | class System; | ||
| 17 | } | ||
| 18 | |||
| 19 | namespace AudioCore::Sink { | ||
| 20 | |||
| 21 | constexpr char auto_device_name[] = "auto"; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * This class is an interface for an audio sink, holds multiple output streams and is responsible | ||
| 25 | * for sinking samples to hardware. Used by Audio Render, Audio In and Audio Out. | ||
| 26 | */ | ||
| 27 | class Sink { | ||
| 28 | public: | ||
| 29 | virtual ~Sink() = default; | ||
| 30 | /** | ||
| 31 | * Close a given stream. | ||
| 32 | * | ||
| 33 | * @param stream - The stream to close. | ||
| 34 | */ | ||
| 35 | virtual void CloseStream(const SinkStream* stream) = 0; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Close all streams. | ||
| 39 | */ | ||
| 40 | virtual void CloseStreams() = 0; | ||
| 41 | |||
| 42 | /** | ||
| 43 | * Pause all streams. | ||
| 44 | */ | ||
| 45 | virtual void PauseStreams() = 0; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Unpause all streams. | ||
| 49 | */ | ||
| 50 | virtual void UnpauseStreams() = 0; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Create a new sink stream, kept within this sink, with a pointer returned for use. | ||
| 54 | * Do not free the returned pointer. When done with the stream, call CloseStream on the sink. | ||
| 55 | * | ||
| 56 | * @param system - Core system. | ||
| 57 | * @param system_channels - Number of channels the audio system expects. | ||
| 58 | * May differ from the device's channel count. | ||
| 59 | * @param name - Name of this stream. | ||
| 60 | * @param type - Type of this stream, render/in/out. | ||
| 61 | * @param event - Audio render only, a signal used to prevent the renderer running too | ||
| 62 | * fast. | ||
| 63 | * @return A pointer to the created SinkStream | ||
| 64 | */ | ||
| 65 | virtual SinkStream* AcquireSinkStream(Core::System& system, u32 system_channels, | ||
| 66 | const std::string& name, StreamType type) = 0; | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Get the number of channels the hardware device supports. | ||
| 70 | * Either 2 or 6. | ||
| 71 | * | ||
| 72 | * @return Number of device channels. | ||
| 73 | */ | ||
| 74 | u32 GetDeviceChannels() const { | ||
| 75 | return device_channels; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Get the device volume. Set from calls to the IAudioDevice service. | ||
| 80 | * | ||
| 81 | * @return Volume of the device. | ||
| 82 | */ | ||
| 83 | virtual f32 GetDeviceVolume() const = 0; | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Set the device volume. Set from calls to the IAudioDevice service. | ||
| 87 | * | ||
| 88 | * @param volume - New volume of the device. | ||
| 89 | */ | ||
| 90 | virtual void SetDeviceVolume(f32 volume) = 0; | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Set the system volume. Comes from the audio system using this stream. | ||
| 94 | * | ||
| 95 | * @param volume - New volume of the system. | ||
| 96 | */ | ||
| 97 | virtual void SetSystemVolume(f32 volume) = 0; | ||
| 98 | |||
| 99 | protected: | ||
| 100 | /// Number of device channels supported by the hardware | ||
| 101 | u32 device_channels{2}; | ||
| 102 | }; | ||
| 103 | |||
| 104 | using SinkPtr = std::unique_ptr<Sink>; | ||
| 105 | |||
| 106 | } // namespace AudioCore::Sink | ||