sink.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @param event - Audio render only, a signal used to prevent the renderer running too
  51. * fast.
  52. * @return A pointer to the created SinkStream
  53. */
  54. virtual SinkStream* AcquireSinkStream(Core::System& system, u32 system_channels,
  55. const std::string& name, StreamType type) = 0;
  56. /**
  57. * Get the number of channels the hardware device supports.
  58. * Either 2 or 6.
  59. *
  60. * @return Number of device channels.
  61. */
  62. u32 GetDeviceChannels() const {
  63. return device_channels;
  64. }
  65. /**
  66. * Get the device volume. Set from calls to the IAudioDevice service.
  67. *
  68. * @return Volume of the device.
  69. */
  70. virtual f32 GetDeviceVolume() const = 0;
  71. /**
  72. * Set the device volume. Set from calls to the IAudioDevice service.
  73. *
  74. * @param volume - New volume of the device.
  75. */
  76. virtual void SetDeviceVolume(f32 volume) = 0;
  77. /**
  78. * Set the system volume. Comes from the audio system using this stream.
  79. *
  80. * @param volume - New volume of the system.
  81. */
  82. virtual void SetSystemVolume(f32 volume) = 0;
  83. protected:
  84. /// Number of device channels supported by the hardware
  85. u32 device_channels{2};
  86. };
  87. using SinkPtr = std::unique_ptr<Sink>;
  88. } // namespace AudioCore::Sink