sink.h 2.7 KB

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