sdl2_sink.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. #include "audio_core/sink/sink.h"
  7. namespace Core {
  8. class System;
  9. }
  10. namespace AudioCore::Sink {
  11. class SinkStream;
  12. /**
  13. * SDL backend sink, holds multiple output streams and is responsible for sinking samples to
  14. * hardware. Used by Audio Render, Audio In and Audio Out.
  15. */
  16. class SDLSink final : public Sink {
  17. public:
  18. explicit SDLSink(std::string_view device_id);
  19. ~SDLSink() override;
  20. /**
  21. * Create a new sink stream.
  22. *
  23. * @param system - Core system.
  24. * @param system_channels - Number of channels the audio system expects.
  25. * May differ from the device's channel count.
  26. * @param name - Name of this stream.
  27. * @param type - Type of this stream, render/in/out.
  28. *
  29. * @return A pointer to the created SinkStream
  30. */
  31. SinkStream* AcquireSinkStream(Core::System& system, u32 system_channels,
  32. const std::string& name, StreamType type) override;
  33. /**
  34. * Close a given stream.
  35. *
  36. * @param stream - The stream to close.
  37. */
  38. void CloseStream(SinkStream* stream) override;
  39. /**
  40. * Close all streams.
  41. */
  42. void CloseStreams() override;
  43. /**
  44. * Get the device volume. Set from calls to the IAudioDevice service.
  45. *
  46. * @return Volume of the device.
  47. */
  48. f32 GetDeviceVolume() const override;
  49. /**
  50. * Set the device volume. Set from calls to the IAudioDevice service.
  51. *
  52. * @param volume - New volume of the device.
  53. */
  54. void SetDeviceVolume(f32 volume) override;
  55. /**
  56. * Set the system volume. Comes from the audio system using this stream.
  57. *
  58. * @param volume - New volume of the system.
  59. */
  60. void SetSystemVolume(f32 volume) override;
  61. private:
  62. /// Name of the output device used by streams
  63. std::string output_device;
  64. /// Name of the input device used by streams
  65. std::string input_device;
  66. /// Vector of streams managed by this sink
  67. std::vector<SinkStreamPtr> sink_streams;
  68. };
  69. /**
  70. * Get a list of connected devices from SDL.
  71. *
  72. * @param capture - Return input (capture) devices if true, otherwise output devices.
  73. */
  74. std::vector<std::string> ListSDLSinkDevices(bool capture);
  75. /**
  76. * Get the reported latency for this sink.
  77. *
  78. * @return Minimum latency for this sink.
  79. */
  80. u32 GetSDLLatency();
  81. } // namespace AudioCore::Sink