audio_device.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <span>
  5. #include "audio_core/audio_render_manager.h"
  6. namespace Core {
  7. class System;
  8. }
  9. namespace AudioCore {
  10. namespace Sink {
  11. class Sink;
  12. }
  13. namespace AudioRenderer {
  14. /**
  15. * An interface to an output audio device available to the Switch.
  16. */
  17. class AudioDevice {
  18. public:
  19. struct AudioDeviceName {
  20. std::array<char, 0x100> name;
  21. AudioDeviceName(const char* name_) {
  22. std::strncpy(name.data(), name_, name.size());
  23. }
  24. };
  25. std::array<AudioDeviceName, 4> usb_device_names{"AudioStereoJackOutput",
  26. "AudioBuiltInSpeakerOutput", "AudioTvOutput",
  27. "AudioUsbDeviceOutput"};
  28. std::array<AudioDeviceName, 3> device_names{"AudioStereoJackOutput",
  29. "AudioBuiltInSpeakerOutput", "AudioTvOutput"};
  30. std::array<AudioDeviceName, 3> output_device_names{"AudioBuiltInSpeakerOutput", "AudioTvOutput",
  31. "AudioExternalOutput"};
  32. explicit AudioDevice(Core::System& system, u64 applet_resource_user_id, u32 revision);
  33. /**
  34. * Get a list of the available output devices.
  35. *
  36. * @param out_buffer - Output buffer to write the available device names.
  37. * @param max_count - Maximum number of devices to write (count of out_buffer).
  38. * @return Number of device names written.
  39. */
  40. u32 ListAudioDeviceName(std::vector<AudioDeviceName>& out_buffer, size_t max_count);
  41. /**
  42. * Get a list of the available output devices.
  43. * Different to above somehow...
  44. *
  45. * @param out_buffer - Output buffer to write the available device names.
  46. * @param max_count - Maximum number of devices to write (count of out_buffer).
  47. * @return Number of device names written.
  48. */
  49. u32 ListAudioOutputDeviceName(std::vector<AudioDeviceName>& out_buffer, size_t max_count);
  50. /**
  51. * Set the volume of all streams in the backend sink.
  52. *
  53. * @param volume - Volume to set.
  54. */
  55. void SetDeviceVolumes(f32 volume);
  56. /**
  57. * Get the volume for a given device name.
  58. * Note: This is not fully implemented, we only assume 1 device for all streams.
  59. *
  60. * @param name - Name of the device to check. Unused.
  61. * @return Volume of the device.
  62. */
  63. f32 GetDeviceVolume(std::string_view name);
  64. private:
  65. /// Backend output sink for the device
  66. Sink::Sink& output_sink;
  67. /// Resource id this device is used for
  68. const u64 applet_resource_user_id;
  69. /// User audio renderer revision
  70. const u32 user_revision;
  71. };
  72. } // namespace AudioRenderer
  73. } // namespace AudioCore