VirtualDevice.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Copyright (c) 2019-2021 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using System.Diagnostics;
  18. namespace Ryujinx.Audio.Renderer.Device
  19. {
  20. /// <summary>
  21. /// Represents a virtual device used by IAudioDevice.
  22. /// </summary>
  23. public class VirtualDevice
  24. {
  25. /// <summary>
  26. /// All the defined virtual devices.
  27. /// </summary>
  28. public static readonly VirtualDevice[] Devices = new VirtualDevice[5]
  29. {
  30. new VirtualDevice("AudioStereoJackOutput", 2, true),
  31. new VirtualDevice("AudioBuiltInSpeakerOutput", 2, false),
  32. new VirtualDevice("AudioTvOutput", 6, false),
  33. new VirtualDevice("AudioUsbDeviceOutput", 2, true),
  34. new VirtualDevice("AudioExternalOutput", 6, true),
  35. };
  36. /// <summary>
  37. /// The name of the <see cref="VirtualDevice"/>.
  38. /// </summary>
  39. public string Name { get; }
  40. /// <summary>
  41. /// The count of channels supported by the <see cref="VirtualDevice"/>.
  42. /// </summary>
  43. public uint ChannelCount { get; }
  44. /// <summary>
  45. /// The system master volume of the <see cref="VirtualDevice"/>.
  46. /// </summary>
  47. public float MasterVolume { get; private set; }
  48. /// <summary>
  49. /// Define if the <see cref="VirtualDevice"/> is provided by an external interface.
  50. /// </summary>
  51. public bool IsExternalOutput { get; }
  52. /// <summary>
  53. /// Create a new <see cref="VirtualDevice"/> instance.
  54. /// </summary>
  55. /// <param name="name">The name of the <see cref="VirtualDevice"/>.</param>
  56. /// <param name="channelCount">The count of channels supported by the <see cref="VirtualDevice"/>.</param>
  57. /// <param name="isExternalOutput">Indicate if the <see cref="VirtualDevice"/> is provided by an external interface.</param>
  58. private VirtualDevice(string name, uint channelCount, bool isExternalOutput)
  59. {
  60. Name = name;
  61. ChannelCount = channelCount;
  62. IsExternalOutput = isExternalOutput;
  63. }
  64. /// <summary>
  65. /// Update the master volume of the <see cref="VirtualDevice"/>.
  66. /// </summary>
  67. /// <param name="volume">The new master volume.</param>
  68. public void UpdateMasterVolume(float volume)
  69. {
  70. Debug.Assert(volume >= 0.0f && volume <= 1.0f);
  71. MasterVolume = volume;
  72. }
  73. /// <summary>
  74. /// Check if the <see cref="VirtualDevice"/> is a usb device.
  75. /// </summary>
  76. /// <returns>Returns true if the <see cref="VirtualDevice"/> is a usb device.</returns>
  77. public bool IsUsbDevice()
  78. {
  79. return Name.Equals("AudioUsbDeviceOutput");
  80. }
  81. /// <summary>
  82. /// Get the output device name of the <see cref="VirtualDevice"/>.
  83. /// </summary>
  84. /// <returns>The output device name of the <see cref="VirtualDevice"/>.</returns>
  85. public string GetOutputDeviceName()
  86. {
  87. if (IsExternalOutput)
  88. {
  89. return "AudioExternalOutput";
  90. }
  91. return Name;
  92. }
  93. }
  94. }