VirtualDevice.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // Copyright (c) 2019-2020 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[4]
  29. {
  30. new VirtualDevice("AudioStereoJackOutput", 2),
  31. new VirtualDevice("AudioBuiltInSpeakerOutput", 2),
  32. new VirtualDevice("AudioTvOutput", 6),
  33. new VirtualDevice("AudioUsbDeviceOutput", 2),
  34. };
  35. /// <summary>
  36. /// The name of the <see cref="VirtualDevice"/>.
  37. /// </summary>
  38. public string Name { get; }
  39. /// <summary>
  40. /// The count of channels supported by the <see cref="VirtualDevice"/>.
  41. /// </summary>
  42. public uint ChannelCount { get; }
  43. /// <summary>
  44. /// The system master volume of the <see cref="VirtualDevice"/>.
  45. /// </summary>
  46. public float MasterVolume { get; private set; }
  47. /// <summary>
  48. /// Create a new <see cref="VirtualDevice"/> instance.
  49. /// </summary>
  50. /// <param name="name">The name of the <see cref="VirtualDevice"/>.</param>
  51. /// <param name="channelCount">The count of channels supported by the <see cref="VirtualDevice"/>.</param>
  52. private VirtualDevice(string name, uint channelCount)
  53. {
  54. Name = name;
  55. ChannelCount = channelCount;
  56. }
  57. /// <summary>
  58. /// Update the master volume of the <see cref="VirtualDevice"/>.
  59. /// </summary>
  60. /// <param name="volume">The new master volume.</param>
  61. public void UpdateMasterVolume(float volume)
  62. {
  63. Debug.Assert(volume >= 0.0f && volume <= 1.0f);
  64. MasterVolume = volume;
  65. }
  66. /// <summary>
  67. /// Check if the <see cref="VirtualDevice"/> is a usb device.
  68. /// </summary>
  69. /// <returns>Returns true if the <see cref="VirtualDevice"/> is a usb device.</returns>
  70. public bool IsUsbDevice()
  71. {
  72. return Name.Equals("AudioUsbDeviceOutput");
  73. }
  74. }
  75. }