sink.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * Create a new sink stream, kept within this sink, with a pointer returned for use.
  35. * Do not free the returned pointer. When done with the stream, call CloseStream on the sink.
  36. *
  37. * @param system - Core system.
  38. * @param system_channels - Number of channels the audio system expects.
  39. * May differ from the device's channel count.
  40. * @param name - Name of this stream.
  41. * @param type - Type of this stream, render/in/out.
  42. *
  43. * @return A pointer to the created SinkStream
  44. */
  45. virtual SinkStream* AcquireSinkStream(Core::System& system, u32 system_channels,
  46. const std::string& name, StreamType type) = 0;
  47. /**
  48. * Get the number of channels the hardware device supports.
  49. * Either 2 or 6.
  50. *
  51. * @return Number of device channels.
  52. */
  53. u32 GetDeviceChannels() const {
  54. return device_channels;
  55. }
  56. /**
  57. * Get the device volume. Set from calls to the IAudioDevice service.
  58. *
  59. * @return Volume of the device.
  60. */
  61. virtual f32 GetDeviceVolume() const = 0;
  62. /**
  63. * Set the device volume. Set from calls to the IAudioDevice service.
  64. *
  65. * @param volume - New volume of the device.
  66. */
  67. virtual void SetDeviceVolume(f32 volume) = 0;
  68. /**
  69. * Set the system volume. Comes from the audio system using this stream.
  70. *
  71. * @param volume - New volume of the system.
  72. */
  73. virtual void SetSystemVolume(f32 volume) = 0;
  74. protected:
  75. /// Number of device channels supported by the hardware
  76. u32 device_channels{2};
  77. };
  78. using SinkPtr = std::unique_ptr<Sink>;
  79. } // namespace AudioCore::Sink