VirtualDevice.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Diagnostics;
  2. namespace Ryujinx.Audio.Renderer.Device
  3. {
  4. /// <summary>
  5. /// Represents a virtual device used by IAudioDevice.
  6. /// </summary>
  7. public class VirtualDevice
  8. {
  9. /// <summary>
  10. /// All the defined virtual devices.
  11. /// </summary>
  12. public static readonly VirtualDevice[] Devices = new VirtualDevice[5]
  13. {
  14. new VirtualDevice("AudioStereoJackOutput", 2, true),
  15. new VirtualDevice("AudioBuiltInSpeakerOutput", 2, false),
  16. new VirtualDevice("AudioTvOutput", 6, false),
  17. new VirtualDevice("AudioUsbDeviceOutput", 2, true),
  18. new VirtualDevice("AudioExternalOutput", 6, true),
  19. };
  20. /// <summary>
  21. /// The name of the <see cref="VirtualDevice"/>.
  22. /// </summary>
  23. public string Name { get; }
  24. /// <summary>
  25. /// The count of channels supported by the <see cref="VirtualDevice"/>.
  26. /// </summary>
  27. public uint ChannelCount { get; }
  28. /// <summary>
  29. /// The system master volume of the <see cref="VirtualDevice"/>.
  30. /// </summary>
  31. public float MasterVolume { get; private set; }
  32. /// <summary>
  33. /// Define if the <see cref="VirtualDevice"/> is provided by an external interface.
  34. /// </summary>
  35. public bool IsExternalOutput { get; }
  36. /// <summary>
  37. /// Create a new <see cref="VirtualDevice"/> instance.
  38. /// </summary>
  39. /// <param name="name">The name of the <see cref="VirtualDevice"/>.</param>
  40. /// <param name="channelCount">The count of channels supported by the <see cref="VirtualDevice"/>.</param>
  41. /// <param name="isExternalOutput">Indicate if the <see cref="VirtualDevice"/> is provided by an external interface.</param>
  42. private VirtualDevice(string name, uint channelCount, bool isExternalOutput)
  43. {
  44. Name = name;
  45. ChannelCount = channelCount;
  46. IsExternalOutput = isExternalOutput;
  47. }
  48. /// <summary>
  49. /// Update the master volume of the <see cref="VirtualDevice"/>.
  50. /// </summary>
  51. /// <param name="volume">The new master volume.</param>
  52. public void UpdateMasterVolume(float volume)
  53. {
  54. Debug.Assert(volume >= 0.0f && volume <= 1.0f);
  55. MasterVolume = volume;
  56. }
  57. /// <summary>
  58. /// Check if the <see cref="VirtualDevice"/> is a usb device.
  59. /// </summary>
  60. /// <returns>Returns true if the <see cref="VirtualDevice"/> is a usb device.</returns>
  61. public bool IsUsbDevice()
  62. {
  63. return Name.Equals("AudioUsbDeviceOutput");
  64. }
  65. /// <summary>
  66. /// Get the output device name of the <see cref="VirtualDevice"/>.
  67. /// </summary>
  68. /// <returns>The output device name of the <see cref="VirtualDevice"/>.</returns>
  69. public string GetOutputDeviceName()
  70. {
  71. if (IsExternalOutput)
  72. {
  73. return "AudioExternalOutput";
  74. }
  75. return Name;
  76. }
  77. }
  78. }